darcs-2.14.5/0000755000000000000000000000000007346545000011070 5ustar0000000000000000darcs-2.14.5/CHANGELOG0000755000000000000000000037266707346545000012332 0ustar0000000000000000Darcs 2.14.5, 6 August 2020 * Resolve issue2650 This is a stupid and rather unfortunate bug that affects all previous versions of the 2.12 and 2.14 branch. It can lead to corruption of the _darcs/format file in repos where *future* darcs versions add an alternative format property. The bug affects commands rebase suspend, rebase pull, and rebase apply. It is possible to manually fix the corruption by deleting from _darcs/format strings of the form "Unknown property: ". Future releases will contain a work-around that automatically fixes this particular kind of corruption when reading the format file, in case it should ever happen in practice. Nevertheless we strongly recommend to upgrade and avoid using the darcs versions affected by this bug. Darcs 2.14.4, 28 April 2020 * Restored the ability to run our shell tests, at least when building directly from a clone of our darcs repo. This was done by importing an old version of shelly (1.7.1, the last that worked for us on Windows), so that (modern) cabal picks that version instead of the newest one from hackage. Then made it build with all supported ghc versions and fixed all warnings. * Fix the quick-and-dirty "solutions" to the MonadFail incompatibility that replaced fail with error to avoid cascading MonadFail requirements all over the place. This broke a number of our tests, proving it to be semantically unsound, as I had expected. In most cases the correct solution was to replace it with (throw . userError), or if possible with (liftIO . fail). Darcs 2.14.3, 24 April 2020 * Support for GHC 8.8 and GHC 8.10 * Loosen upper bounds for a few dependencies * mitigate issue 2643 (corrupt patch index) with a better error message * remove our own optimisation settings in darcs.cabal * Setup.hs: allow use of darcs as a cabal subproject Darcs 2.14.2, 26 January 2019 * Support GHC 8.6 (Ganesh Sittampalam) * Some other dependency bumps (Ganesh Sittampalam) * Fixed the following bugs: * 2617 convert import crashes with out-of-order tags (Ben Franksen) Darcs 2.14.1, 24 June 2018 * Some dependency bumps (Ganesh Sittampalam, Ben Franksen, Guillaume Hoffmann) * Windows test fixes (Ganesh) * Fixed the following bugs: * 2588 clone creates target repo with wrong permissions (Ben) Darcs 2.14.0, 4 April 2018 * fix encoding business, make DARCS_DONT_ESCAPE_8BIT=1 default (Ben, Ganesh Sittampalam) * show explicit dependencies in `darcs log -s` (Gian Piero Carrubba) * improve bash/zsh completion (Ben, Gian Piero) * no longer print an error message when ctrlc'ing pager (Guillaume Hoffmann) * `darcs help markdown` mentions all files in `_darcs/prefs/` (Guillaume) * add patch index status to `show repo` command (Ben) * per-file conflict marking (Ben Franksen) * make it possible to use DARCS_SCP=rsync (Ben) * add --not-in-remote option to unrecord command (Ben) * plug memory leak and improve efficiency in annotate (Ben) * save unneeded FL/RL reverses in SelectChanges module (Ben) * optimize token replace code and --look-for-replaces (Ben) * no longer show conflicting files on `whatsnew -s`, will reintrodue this feature when it is done efficiently (Guillaume) * separate display and storage of patches (Ben) * support GHC 8.2 and GHC 8.4 (Ganesh) * many refactorings in Darcs.Repository modules and API (Ben, Guillaume) * no longer track build dependencies in Setup.hs, nor use alpha, beta, rc names (Guillaume) * refactor `pull --reorder-patches` (Ben) * refactor SelectChanges (Ben) * remove Patchy typeclass and redundant constaints where possible (Guillaume) * fix build with cabal new-build (Francesco Ariis) * unit and quickcheck tests for inventories (Ben) * throw out all access to bytestring internals from Darcs.Util.ByteString (Ben) * refactor, simplify, and document hunk application (Ben) * drop support of old cache location and SHA1-hashed repos (Guillaume) * rely on GHC's own stack traces for bug reporting (Guillaume) * fixed the following bugs: * fix mail encoding with '.' or '=' as last character (Timo von Holtz) * 2526: whatsnew -l --boring should list boring files (Ben) * 2208: replace detects existing force hunks in working (Ben) * 2512: author name is written to repository after multiple-choice prompt (Stephan-A. Posselt) * 2359: convert --export mishandles Unicode filenames (Ben) * 2545: prevent argument smuggling in SSH repository URLs (Gian Piero) * 2581: fix rebase pull --reorder (Ben) * 2575: fix unrevert with rebase (Ben) * 2579: allow darcs send to work even if no MTA is installed * 2555: include explicit dependencies in the output of `log -v` (Gian Piero) * 2569: decoding multibyte characters (Ben) * 2563: create remote repo in correct format in ssh tests (Ben) * 2565: create _darcs dir after searching for an existing one (Ben) * 2567: darcs whatsnew --unified (Ben) * 2566: avoid renaming across file systems (Ben) * 2564: delete wrong and irrelevant propConcatPS (Guillaume) * 2559: remove trailing empty lines in patch header edition (Guillaume) * 2536: mask out internal matchers in `show files` routing logic (Gian Piero) Darcs 2.12.5, 11 January 2017 * Bump some dependency upper bounds (Ganesh Sittampalam) * Fix issue2516 - failure cloning from URLs on Windows (Ben Franksen) Darcs 2.12.4, 14 September 2016 * *really* fix compile error under Windows (Guillaume Hoffmann) Darcs 2.12.3, 10 September 2016 * fix compile error under Windows (Guillaume Hoffmann) Darcs 2.12.2, 7 September 2016 * fix missing testsuite file in tarball (Guillaume Hoffmann) Darcs 2.12.1, 5 September 2016 * fix building with GHC 8 * drop support for GHC 7.6 and 7.8, i.e., require GHC 7.10 * improvements in `darcs whatsnew` output with irrelevant files (Ben Franksen) Darcs 2.12.0, 29 April 2016 * `darcs show dependencies`: export patch dependency graph as dot file (Ale Gadea) * improvements in `record` output with irrelevant files (Ben Franksen) * `darcs log -v --machine-readable`: show internal representation of patches (including explicit dependencies). Remove patch viewing via the `annotate` command. (Guillaume Hoffmann) * `whatsnew -s` (and `status`) show conflicting files (Guillaume Hoffmann) * honor "quiet" flag in command outputs (Ben Franksen) * a single `show patch-index` command (Guillaume Hoffmann) * remove deprecated aliases of show (Guillaume Hoffmann) * handle file moves natively when importing from git (Owen Stephens) * require GHC 7.6 (base > 4.6) and support GHC 8 (Ganesh Sittampalam) * switch to sandi from dataenc (Daniil Frumin) * remove hack to enable arbitrary protocols via env variables (Guillaume Hoffmann) * fixed the following bugs: * 1807: clarify help of PAGER, DARCS_PAGER (Guillaume Hoffmann) * 2258: improve patch index error message with suggestion (Guillaume Hoffmann) * 2269: push hijack test to suspend time (Eric Kow) * 2276: Keep track of patch hijack decisions (Eric Kow) * 2138: report conflicting files in whatsnew -s (Guillaume Hoffmann) * 2393: remove whatsnew functionality from annotate (Guillaume Hoffmann) * 2400: use async package to keep track of unpack threads (Ben Franksen) * 2459: fall back to writing the file if createLink fails (Ben Franksen) * 2479: root dir most not be among the sources of a move (Ben Franksen) * 2481: expose API for 'darcs diff' command (Ganesh Sittampalam) * 2486: obliterate --not-in-remote -q should be more quiet (Ben Franksen) * 2489: dequote filepaths while importing from git (Guillaume Hoffmann) * 2494: output of darcs record with file arguments (Ben Franksen) Darcs 2.10.3, 29 January 2016 * implement weak repository hash and show it in "darcs show repo" * implement "whatsnew --machine-readable" for more parsability * enhance Git import: empty directories, unescape file names, unnamed commits * make commit an alias for record * expose API for "darcs diff" * force grep to treat output of locale as text * bump dependencies: vector, process, HUnit, binary, transformers, time, HTTP, transformers-compat Darcs 2.10.2, 9 November 2015 * switch from dataenc (deprecated) to sandi * finish updating help strings with new command names * make patch selection lazier in presence of matchers * clean contrib scripts * switch patches retrieval order when using packs * disable mmap on Windows * enhance darcs send message * fix quickcheck suite * optimize patch apply code memory use * shorter README with quickstart instructions * fixed the following bugs: * 2457: fix darcs-test command line options * 2463: building darcs on powerpc * 2444: added default interactivity parameter to isInteractive Darcs 2.10.1, 9 July 2015 * generalized doFastZip for darcsden support * support terminfo 0.4, network 2.6, zlib 0.6, quickcheck 2.8 and attoparsec 0.13 * errorDoc now prints a stack trace (if profiling was enabled) * beautified error messages for command line and default files * fixed the following bugs: * 2449: test harness/shelly: need to handle mis-encoded/binary data * 2423: diff only respecting --diff-command when a diff.exe is present * 2447: get contents of deleted file * 2307: add information about 'darcs help manpage' and 'darcs help markdown' * 2461: darcs log --repo=remoterepo creates and populates _darcs * 2459: cloning remote repo fails to use packs if cache is on a different partition Darcs 2.10.0, 19 April 2015 * Important changes in Darcs 2.10 * darcs rebase: enable deep amending of history * darcs pull --reorder: keep local-only patches on top of mainstream patches * darcs dist --zip: generate a zip archive from a repository * patch bundle contexts are minimized by default. * darcs convert export/import for conversion to/from VCSes supporting the fast-export protocol * darcs test --backoff: exponential backoff test strategy, faster than bisect on big repositories * work normally on sshfs-mounted repositories * automatic detection of file/directory moves, and of token replaces * patience diff algorithm by default * interactive mode for whatsnew * tag --ask-deps: create tags that may not include some patches * add a last question after all patches have been selected to confirm the whole selection * command names: * `clone` is the new name of `get` and `put` * `log` is the new name of `changes` * `amend` is the new name of `amend-record` * show output of `log` into a pager by default * the output of `log` is more similar to git's: * show patch hash in UI (hash of the patch's metadata) * put author and date on separate lines * enable to match on patch hash prefix with -h and --hash * better messages: * better error messages for http and ssh errors * `init`, `add`, `remove`, `move` and `replace` print confirmation messages * `rollback` only happens in the working copy * `darcs send` no longer tries to send a mail by default * when no patch name given, directly invoke text editor * use nano as default text editor instead of vi * keep log files for patch name and mail content in _darcs * `optimize` and `convert` are now supercommands * improve `darcs help environment` and `darcs help markdown` * warn about duplicate tags when creating a new one * allow `darcs mv` into known, but deleted in working, file * improve` --not-in-remote`, allowing multiple repos and use default * faster `darcs diff` * faster `log` and `annotate` thanks to patch index data structure * faster push via ssh by using compression * cloning to an ssh destination (formerly `darcs put`) is more efficient * faster internal representation of patch hashes * when cloning from http, use packs in a more predictable way * store global cache in bucketed format * require and support GHC 7.4 to 7.10 * Other issues resolved in Darcs 2.10 * 346: implement "patience diff" from bzr * 642: Automatic detection of file renames * 822: generalized the IO Type for better error messages and exception handling * 851: interactive mode for whatsnew * 904: Fix record on Linux/FUSE/sshfs (fall back to sloppy locks automatically) * 1066: clone to ssh URL by locally cloning then copying by scp * 1268: enable to write darcs init x * 1416: put log files in tempdir instead of in working dir * 1514: send --minimize-context flag for send * 1624: bucketed cache * 1828: file listing and working --dry-run for mark-conflicts * 1987: Garbage collection for inventories and patches * 2181: put cache in $XDG_CACHE_HOME (~/.cache by default) * 2193: make that finalizeTentativeChanges no longer run tests * 2198: move repo testing code to Darcs.Repository.Test * 2200: darcs replace complains if no filepaths given * 2204: do not send mail by default * 2237: prevent patch index creation for non-hashed repos * 2235: Accept RFC2822 dates * 2246: add default boring entry for emacs session save files * 2253: attempting to use the patch index shouldn't create it on OF repos * 2278: Document default value for --keep-date / --no-keep-date * 2199: getMatchingTag needs to commute for dirty tags * 2247: move patch index creation into the job running code * 2238: let optsModifier remove all occurrences of LookForAdds * 2236: make 'n' an alias for 'q' in lastregret questions * 2155: Expurgate the non-functional annotate --xml-output option * 2248: always clean up rebase-in-progress state * 2270: fixed darcs changes -i --only-to-files * 2282: don't allow remote operations to copy the rebase patch * 2287: obliterate -O doesn't overwrite existing file. * 2227: move the rebase patch to the end before an amend-record * 2277: rebase suspend and unsuspend supports --summary. * 2311: posthook for 'get' should run in created repo * 2312: posthooks for 'record' and 'amend-record' should receive DARCS_PATCHES * 2163: new option for amend, select author for patch stealing. * 2321: when no patch name given, directly invoke text editor * 2320: save prompted author name in ~/.darcs/author instead of ./_darcs/prefs/author * 2250: tabbing in usageHelper - pad by max length of command name * 2309: annotate includes line numbers * 2334: fix win32 build removing file permission functions * 2343: darcs amend-record does not record my change * 2335: one liner when adding tracked files if not verbose * 2313: whatsnew -l: Stack space overflow * 2347: fix amend-record --prompt-long-comment * 2348: switch to cabal's test framework * 2209: Automatically detect replace * 2332: ignore case of characters in prompt * 2263: Option --set-scripts-executable is not properly documented * 2367: rename amend-record to amend, make --unrecord more visible * 2345: solution using cabal's checkForeignDeps * 2357: switching to regex-compat-tdfa for unicode support * 2379: only use packs to copy pristine when up-to-date * 2365: correctly copy pristine in no-working-dir clones * 2244: darcs tag should warn about duplicate tags * 2364: don't break list of 'bad sources' * 2361: optimize --reorder runs forever with one repository * 2364: fix file corruption on double fetch * 2394: make optimize a supercommand * 2396: make convert a supercommand and enhance help strings * 2314: output-auto-name in defaults file * 2388: check if inventories dir has been created * 2249: Rename isFile to isValidLocalPath and WorkRepoURL to WorkRepoPossibleURL * 2153: allow skipping backwards through depended-upon patches * 2380: allow darcs mv into known, but deleted in working, file * 2403: need to avoid moving the rebase patch to the end * 2409: implement darcs rebase apply * 2385: invoke pager without temporary file * 2333: better error message when pushing and darcs not in path Darcs 2.8.5, 25 August 2014 * GHC 7.8 support * Resolved issue2364: Download problems with GHC 7.8 * Support matching on short patch hash * Resolved issue2345: Fix bug where configure script reported missing libiconv rather than libcurl Darcs 2.8.4, 7 February 2013 * GHC 7.6 support * Resolved issue2199: get --tag can include extra patches * Removed the --xml-output option to annotate which has been non-functional for a while Darcs 2.8.3, 4 November 2012 * Tweak the library to avoid a C symbol clash with cryptohash Darcs 2.8.2, 2 September 2012 * Addition to the Darcs API to support darcsden Darcs 2.8.1, 14 May 2012 * Bumped mtl dependency * Updated contact details to use development mailing list Darcs 2.8, 22 April 2012 * Important changes in Darcs 2.8 * Local support for the legacy "old-fashioned" repository format has been removed. * You can still work with remote repositories in this format * Local repositories can still be upgraded via "darcs optimize --upgrade". * "darcs annotate" is now significantly faster and uses less memory, although it still slows down linearly with repository size. * An experimental option is available to speed up HTTP downloads. * You can now use "darcs optimize --http" to create a repo optimized for HTTP downloads, and use "darcs get --packs" to download such a repo. * There are still some known issues with it, so the feature is not enabled by default. * Darcs now supports multiple email addresses for the author in the global prefs file. So, if you use different identities for home and work, you can now easily select between them. (issue1530) * The -o/-O options for obliterate which were removed in 2.5 are back. * "darcs status" has been added as a hidden alias for "darcs whatnew -ls" to ease the transition from some other source control systems. (issue182) * "darcs amend-record" now has the option --unrecord to allow individual changes to be unrecorded. (issue1470). This can also be used as "darcs amend-unrecord". * "darcs amend-record"'s interactive selection now supports 'k' for going back to a previous patch. * "darcs dist" now has the option --set-scripts-executable. (issue734) * pushing to ssh:// URLS is now supported. eg: darcs push ssh://code.haskell.org/foo * If a test fails during darcs record, you now have the option to record it anyway. (issue332) * Hunk-splitting now works in "darcs revert" (issue114) * Sending patches by email is now more robust and human friendly. We display a cleaner version in plain text for humans, and have added a complete version of the patch for "darcs apply". (issue1350) * "darcs send" now tries to report the right character set in the email headers, and has the option --charset to override this. * A new environment variable has been added to help control network connections: DARCS\_CONNECTION\_TIMEOUT. See the manual for details. * The --ephemeral and --partials options to "darcs get" has been removed. "darcs check --partial" has also been removed. * "darcs rollback" now has a --no-record option, to be used when you only want to update the working directory. * The --nolinks option for "darcs get" was removed. * The "--old" flag has been removed for "darcs init", "darcs get" and "darcs put". * "darcs resolve" has been removed an alias for "darcs mark-conflicts". * "darcs init" and "darcs get" now have a --no-working-dir option. * Conflicts are now marked with red in the terminal. (issue1681) * ssh ControlMaster support has been removed. * ssh stderr output is now passed through, making it easier to diagnose problems. (issue845) * Interactive selection now has a 'g' command to go to the first patch. * The --unified flag is now available for record, end-record, revert and unrevert (issue1166) * darcs now has a "darcs test" command for running whatever test-suite is associated with the repository. * Other issues resolved in Darcs 2.8 * 1266: "darcs init" now warns when run inside another darcs repo. * 1344: When using darcs send, let users know sooner if they won't eventually be able to send * 1397: darcs changes /bad /paths no longer lists all changes * 1473: problem with annotate --repodir * 1551: Now we only use 'file content did not change' prompt for darcs send * 1558: xml output for patch hash no longer includes "gz" extension * 1599: automatically expire unused caches * 1637: When darcs get fails due to a HTTP failure, port the actual HTTP failure. * 1640: darcs apply --verbose docs have been improved * 1661: darcs add --quiet is quieter * 1705: fix error with unhandled --index in "darcs show contents" * 1714: provide more sensible behavior when combining an "ALL" default with a default for a specific sub-command * 1727: a better diagnostic message is provided when the user tries to move the root of the repository * 1740: "darcs mv" now gracefully the handles the case where the user first does an "mv" on a directory and then follows up with a "darcs mv" * 1804: The diagnostic message "getSymbolicLinkStatus: does not exist" has been improved * 1883: rename --patch-name option to --name. This is usually used in darcs record in shorthand (-m) form. This rename is aimed at eliminating the confusion with the patch matcher, which bites amend-record and rollback users. * 1884: darcs get was wrongly reporting "getting lazy repository" when you hit C-c * 1908: try to create a global cache before checking its availability * 1922: Fixed bug where obliterate -o was producing incorrect bundles in some cases * 1923: bad source warning mechanism no longer warns about sources outside your control * 1932: Handling of files with colons is improved * 1965: attempting "darcs move" on non-repo files now gives a sensible error * 1977: "darcs repair" now no longer complains if the pristine.hashed directory is missing * 1978: Improve handling of the _darcs/format file with "darcs get" * 1984: "darcs convert" now gives a better error message for invalid repo names * 2013: "darcs send" no longer ignores --to (or default recipient) with --context * 2021: character encoding handling has been improved * 2041: "darcs add" no longer follows directory symlinks * 2054: The behavior when combining --boring with a boring file has been improved * 2066: "darcs record" better handles adding deleted and added files passed on the command line * 2067: darcs diff no longer outputs blank lines when non-existent files are given * 2076: "darcs move myfile" into directory confuses darcs * 2077: "darcs mv myfile" into directory no longer confuses darcs * 2079: "darcs put" now does --set-default by default Darcs 2.5.2, 14 March 2011 * Important changes in Darcs 2.5.2 * compatible with Haskell Platform 2011.2.0.0 * bump parsec dependency for HP compatibility * fix regression allowing to add files inside boring directories * Issues resolved in Darcs 2.5.2 * 2049: Darcs regression: 2.5 creates a broken patch Darcs 2.5.1, 10 February 2011 * Important changes in Darcs 2.5.1 * original text is included in conflict marks * GHC 7.0 is supported * the version of GHC is restricted in the cabal file * warning message about old-fashioned repositories points to wiki * non-repository paths are guarded * library API: program name is configurable * darcs send prints the remote repository address right away * informational message about --set-default is disabled with --no-set * _darcs/format is correctly handled on get * linking libdarcs on Windows is fixed * Issues resolved in Darcs 2.5.1 * 1978: get does not correctly treat _darcs/format * 2003: Message about --set-default should be optional * 2008: build with GHC 7.0 * 2015: linking with libdarcs broken under Windows (2.5.0) * 2019: allow building with mtl 2 * 2035: darcs accepts fake subpaths (relative paths outside of the repo) Darcs 2.5, 30 October 2010: * Important changes in Darcs 2.5 * trackdown can now do binary search with the --bisect option * darcs always stores patch metadata encoded with UTF-8 * diff now supports the --index option * amend-record now supports the --ask-deps option * apply now supports the --match option * amend-record has a new --keep-date option * inventory-changing commands (like record and pull) now operate in constant time with respect to the number of patches in the repository * the push, pull, send and fetch commands no longer set the default repository by default * the --edit-description option is now on by default for the send command * Issues resolved in Darcs 2.5 * 64: store metadata as UTF-8 * 121: add --ask-deps support to amend-record * 643: darcs send -o outputs remote repo email address * 1159: avoid bogus repository cache entries * 1176: caches interfere with --remote-repo flag * 1208: add trackdown --bisect * 1210: global cache gets recorded in _darcs/prefs/sources * 1232: darcs convert copies _darcs/prefs/prefs * 1250: check for newlines in setpref values * 1277: percolate repository format errors correctly * 1288: the main darcs code now compiles and runs with witnesses * 1290: support diff --index * 1337: don't show unrelated patches in darcs changes on untracked path * 1389: change predist pref to point people to use 'cabal sdist' * 1427: accept gzipped patch bundles in darcs apply * 1456: make dist write more portable archives * 1473: make annotate accept '.' as argument * 1503: prefer local caches to remote ones * 1713: shorter interactive prompts * 1716: allow mail header lines of all whitespace in test * 1719: do not back up files when no conflict markers are inserted * 1726: don't consider all files with _darcs prefix boring * 1739: make ColorPrinter handle characters > 255 * 1763: use correct filename encoding in conflictors * 1765: refuse to remove non-tracked directories recursively * 1769: add support for --match 'comment ...' * 1784: push and pull print remote address right away * 1815: work around Cabal sdist permissions issue * 1817: fix support for external merge tools * 1824: avoid PACKAGE_VERSION under Windows * 1825: do not omit important prims in unrecordedChanges w/ files * 1860: (un)applying move patches doesn't corrupt pristine * 1861: fix typo in --no-boring help * 1874: recognise network tests on cabal test command line * 1875: avoid accidentally setting default * 1879: notice unexpected commute failure on merge * 1887: add a missing newline to --list-options output * 1893: move fields of conditional builds within scope of condition * 1898: notify user when they can use set-default * 1913: sort changes in treeDiff Darcs 2.4.4, 9 May 2010 * Important changes in Darcs 2.4.4 * darcs builds on Windows with GHC 6.10 (and GHC 6.12). * darcs (built with GHC 6.12 on Windows) works with SSH again * Issues resolved in Darcs 2.4.4 * 1814: Apply binary mode to ssh process and patch file handles. Darcs 2.4.3, 9 May 2010 * Important changes in Darcs 2.4.3 * darcs builds on Windows with GHC 6.12. Darcs 2.4.2, 8 May 2010 * Important changes in Darcs 2.4.2 * darcs will no longer give "mmap of _darcs_index" errors on Windows * darcs convert performance regression (against 2.3.x) solved * darcs get --partial no longer produces inconsistent repositories * Issues resolved in Darcs 2.4.2 * 1761: mmap of '_darcs/index' failed on Windows mapped drives * 1814: include contrib/darcs-errors.hlint in release tarball * 1823: read (mmap) _darcs/index file correctly on Windows * 1826: error building on Windows with GHC 6.12 * 1837: inconsistent repository upon darcs get --partial Darcs 2.4.1, 31 March 2010 * Important changes in Darcs 2.4.1 * darcs works again on Windows shared directories * missing documentation and test files have been added to the tarball * darcs will no longer give errors about a nonexistent file when compiled with the wrong mmap * moving files between directories can no longer break the directory index * darcs handles the case that someone uses 'remove -r' on an untracked directory * Bugs Fixed in Darcs 2.4.1 * 1750: uncover help text for 'darcs show pristine' * 1753: restrict mmap to version used by hashed-storage * 1754: fix issue458.sh on systems with xattrs * 1756: moving files between directories breaks index * 1757: add test files to distribution tarball * 1765: refuse to remove non-tracked directories recursively * 1767: send CRC erros to standard error Darcs 2.4, 27 February 2010 * Important changes in Darcs 2.4 * Use fast index-based diffing everywhere (Petr) * Interactive patch splitting (Ganesh) * An 'optimize --upgrade' option to convert to hashed format in-place (Eric) * Hunk matching (Kamil Dworakowski, tat.wright) * Progress reporting is no longer deceptive (Roman) * A 'remove --recursive' option to remove a directory tree from revision control (Roman) * 'show files' accepts arguments to show a subset of tracked files (Luca) * A '--remote-darcs' flag for pushing to a host where darcs isn't called darcs * Many miscellaneous Windows improvements (Salvatore, Petr and others) * 'darcs send' now mentions the repository name in the email body (Joachim) * Handle files with boring names in the repository correctly (Petr) * Fix parsing of .authorspellings file (Tomáš) * Various sane new command-line option names (Florent) * Remove the '--checkpoint' option (Petr) * Use external libraries for all UTF-8 handling (Eric, Reinier) * Use the Haskell zlib package exclusively for compression (Petr) * Bugs Fixed in Darcs 2.4 * 183: do not sort changes --summary output * 223: add --remote-darcs flag to specify name of remote darcs executable * 291: provide (basic) interactive patch splitting * 540: darcs remove --recursive * 835: 'show files' with arguments * 1122: get --complete should not offer to create a lazy repository * 1216: list Match section in ToC * 1224: refuse to convert a repo that's already in darcs-2 format * 1300: logfile deleted on unsucessful record * 1308: push should warn about unpulled patches before patch-selection * 1336: sane error message on --last "" (empty string to numbers parser) * 1362: mention repo name in mail send body * 1377: getProgname for local darcs instances * 1392: use parsec to parse .authorspelling * 1424: darcs get wrongly reports "using lazy repository" if you ctrl-c old-fashioned get * 1447: different online help for send/apply --cc * 1488: fix crash in whatsnew when invoked in non-tracked directory * 1548: show contents requires at least one argument * 1554: allow opt-out of -threaded (fix ARM builds) * 1563: official thank-you page * 1578: don't put newlines in the Haskeline prompts * 1583: on darcs get, suggest upgrading source repo to hashed * 1584: provide optimize --upgrade command * 1588: add --skip-conflicts option * 1594: define PREPROCHTML in makefile * 1620: make amend leave a log file when it should * 1636: hunk matching * 1643: optimize --upgrade should do optimize * 1652: suggest cabal update before cabal install * 1659: make restrictBoring take recorded state into account * 1677: create correct hashes for empty directories in index * 1681: preserve log on amend failure * 1709: fix short version of progress reporting * 1712: correctly report number of patches to pull * 1720: fix cabal haddock problem * 1731: fix performance regression in check and repair * 1741: fix --list-options when option has multiple names * 1749: refuse to remove non-empty directories Darcs 2.3.1, 20 Sep 2009 * Important changes in Darcs 2.3.1 * Fix bugs introduced by optimizations in 2.3.0 (Petr, Salvatore) * Documentation improvements (Taylor, Trent) * Remove autoconf build system (Petr) * Bugs Fixed in Darcs 2.3.1 See http://bugs.darcs.net/issueN for details on bug number N. * issue1373 darcs manual wrongly promises [^ ] is a valid token spec (Trent) * issue1478: document summary mnemonics (Trent) * issue1582 DeleteFile: permission denied (Access is denied.) (Salvatore) * issue1507 whatsnew does not use 'current' when 'pristine' is missing (Petr) Darcs 2.3.0, 23 Jul 2009 * Important changes in Darcs 2.3.0 * Lots and lots of documentation changes (Trent). * Haskeline improvements (Judah). * Cabal as default buildsystem (many contributors). * Fixes in darcs check/repair memory usage (Bertram, David). * Performance improvement in subtree record (Reinier). * New option: --summary --xml (Florian Gilcher). * New option: changes --max-count (Eric and Petr). * Fix changes --only-to-files for renames (Dmitry). * Performance fix in "darcs changes" (Benedikt). * Hardlinks on NTFS (Salvatore). * Coalesce more changes when creating rollbacks (David). * New unit test runner (Reinier). * Inclusion of darcs-shell in contrib (László, Trent). * Author name/address canonisation: .authorspellings (Simon). * Working directory index and substantial "darcs wh" optimisation (Petr). * New command: "darcs show index" (Petr). * Gzip CRC check and repair feature (Ganesh). * Bugs Fixed in Darcs 2.3.0 See http://bugs.darcs.net/issueN for details on bug number N. * 948 darcsman (Trent) * 1206 countable nouns (Trent) * 1285 cabal test v. cabal clean (Trent) * 1302 use resolved, not resolved-in-unstable (Trent) * 1235 obliterate --summary (Rob) * 1270 no MOTD for --xml-output (Lele) * 1311 cover more timezones (Dave) * 1292 re-encoding haskeline input (Judah) * 1313 clickable ToC and refs in PDF manual Trent) * 1310 create merged \darcsCommand{add} (Trent) * 1333 better "cannot push to current repository" warning (Petr) * 1347 (autoconf) check for unsafeMMapFile if mmap use enabled (Dave) * 1361 specify required includes for curl in cabal file (Reinier) * 1379 remove libwww support (Trent) * 1366 remove unreachable code for direct ncurses use (Trent) * 1271 do not install two copies of darcs.pdf (Trent) * 1358 encode non-ASCII characters in mail headers (Reinier) * 1393 swap "darcs mv" and "darcs move" (Trent) * 1405 improve discoverability of global author file (Trent) * 1402 don't "phone home" about bugs (Trent) * 1301 remove obsolete zsh completion scripts (Trent) * 1162 makeAbsolute is now a total function (Ben F) * 1269 setpref predist - exitcode ignored bug (Ben M) * 1415 --edit-long-comment, not --edit-description, in help (Trent) * 1413 remove duplicate documentation (Trent) * 1423 complain about empty add/remove (Trent) * 1437 Implement darcs changes --max-count (Eric) * 1430 lazy pattern matching in (-:-) from Changes command module (Dmitry) * 1434 refactor example test (Trent) * 1432 refer to %APPDATA%, not %USERPROFILE% (Trent) * 1186 give a chance to abort if user did not edit description file (Dmitry) * 1446 make amend-record -m foo replace only the patch name (Dmitry) * 1435 default to get --hashed from a darcs-1.0 source (Trent) * 1312 update and reduce build notes (Trent) * 1351 fix repository path handling on Windows (Salvatore) * 1173 support hard links on NTFS (Salvatore) * 1248 support compressed inventories for darcs-1 repos (Ganesh) * 1455 implement "darcs help environment" (Trent) Darcs 2.2.0, 16 Jan 2009 * Important changes in Darcs 2.2.0 * Support for GHC 6.10. * Improved Windows support. * Cabal is now supported as a build method for darcs. * Low-level optimisations in filesystem code. * Overhaul of the make-based build system. * Extensive manual and online help improvements. * Improved API documentation (haddock) for existing darcs modules. * Improvements in the testing infrastructure. * Improved performance for "darcs repair". * Improved robustness for "darcs check". * Numerous major and minor bug fixes, refactorings and cleanups. * When recording interactively it is now possible to list all currently selected hunks (command 'l'). * It is now possible to specify --in-reply-to when using darcs send, to generate correct references in the mail header. * Repositories can no longer be created with --no-pristine-tree. This only affects the legacy darcs-1 repository format. * Experimental Darcs library, providing increase flexibility and efficiency to third-party utilities (compared to the command-line interface). Only built via Cabal. NOT a stable API yet. * Bugs Fixed in Darcs 2.2.0 See http://bugs.darcs.net/issueN for details on bug number N. * 525 amend-record => darcs patches show duplicate additions * 971 darcs check fails (case sensitivity on filenames) * 1006 darcs check and repair do not look for adds * 1043 pull => mergeAfterConflicting failed in geteff (2.0.2+) * 1101 darcs send --cc recipient not included in success message * 1117 Whatsnew should warn on non-recorded files * 1144 Add darcs send --in-reply-to or --header "In-Reply-To:... * 1165 get should print last gotten tag * 1196 Asking for changes in /. of directory that doesn't exist... * 1198 Reproducible "mergeConflictingNons failed in geteff with ix" * 1199 Backup files darcs added after external merge * 1223 sporadic init.sh test failure (2.1.1rc2+472) * 1238 wish: darcs help setpref should list all prefs * 1247 make TAGS is broken * 1249 2.1.2 (+ 342 patches) local drive detection on Windows error * 1272 amend-record not the same as unrecord + record * 1273 renameFile: does not exist (No such file or directory) * 1223 sporadic init.sh test failure (2.1.1rc2+472) darcs (2.1.2) * Quality Assurance: Disable a new test that was not yet working under Windows -- Eric Kow Mon, 10 Nov 2008 10:40:00 GMT darcs (2.1.1) -- Eric Kow Mon, 10 Nov 2008 08:18:00 GMT darcs (2.1.1rc2) * Portability: Removed accidental QuickCheck 2.1 configure check. Note that it may be required in a future version of darcs. -- Eric Kow Mon, 10 Nov 2008 11:17:00 GMT darcs (2.1.1rc1) * Portability: GHC 6.10.1 support (Petr Ročkai, Eric Kow) * Bug Fix: Fix file handle leak and check for exceptions on process running on Windows (issue784, Salvatore Insalaco) * Quality Assurance: Consolidated regression test suites using shell scripts only (Eric Kow, Tommy Petterson, Matthias Kilian) -- Eric Kow Mon, 10 Nov 2008 09:49:00 GMT darcs (2.1.0) * Bug Fix: Eliminate a 'same URLs with different parameters' error when fetching files over HTTP (issue1131, Dmitry Kurochkin) * User Experience: Corrections to the default boring file (Ben Franksen) * Bug Fix: Fix the %a option in darcs send --sendmail-command (Ben Franksen) * Bug Fix: Do not obscure the SSH prompts or text editor output with progress reporting (issue1104, issue1109, Dmitry Kurochkin, David Roundy) * Bug Fix: pull --intersection work now works as advertised (Tommy Pettersson) -- Eric Kow Sun, 09 Oct 2008 12:05:32 GMT darcs (2.1.0pre3) * Bug Fix: Eliminate an error merging repeated conflicts in darcs-2 repositories (issue1043, David Roundy) * New Feature: Hide 'Ignore-this:' lines which will be generated by future versions of darcs to prevent patch-id collisions. (issue1102, Eric Kow, David Roundy) * Bug Fix: Support darcs repositories which have symbolic links in their paths (issue1078, Dmitry Kurochkin) * Bug Fix: Make ssh connection sharing (darcs transfer-mode) work with old-fashioned repositories (issue1003, David Roundy) -- Eric Kow Sun, 02 Oct 2008 09:12:41 GMT darcs (2.1.0pre2) * IMPORTANT: Create darcs-2 repositories by default in darcs init (issue806, David Roundy) * User Experience: Do not allow users to add files to a darcs repository if their filenames would be considered invalid under Windows. This can be overridden with the --reserved-ok flag (issue53, Eric Kow) * Bug Fix: Do not leave behind a half-gotten directory if darcs get fails (issue1041, Vlad Dogaru, David Roundy) * User Experience: notice when you are trying to pull from a seemingly unrelated repository, that is one with a sufficiently different history. This can be overridden with the --allow-unrelated-repos flag (Dmitry Kurochkin, David Roundy) * Bug Fix: Fix hang after a user input error (for example, EOF) (Judah Jacobson) * Quality Assurance: Improvements to documentation and online help (Simon Michael) -- Eric Kow Sun, 25 Sep 2008 08:10:49 GMT darcs (2.0.3pre1) * New Feature: Optional readline-like functionality when compiled with the haskeline package (Judah Jacobson, Gaëtan Lehmann) * Bug Fix: No more spurious pending patches (issue709, issue1012, David Roundy) * Bug Fix: darcs get --to-match now works with hashed repositories (issue885, David Roundy) * User Experience: Catch mistakes in _darcs/prefs/defaults (issue691, Dmitry Kurochkin) * User Experience: Improved support for darcs send over http (see also tools/upload.cgi) (Dmitry Kurochkin, David Roundy) * Bug Fix: Recognize user@example.com: as an ssh path, that is, not requiring a path after the server component. (David Roundy) * New Feature: Accept an optional directory argument in darcs send --output-auto-name (Dmitry Kurochkin) * User Experience: New --no-cache option to help debug network issues (issue1054, Dmitry Kurochkin) * Performance: New --http-pipelining and --no-http-pipelining flags. Passing --http-pipelining to darcs can make darcs get and pull faster over HTTP. Due to a libcurl bug, this is not the default option unless darcs is compiled with libcurl 7.19.1, due 2008-11. (Dmitry Kurochkin) * Bug Fix: Eliminate hanging and crashes while fetching files over HTTP (issue920, issue977, issue996, issue1037, Dmitry Kurochkin) * Security: Fix some insecure uses of printfs in darcs.cgi (Steve Cotton) * Bug Fix: Handle filepaths in a simpler and more robust fashion. This fixes relative filepaths and recognition of symbolic links and avoids possible future bugs (issue950, issue1057, David Roundy, Dmitry Kurochkin) * Bug Fix: Make darcs diff --patch work even if the patch is within a tag (issue966, darcs 2 regression, Dmitry Kurochkin) * Quality Assurance: Extend use of Haskell's GADTs to most of the darcs code, fixing many potential bugs along the way (Jason Dagit, David Roundy) * Quality Assurance: Several improvements to darcs code quality (Petr Ročkai) * Bug Fix: Correct assumptions made by darcs about Windows file size types (issue1015, Simon Marlow, Ganesh Sittampalam) * Bug Fix: Support case insensitive file systems using hashed repositories in darcs repair (partial issue971, Petr Ročkai). IMPORTANT: This introduces a memory use regression, which affects large repositories. We found that doing a darcs repair on the GHC repository requires a machine with 2 GB of RAM. The regression is well-understood and should be solved in the next darcs release. In the meantime we felt that the improved robustness was worth the performance trade-off. * Quality Assurance: Simplify building darcs on Windows by optionally using the zlib and terminfo Haskell packages (Ganesh Sittampalam, Petr Ročkai) * User Experience: Better error reporting when patches that should commute fail to do so. (Jason Dagit) * New Feature: --match "touch filenames", for example --match 'touch foo|bar|splotz.*(c|h)' (issue115, Dmitry Kurochkin) * User Experience: Improve debugging and error messages in HTTP code (Dmitry Kurochkin, David Roundy) * Bug Fix: Ensure that darcs responds to Ctrl-C on Window, even if compiled with GHC < 6.10 (issue1016, Simon Marlow) * New Feature: darcs changes --context now also works with --human-readable and --xml-output (issue995, Dmitry Kurochkin) * Bug Fix: Always darcs send with context, as if --unified flag were used (was implemented in 2.0.2, but not consistently) (David Roundy) * Bug Fix: Make sure that darcs get --tag works even when the user hits Ctrl-C to get a lazy repository (Dmitry Kurochkin) * Quality Assurance: Improvements to documentation and online help, most crucially, user-focused help on upgrading to darcs 2. (Trent Buck, Lele Gaifax, Simon Michael, Max Battcher) * New Feature: darcs changes --number associates each patch with number, counting backwards (see the --index feature) (David Roundy) * New Feature: ability to match patches on index, for example, darcs changes --index=3-6 shows the last three to six patches (David Roundy) * User Experience: slightly reduce the verbosity of darcs pull --verbose (David Roundy) -- Eric Kow Sun, 18 Sep 2008 02:36:45 GMT darcs (2.0.2) -- David Roundy Sun, 24 Jun 2008 01:20:41 GMT darcs (2.0.1) * Bug Fix: Make Ctrl-C work even though darcs is now compiled to use the threaded runtime (issue916, David Roundy) * New Feature: Include patch count in darcs --version, for example, 2.0.1 (+ 32 patches) (David Roundy) * Bug Fix: Avoid an error caused by renaming a file on case-insensitive file-systems (Eric Kow) * Bug Fix and New Feature: Improved XML output (Benjamin Franksen, Lele Gaifax, David Roundy) * User Experience: Always darcs send with context, as if --unified flag were used (David Roundy) -- David Roundy Sun, 23 Jun 2008 21:47:07 GMT darcs (2.0.1rc2) * Performance: Faster strings, using Data.Bytestring by default (Gwern Branwen, Eric Kow, Ian Lynagh, David Roundy) * User Experience: On Windows, use MS-DOS 'edit' as a default editor if Emacs and friends are not available (Eric Kow) * Bug Fix: On Windows, notice when external programs fail to launch because they do not exist (Eric Kow) * New Feature: darcs put --no-set-default and --set-default (Nicolas Pouillard) -- David Roundy Sun, 13 Jun 2008 01:17:45 GMT darcs (2.0.1rc1) * Bug Fix: Fix tag --checkpoint so that darcs get --partial can avoid fetching all patches (issue873, David Roundy) * User Experience: Better progress reporting [NB: darcs is now compiled with threaded runtime by default] (issue739, David Roundy, Bertram Felgenhauer) * Performance: Reduce memory usage of darcs put (David Roundy) * Bug Fix: Improved date matching (issue793, issue187, Eric Kow) * Performance: Fix an optimization in diff-detection (affects darcs whatsnew and record) (Pekka Pessi) * Quality Assurance: --enable-hpc for checking program coverage (Christopher Lane Hinson) * Bug Fix: Do not rollback if no primitive patches were selected (issue870, Eric Kow) * Bug Fix: Make it possible to --dry-run on repositories we cannot write to (issue855, Eric Kow, David Roundy) * Bug Fix: Avoid a race condition caused by cleaning out the pristine cache (issue687, David Roundy) * User Experience: When pushing, prints a small reminder when the remote repository has patches to pull (Eric Kow, David Roundy) * UI changes: --extended-help is now called --overview, no more --verify-hash, no more send --unified (David Roundy, Eric Kow) * User Experience: Show ssh's stderr output in case it wants to ask the user something (issue845, Eric Kow) * Bug Fix: Improved interaction with pager (David Roundy, Pekka Pessi, Eric Kow) * Bug Fix: darcs send -o - (Pekka Pessi) * Bug Fix: (regression) Re-enable darcs mv as a means of informing darcs about manual renames (issue803, David Roundy) * Bug Fix: Fix bugs related to use of threaded runtime (issue776, David Roundy) * Portability: Respect OS conventions in creation of temporary files (Eric Kow) * New Feature: Check for and repair patches which remove non-empty files (issue815, David Roundy) * Bug Fix: Make get --to-match work with hashed repositories (David Roundy) * Bug Fix: Conflict-handling with darcs-2 semantics (issue817, David Roundy) * Bug Fix: Make --ask-deps ask the right questions (Tommy Pettersson) * User Experience: Improved error messages and warnings (issue245, issue371, Nicolas Pouillard, David Roundy, Eric Kow) * New Feature: darcs trackdown --set-scripts-executable (Reinier Lamers) * Quality Assurance: Various improvements to documentation (issue76, issue809, Gwern Branwen, Lele Gaifax, Eric Kow, Nicolas Pouillard, David Roundy) * Bug Fix: Correct detection of incompatibility with future darcs (issue794, Eric Kow) * User Experience: Make darcs changes --interactive behave more like other interactive commands (Eric Kow) * Performance: Optimized handling of very large files (Gwern Branwen) * New Feature: Colorize added and removed lines, if the environment variable DARCS_DO_COLOR_LINES=True (Nicolas Pouillard) * New Feature: --remote-repodir flag to allow separate default repositories for push, pull and send (issue792, Eric Kow) * Performance: Optimized get --to-match handling for darcs 1 repositories (Reinier Lamers) * Bug Fix: Make changes --repo work when not in a repository (David Roundy) * New Feature: darcs changes --count (David Roundy) -- David Roundy Sun, 03 Jun 2008 12:43:31 GMT darcs (2.0.0) * Fix silly bug which leads to darcs --version not showing release when it's a released version. (David Roundy) -- David Roundy Sun, 07 Apr 2008 15:06:38 GMT darcs (2.0.0rc1) -- David Roundy Sun, 01 Apr 2008 15:44:11 GMT darcs (2.0.0pre4) * When darcs encounters a bug, check version versus central server in order to decide whether to recommend that the user report the bug. * Display duplicate identical changes when using darcs-2 repository format. (Issue579) * Fix a bug in convert that lead to invalid tags in the converted repository. (Issue585) * Add an annoying warning when users run convert. * Numerous fixes to the time/date matching code, which should now work even in central Europe. (Eric Kow) * Add support for reading hashed repositories that use SHA256 hashes. The plan is to enable writing of SHA256 hashes in the next release. (David Roundy) * New Feature: Add a 'show authors' command (Eric Kow) * darcs.cgi improvements: Patch pages show "Who" and "When" some file annotation pages show "who" and "when" with a mouse-over. Also, darcs.cgi can now be hosted in a path containing The tilde character. (Zooko, Mark Stosberg) * User Experience: Improved and added many debugging, error and progress messages (David Roundy, Mark Stosberg, Eric Kow) * New Feature: New DARCS_PATCHES, DARCS_FILES and DARCS_PATCHES_XML environment variables are made available for the posthook system, allowing for more easier options to to integrate darcs with other systems. (David Roundy, Mark Stosberg) * Quality Assurance: Added and updated automated regression tests (Mark Stosberg, David Roundy, Eric Kow, Trent Buck, Nicolas Pouillard, Dave Love, Tommy Pettersson) * Bug Fix: Gzipped files stored in the repo are now handled properly (Zooko, David Roundy) * Quality Assurance: Various Documentation Improvements (issue347, issue55 Mark Stosberg, Nicolas Pouillard, Marnix Klooster) * Bug Fix: With --repodir, commands could not be disabled (Trent Buck, David Roundy) * New Feature: tools/update_roundup.pl scripts allows the darcs bug tracker to be notified with a darcs patch resolving a particular issue is applied. A link to the patch in the web-based repo browser is provided in the e-mail notifying bug subscribers. (Mark Stosberg) * Internal: Begin work on memory efficiency improvements (David Roundy) * Performance: darcs is faster when identifying remote repos handling pending changes and running unrecord. (David Roundy) * Internal: Source code clean-up and improvements (David Roundy, Jason Dagit, Eric Kow, Mark Stosberg) * User Experience: A pager is used automatically more often, especially when viewing help. (Eric Kow) * Bug Fix: push => incorrect return code when couldn't get lock. (issue257, VMiklos, David Roundy, Eric Kow, Mark Stosberg) * Bug Fix: 'whatsnew' and 'replace' now work together correctly. (Nicolas Pouillard, David Roundy) -- David Roundy Sun, 21 Mar 2008 15:31:37 GMT darcs (2.0.0pre3) * Fix issue 244, allowing users of darcs changes to specify the new name of a file that has an unrecorded mv. (David Roundy, Mark Stosberg, Tuomo Valkonen) * Fix issue 600, bug in darcs optimize --relink. (David Roundy, Trent Buck, Mark Stosberg, Tommy Pettersson) * Add a new framework for outputting progress messages. If darcs takes more than about one second to run a command, some sort of feedback should now be provided. (David Roundy) * Rewrite rollback, changing its behavior to be more useful. Rollback now prompts for a name for the new "rollback" patches. It also allows you to roll back multiple patches simultaneously, and to roll back only portions of the patches selected. Altogether, rollback is now more interactive, and should also be more useful. (David Roundy) * Bug Fix: date parsing is now improved (Mark Stosberg, David Roundy) * Performance: Improved speed of darcs pull on very large repos. (David Roundy) * Fix issue 586, but in darcs repair on hashed and darcs-2 repositories. (Nicolas Pouillard) * Improve docs for 'darcs init' (Mark Stosberg) * Fix typo in test partial.sh which made part of the tests for --partial invalid. (Mark Stosberg) * Document that darcs handles some types of binary files automatically. (issue55, Mark Stosberg) * Fix typo in a test that made it compare a file to itself. (Mark Stosberg) * Document that single quotes should be used in .darcs/defaults. (issue347, Mark Stosberg) * New Feature: Automatically create the the global cache if we define we want to use it. (David Roundy, Trent Buck) * Performance: Improved HTTP pipelining support (Dmitry Kurochkin) * Fix issue 571, build failure when termio.h is not found. (Dave Love) -- David Roundy Sun, 22 Jan 2008 20:06:12 GMT darcs (2.0.0pre2) * Add instructions in documentation for how to view patches in Mutt (a mail reader). (Gwern Branwen) * Fix build on Solaris. (Dave Love) * Added "auto-optimize" support for hashed inventories, in that darcs automatically optimizes inventories when it seems wise (which is currently defined as "every time we modify the inventory"). * Fix expensive performance bugs involved in conflict handling. Thanks to Peter for pointing these out!. * Fix reading of hashed repositories to avoid reading patches that we don't actually need (i.e. foolish inefficiency bug). Thanks to Simon for reporting these performance bugs. * Added a new --debug flag for debug output. * Added compatibility with ghc 6.4. At this point darcs 2 should work with any ghc from 6.4 to 6.8.2. * Fix bug where parsing of setpref patch called tailPS unnecessarily. (David Roundy) * Refactor parsing of commands and command line arguments. Implement hidden commands. (Eric Kow) * Use a single command to initialize a remote repository. This replaces the method of stringing together multiple commands with the shell-dependent && operator. (Tristan Seligmann) * Allow for files in _darcs/inventories to be gzipped. This is not specifically related to issue553, but it fixes a regression introduced by the issue553 fix. (Issue553, Eric Kow) * Check for potential hash collision in writeHashFile. (Eric Kow) * Don't try to write hash file if it already exists, as you can not overwrite an open file on Windows. (Issue553, Eric Kow) * Close file handles when done reading it lazily. (Eric Kow) * Modernize and enhance buggy renameFile workaround by using the hierarchical library structure and only catching 'does not exist' errors. (Eric Kow) * Add "hidden" printer for decorating patches with color for easier reading when printed to screen during verbose or debug output, but hides (removes) the decoration when printing to the repository files. This is the counterpart of the invisible printer, which makes non-human-friendly patch contents invisible when printed to the screen. (David Roundy) * Add "hidden" printer, for printing things to screen but not file. (David Roundy) * Make darcs distinguish between repository sub paths and "normal" relative paths. Better handling of absolute paths. (Eric Kow) * Fix some bugs introduced by Better handling of file paths. (Eric Kow) * Handle corner case when polling from self. (issue354, issue358, Eric Kow) * Handle corner cases when pulling from current repository. (Issue354, Issue358, Eric Kow) * Fix bug in make_dotdots when pushing from a sub directory. (issue268, Eric Kow) * Fix bug in make_dotdots when pushing from a subdirectory. (Issue268, Eric Kow) * Better handling of file paths. Distinguish between paths to files belonging to the repository as well as not belonging to the repository, both in absolute and relative form. (Eric Kow) * Add path fixing to darcs send, and don't try sending to self. (issue427, Eric Kow) * Fix path issue for darcs send. (Issue427, Eric Kow) * Disable mmap under Windows. (issue320, Eric Kow) * Backup unmanaged working dir files as needed. (issue319, issue440, Eric Kow) * Backup unmanaged files in the working directory when they are overwritten by managed files with the same names in pulled or applied patches. (Issue319, Issue440, Eric Kow) * Offer some advice if sendmail failed. (issue407, Eric Kow) * Document behavior of "boring" managed files. (Issue259, Eric Kow) * Make Doc a newtype, so we can define a Show instance. (David Roundy) * Make make_changelog GHC 6.8 compliant. (Ganesh Sittampalam) * GHC 6.8 needs containers package. (Ganesh Sittampalam) * Configure hack to deal with openFd -> fdToHandle' renaming in GHC 6.8. (Ganesh Sittampalam) * Make makefile summarize calls to GHC when compiling. VERBOSE=1 turns the long format back on. (Eric Kow) * When building, print summarized call to GHC in makefile, instead of very long command lines with many boring options. VERBOSE=1 reverts to showing options again. (Eric Kow) * Add svg logo. (David Roundy) * Add mercurial files to the default boring file. (David Roundy) * Add patterns for mercurial files to default boring patterns. (David Roundy) * Define color versions of traceDoc and errorDoc for debugging. (David Roundy) * Clarify error message for --last. (issue537, Eric Kow) * Clarify in error message that darcs option --last requires a *positive* integer argument. (Issue537, Eric Kow) * Optimize getCurrentDirectorySansDarcs a little. (Eric Kow) * Never create temporary directories in the _darcs directory. (issue348, Eric Kow) * Never create temporary directories in the _darcs directory. (Issue348, Eric Kow) * Make revert short help less cryptic. (Eric Kow) * Make revert short help less cryptic. (Eric Kow) * Make --checkpoint short help more explicit. (issue520, Eric Kow) * Make --checkpoint short help more explicit. (Issue520, Eric Kow) * Add format infrastructure for darcs-2 repo format. (David Roundy) * Always optimize the inventory in 'darcs tag'. (Eric Kow) * Fix bug in Tag --checkpoint where the inventory was not updated. (Eric Kow) * Fix accidental regression of --no-ssh-cm flag. (Eric Kow) * Move conditional #include from Darcs.External to makefile. The GHC manual says that this is *not* the preferred option, but for some reason, the include pragmas seem to get ignored. Perhaps it is because the requirement that the pragmas be on the top of the file conflict with the #ifdef statements. In any case, this patch gets rid of the warning on MacOS X: warning: implicit declaration of function 'tgetnum'. (Eric Kow) * Pass CFLAGS to the assembler. E.g. -mcpu is essential on sparc. (Lennart Kolmodin) * Optimize 'darcs optimize --reorder'. (David Roundy) * Add a table of environmental variables to the manual. (issue69, Eric Kow) * Use System.Directory.copyFile for file copying. (Kevin Quick) * Implement darcs show contents command. It shows the contents of a file at a given version. (issue141, Eric Kow) * Make Changes --context --repodir work. (Issue467, Erik Kow) * Rename 'query' to 'show', but keep 'query' as an alias. (There is also an extra alias 'list' that means the same as show.) The subcommand 'query manifest' is renamed to 'show files', and does not list directories by default, unless the alias 'manifest' is used. (Eric Kow) * Support record -m --prompt-long-comment. (issue389, Eric Kow) * Hide the command 'unpull' in favor of 'obliterate'. (Eric Kow) * Make option --no-deps work again. It now also works for obliterate, unrecord, push and send. (issue353, Tommy Pettersson) * Make Record --ask-deps abort if user types 'q' instead of recording without explicit dependencies. User is now required to type 'd' (done). If the resulting patch is completely empty (no changes and no dependencies) the record is automatically canceled. (issue308, issue329, Kevin Quick) * Use pure record-access for PatchInfo in Patch.Info. (David Roundy) * Improve error message when unable to access a repository. (David Roundy) * Switch to using new Haskell standard library function cloneFile for copying files. (Kevin Quick) * Remove more GUI code. (Eric Kow) * Fix some --dry-run messages: "Would push" instead of "Pushing". (issue386, Eric Kow) * Ensure that logfile for record has trailing newline. (issue313, Eric Kow) * Add a stub command 'commit' that explains how to commit changes with darcs. (Eric Kow) * Makes non-repository paths in DarcsFlags absolute. (issue427, Zachary P. Landau) * Fix problem with missing newline in inventory, to simplify for third party scripts. (Issue412, Eric Kow) * Add all pulled repositories to _darcs/prefs/repos. (Issue368, Eric Kow) * Implement Apply --dry-run. (Issue37, Eric Kow) * Never change defaultrepo if --dry-run is used (issue186, Eric Kow) * Filter out any empty filenames from the command line arguments. (Issue396, Eric Kow) * Use prettyException in clarify_errors so we don't blame user for darcs' own errors. (Issue73, Eric Kow) * Rename command 'resolve' to 'mark-conflicts'. 'Resolve' remains as a hidden alias. (issue113, Eric Kow) * Make 'query manifest' list directories by default. (issue456, Eric Kow) * Allow --list-options even if command can not be run. (issue297, Eric Kow) * Make 'unadd' an alias for 'remove'. Make 'move' an alias for 'mv'. Add a stub for 'rm' that explains how to remove a file from a darcs repository. (issue127, Eric Kow) * Fix --help. (Issue282, Eric Kow) * New --nolinks option to request actual copies instead of hard-links for files. (Kevin Quick) * Harmonize capitalization in flags help. (Eric Kow) * Define datarootdir early enough in autoconf.mk.in. (Issue493, Eric Kow) * Fix a bug where Get --partial would use a checkpoint without detecting it was invalid. Checkpoints can for example become invalid after an Optimize --reorder. (issue490, David Roundy) * User Agent size limit for curl gets is removed. (Issue420, Kevin Quick) * Don't garb string parameters passed to libcurl, as required by the api specification. (Daniel Gorin) * Fix handling of --repo with relative paths. (Eric Kow) * Check for gzopen in zlib. curl depends on zlib and is detected prior to zlib by the configure file, but without the -lz flag on some versions. (Andres Loeh) * Switch to haskell's System.Process under Unix for execution of external commands; requires GHC 6.4. (Eric Kow) * Remove (some more) conflictor code. (Eric Kow) * Remove (unused) conflictor code. (David Roundy) * Support makefile docdir/datarootdir variables. (Dave Love) * Added prehooks that works the same as posthooks, but they run before the command is executed. This can for example be used to convert line endings or check character encodings before every Record. The darcs command aborts if the prehook exits with an error status. (Jason Dagit) * Use system instead of rawSystem for calling interactive cmds in Windows, which lets us support switches, for example, in DARCS_EDITOR. (Eric Kow) * add support for partial and lazy downloading of hashed repositories. (David Roundy) * Fix refactoring bug in Checkpoints where we sometimes looked for things in the wrong place. (David Roundy) * Fail on error in get_patches_beyond_tag. This will expose any bugs where we use this function wrongly. (As was the case in darcs check --partial with hashed inventories.) (David Roundy) * Restructure the source tree hierarchy from a mostly flat layout to one with directories and subdirectories that reflects the modularity of the source. (Eric Kow) * In tests, don't assume grep has -q and -x flags. (Dave Love) * Add --output-auto-name option to Send (Zachary P. Landau) * Added regression testing for the "pull --complement" operation. Updated documentation to explain why "darcs pull --complement R1 R1" is the same as "darcs pull R1" instead of the empty set. (Kevin Quick) * Change all "current" to "pristine" in manual and help texts. (Tommy Pettersson) * Added the ability to specify the --complement argument on the pull command as an alternative to --intersect and --union. When --complement is specified, candidate patches for a pull are all of the pullable patches that exist in the first repository specified but which don't exist in any of the remaining repositories (the set-theory complement of the first repository to the union of the remaining repositories). (Kevin Quick) * Fix bug where darcs would try to write temporary files in the root directory (/) if it couldn't find a repository root to write them in. Now it uses the current directory in that case. (issue385, Zachary P. Landau) * Make write_repo_format use the same syntax as read_repo_format when dealing with different repository formats. (Benedikt Schmidt) * Remove some unused functions from Population. (Eric Kow) * Use IO.bracket instead of Control.Exception.bracket in Exec, to restore the old way darcs works on *nix. (Eric Kow) * Import bracketOnError from Workaround instead of Control.Exception to support GHC 6.4. (Eric Kow) * Switch to haskell's System.Process under Windows for execution of external commands; requires GHC 6.4. (Simon Marlow) * Fix bug where darcs ignored command arguments in the VISUAL environment variable. (issue370, Benedikt Schmidt) * Make annotate work on files with spaces in the name. (Edwin Thomson) * Prettify exceptions in identifyRepository. (Juliusz Chroboczek) * QP-encode patch bundles transfered with the Put command. (Juliusz Chroboczek) * Fix bug in darcs get --tag that left cruft in pending. (David Roundy) * Fix bug when trying to 'darcs mv foo foo'. (issue360, David Roundy) * Separate comment from OPTIONS pragma for GHC 6.4 compatibility. (Eric Kow) * Make hashed inventories support optimize and reordering. (David Roundy) * Change all Maybe Patch to the new type Hopefully Patch, which is similar to Either String, for storing patches that may or may not exist. This should make it much easier to improve error reporting. (David Roundy) * Fix pending bug that broke several_commands.sh. (David Roundy) * Fix hashed inventory bug in Add. (David Roundy) * Make Get and Put reuse code for Initialize. This makes Put accept any flags that Init accepts. (David Roundy) * Fix new get to not mess up pending. (David Roundy) * External resolution can resolve conflicting adds. (Edwin Thomson) * Only copy the files that are needed for the resolution, when invoking an external resolution tool. This saves much time and resources on repositories with many files in them. (Edwin Thomson) * Change message in 'darcs check' from "applying" to "checking". (issue147, Tommy Pettersson) * Add code fore hashed inventories. (David Roundy) * New option for Diff: --store-in-memory. darcs diff usually builds the version to diff in a temporary file tree, but with --store-in-memory it will represent the files in memory, which is much faster (unless the tmp directory already is a ram disk). (Edwin Thomson) * Fix bug where duplicated file names on the command line would fool darcs. (issue273, Tommy Pettersson) * When recording with option --pipe, assume users local timezone if none is given, instead of UTC. Except if the date is given in raw patch format 'yyyymmddhhmmss' it is still parsed as UTC. (issue220, Eric Kow) * Account for timezone information, e.g. in dates when recording with option --pipe. (issue173, Eric Kow) * Fix bug in refactoring of get. (David Roundy) * Refactor repository handling to allow truly atomic updates. (David Roundy) -- David Roundy Sun, 16 Dec 2007 20:16:47 GMT darcs (1.0.9) * Make shell harness failures fatal in Makefile. (Eric Kow) * Bugfix, fix bug where we add a file but not its boring parent directory. (David Roundy) * Allow escaped quotes in 'quoted' for match text. (Dave Love) * Don't exit with failure when tests_to_run is used and there are no perl tests. (David Roundy) * Apply patches "tolerantly" to the working directory; don't quit, but print a warning for every problem and continue. This is a workaround for a bug in darcs where it sometimes fails to update the working directory. When darcs updates the working directory it has already successfully updated the inventory and the pristine cache, so the repository itself is not corrupted. However, an incomplete update to the working directory results in unintended differences between the working and pristine tree, looking like spurious unrecorded changes. These can be easily removed with 'darcs revert', but spurious changes have to be manually sorted out from real unrecorded changes. By darcs no longer quiting at the first problem, more of the working tree gets updated, giving less spurious changes and less manual work to fix the mess should the bug bite you. (issue434, Eric Kow, David Roundy) * Add a README file, created from HACKING. (issue287, Eric Kow) * New command, query tags (similar to 'darcs changes -t .) (Florian Weimer) * Include the query commands in the manual. (Florian Weimer) * The ssh control master is now off by default (it seems to hang on some large repositories). The option --disable-ssh-cm is replaced by the two options --ssh-cm and --no-ssh-cm (default). (Eric Kow) * Do not append a colon to host name when calling sftp. This does not solve all of issue362, just a minor annoyance along its way. (issue362, Eric Kow) * Get 'open' and 'psignal' declared on Solaris. (Dave Love) * Zsh completion supports new _darcs/pristine repository format. (Georg Neis) * Add documentation for DARCS_PAGER. (Benedikt Schmidt) * Turning off and on the ssh control master works for the Changes command. (issue383, Georg Neis) * Optimize unrecorded file moves with unrecorded file adds and removals. That is, if you add, rename and remove files multiple times without recording, whatsnew (and record) will only see the final result, not the whole sequence of moves. (Marco Tulio Gontijo e Silva) * Fix link error with errno for gcc 4.12 / glibc 2.4. (Benedikt Schmidt) * Remove the confusing text "user error" from some of GHC's error descriptions. (Juliusz Chroboczek) * Check for and fail build configuration if module quickcheck isn't available. (issue369, David Roundy) * Make darcs push QP-encode the bundle before transferring. This should hopefully fix issues with scp/sftp corrupting bundles in transit. (Juliusz Chroboczek) * Make it very clear in the documentation that the options --from and --author does NOT have anything to do with the sender or email author when sending patches as email with the darcs Send command. (Kirsten Chevalier) * Allow commented tests in tests_to_run. (David Roundy) * Make it an error to Put into a preexisting directory. Often one could be tempted to try to put into a directory, expecting to have the repository created as a subdirectory there, and it is confusing to have instead the repository contents mingled with whatever was already in that directory. (David Roundy) * Explicitly flush output on Windows after waiting for a lock, because Windows' stdout isn't always in line-buffered mode. (Simon Marlow) * Improve unhelpful "fromJust" error message in Push command. (Kirsten Chevalier) * Support option --all for Obliterate, Unpull and Unrecord. (issue111, David Roundy) * Ignore failure to set buffering mode for terminal in some places (supposedly fixes issue41, issue94, issue146 and issue318). (Tommy Pettersson) * Buildfix, don't import Control.Exception functions when compiling on Windows. (Edwin Thomson) * Add make rules for tag files. (Dave Love) * Add a semi-automated test for SSH-related things. (Eric Kow) * Allow Dist --dist-name to put the tar file in any directory by giving a full path as the dist name. (issue323, Wim Lewis) * Add rigorous error checking when darcs executes external commands. All low-level C return values are checked and turned into exceptions if they are error codes. In darcs main ExecExceptions are caught and turned into error messages to help the user. (Magnus Jonsson) * Redirect error messages from some external commands to stderr. (Tommy Pettersson) * Make configure fail if a required module is missing. (David Roundy) * The options for turning off and on the ssh control master works from the defaults file. (issue351, Tommy Pettersson) * Amend-record now keeps explicit dependencies (made with --ask-deps) from the amended patch. (issue328, Edwin Thomson) * Make libcurl use any http authentication. This let darcs use repositories protected with digest authentication. (Tobias Gruetzmacher) * Turning off and on the ssh control master works for the Send command. (Eric Kow) * Redirect stderr to Null when exiting SSH control master. This suppresses the output "Exit request sent" not suppressed by the quiet flag. (Eric Kow) * Fix curses stuff, especially on Solaris 10. (Dave Love) * Annotate various boring patterns. (Dave Love) -- Tommy Pettersson Sun, 03 Jun 2007 21:37:06 GMT darcs (1.0.9rc2) * Pass e-mail address only for %t in --sendmail-command. Msmtp seems to require this. Note that the full address is encoded in the message body. (Eric Kow) * Show error messages on stderr when starting and stopping the ssh control master. (Tommy Pettersson) * Rewrite check for spoofed patches with malicious paths. The check can now be turned off with the option --dont-restrict-paths (issue177). The new check only works for Apply and Pull, and it only looks at the remote patches. A more complete check is desirable. (Tommy Pettersson) * Add LGPL file referenced in fpstring.c (Dave Love). * Update FSF address in copyright headers(Dave Love). * New default boring file patterns: ,v .# .elc tags SCCS config.log .rej .bzr core .obj .a .exe .so .lo .la .darcs-temp-mail .depend and some more (Dave Love). * Move darcs.ps to the manual directory (Tommy Pettersson). * Pass -q flag to scp only, not ssh and scp. Putty's SSH (plink) does not recognize the -q flag. (issue334, Eric Kow) * Bugfix. Make darcs.cgi look for both pristine and current (Dan). * Don't lock the repo during `query manifest' (issue315, Dave Love). * Buildfix. Include curses.h with term.h (issue326, Dave Love). * Bugfix. Unrecord, Unpull and Obliterate could mess up a repository slightly if they removed a tag with a corresponding checkpoint. Only the commands Check and Repair were affected by the damage, and Get would also copy the damage to the new repository. (issue281, Tommy Pettersson) * Add a HACKING file with helpful references to pages on the darcs wiki (Jason Dagit). * New boring file patterns: hi-boot o-boot (Bulat Ziganshin, Eric Kow). * Require 'permission denied' test for MacOS X again. Perhaps something in MacOS X was fixed? (Eric Kow). * Look for Text.Regex in package regex-compat. Needed for GHC 6.6. (Josef Svenningsson) -- Tommy Pettersson Sun, 16 Nov 2006 14:03:51 GMT darcs (1.0.9rc1) * Improved handling of input, output and error output of external commands. Null-redirection on windows now works. Only stderr of ssh is null-redirected since putty needs stdin and stdout. (issue219, Eric Kow, Tommy Pettersson, Esa Ilari Vuokko) * Optimize away reading of non-managed files in summary mode of Whatsnew --look-for-adds (issue79, Jason Dagit). * Remove direct dependency to mapi32.dll; Improve MAPI compatibility. (Esa Ilari Vuokko) * Ignore .git if _darcs is found (Juliusz Chroboczek). * Add a haskell code policy test to catch uses of unwanted functions, bad formating and such. (Tommy Pettersson) * If the logfile supplied with option --logfile does not exist, fail instead of inserting no long comment. (issue142, Zachary P. Landau) * Make the pull 'permission test' work when run as root (Jon Olsson). * Handle unsimplified patches when further simplifying the summarized output. For unknown reason (a possibly previous version of) darcs allows a single patch to Add and Remove the same file in a single patch. The Changes command used to combine them, showing just a Remove. (issue185, Lele Gaifax) * Add workaround for HasBounds that was removed in GHC 6.6 (Esa Ilari Vuokko). * Really make --disable-ssh-cm work (issue239, Eric Kow). * Fix false errors in pull.pl test (David Roundy). * Clean up docs on DarcsRepo format (David Roundy). * Use stdin for passing the batch file to sftp, to allow password-based authentication (issue237, Eric Kow, Ori Avtalion). * Make darcs fail if the replace token pattern contains spaces. It would otherwise create a non-parsable patch in pending. (issue231, Tommy Pettersson) * Set a default author in the test suite harness so not every test has to do so. (Tommy Pettersson). * Run external ssh and scp commands quietly (with the quiet flag), but not sftp which doesn't recognize it (issue240). This reduces the amount of bogus error messages from putty. (Eric Kow) * Implement help --match, which lists all available forms for matching patches and tags with the various match options (Eric Kow). * Added .elc and .pyc suffixes to default binary file patterns (Juliusz Chroboczek ). * Added a link to the 'projects' part of the cgi repository interface, so that you go back to the project list (Peter Stuifzand). * Add a test suite for calling external programs (Eric Kow). * Don't warn about non-empty dirs when in quiet mode (Eric Kow). * New option --umask. This is best used in a repository's defaults file to ensure newly created files in the repository are (not) readable by other users. It can also be used when invoking darcs from a mail reader that otherwise sets a too restrictive umask. (Issue50, Juliusz Chroboczek) * Only check for ssh control master when it might be used. This suppresses the annoying "invalid command" error message. (Issue171, Eric Kow) * Fail with a sensible message when there is no default repository to pull from. (Lele Gaifax) -- Tommy Pettersson Sun, 08 Oct 2006 17:52:07 GMT darcs (1.0.7) * Fixed bug leading to a spurious "darcs failed: resource vanished" error message when darcs output is piped to a program such as head that then exits. (Issue160, David Roundy) * New option --diff-command overrides the default value of "diff" when darcs calls an external program to show differences between versions (Eric Kow). * Use the ControlMaster feature in OpenSSH version 3.9 and above to multiplex ssh sessions over a single connection, instead of opening a new connection for every patch (Issue32, Eric Kow). * Add a standalone graphical interface (experimental). The gui code prior to this patch allows graphical darcs forms to be run from the command line. This builds off that functionality by adding a graphical front-end, allowing users to access these forms with a click of a button. In other words, this allows users to run darcs without the command line. (Eric Kow) * Make unpull, unrecord, obliterate accept --gui (Eric Kow). * Freshen GUI code so that it compiles (Eric Kow). * Provide more information when a remote repository can't be correctly identified. (Juliusz Chroboczek) * The Send command can save, reuse and delete the accompanying description in a logfile. (Zachary P. Landau) * Display list of subcommands when getting help on a supercommand. (Eric Kow) * A proper fix for the problem with rmdir when there are non-managed files left in the working copy of the directory so it can't really be removed. This solves the two related problems with a missguiding error message in one case, and an unreported repository corruption in the other. Now there is no false warning and no repository coruption. (issue154, Eric Kow) * Escaping of trailing spaces and coloring now works with in the pager called with 'p' from interactive dialogues. (issue108, Tommy Pettersson) * Added default recognized binary file extensions: bmp, mng, pbm, pgm, pnm, ppm, tif, tiff. (Daniel Freedman) * Added a RSS link to common.xslt. (Peter Stuifzand) * Make short option -i a synonym for --interactive (Zachary P. Landau). * Improved argument substitution for --external-merger. All apperences of %N are replaced, not only those occurring as single words. (Daan Leijen) * Transition from _darcs/current to _darcs/pristine completed. New repositories are created with a "pristine" directory. Previous versions of darcs have been looking for this directory since version 1.0.2, but older versions than that can't read the new repository format. (Juliusz Chroboczek) * If you specify a repository directory, any absolute paths prefixed by this directory are converted to be ones relative to the repodir. (issue39, Eric Kow) * The --repodir flag works with many more commands: changes, dist, get, optimize, repair, replace, setpref, tag, trackdown. (RT#196, RT#567, Eric Kow) * The --repodir flag works with initialize command, and tries to create it if it does not exists. (RT#104, Eric Kow) * Add autom4te.cache to default boring patterns. (Kirill Smelkov) * Don't create temporary copies of the repository for the external merger program, unless there is for sure some conflict to resolve. (Edwin Thomson) * Modify Changes --interactive dialogue to behave like other interactive commands: accept 'y' and 'n' as answers and exit automatically after last question. (Zachary P. Landau) * Unnamed patches are now called "changes" in the interactive patch selection dialogues. (Tommy Pettersson) * Treat Enter as an invalid response in single character prompt mode, and give feedback instead of being mysteriously silent and unresponsive. (RT#261, Eric Kow) * Make short option -f a synonym for --force (Zooko). * Posthooks no longer cause an output message about success or failure, unless the --verbose option is used. (Jason Dagit) * Fix crash when using changes --interactive with --patch or --match (Zachary P. Landau). -- Tommy Pettersson Sun, 13 May 2006 17:14:38 GMT darcs (1.0.6) -- Tommy Pettersson Sun, 28 Feb 2006 11:18:41 GMT darcs (1.0.6rc1) * Check paths when applying patches to files and directories to stop maliciously handcrafted patches from modifying files outside of the repository or inside darcs private directories (issue48, Tommy Pettersson). * Revert optimization that sometimes applied patches incorrectly and corrupted the repository. This make darcs somewhat slower when applying patches. A full pull of the darcs repository itself takes 50% longer. (issue128, Tommy Pettersson). * Fix bug in Get --tag that produced a corrupt repository (issue67, Edwin Thomson). * Add newline between long comment and changed files list in dry-run summary to remove ambiguity (Edwin Thomson). * Extended date matching functionality: ISO 8601 dates and intervals, a larger subset of English like "yesterday at noon" (issue31/RT#34, Eric Kow). * Allow rename to different case (RT #466, Eric Kow). * Save long comment in a file if record fails the test run (Zachary P. Landau). * Fix win32 build breaks (Will Glozer). * Make --exact-version work when darcs is built from distributed tar ball (Marnix Klooster). * Coalesce pending changes created with setpref (issue70/RT#349, Eric Kow). * Support --interactive option in changes command (issue59, Zachary P. Landau). * New help command (RT#307, Eric Kow). * Add --without-docs option to configure (Richard Smith). * Obey normal autoconf conventions. Allows you to 'make install prefix=...' and doesn't change default for sysconfdir. (Dave Love) * Fix bug with non-existing directories. (David Roundy) * Remote apply does not use cd to change current directory to target directory any more. It uses --repodir when invoking remote darcs. This may break some darcs wrappers. (Victor Hugo Borja Rodriguez) * Support signed push (Esa Ilari Vuokko). * Added support for pulling from multiple repositories with one pull. The choice of --union/--intersection determines whether all new patches are pulled, or just those which are in all source repositories. This feature implements a suggestion by Junio Hamano of git. (David Roundy) * Patch bundle attachments get a file name, based on the first patch. (Zachary P. Landau) * The send command now takes a --subject flag. (Joeri van Ruth) * Fix --set-scripts-executable to work also when getting a local repository. (issue38, Eric Kow) * Removed the helper program darcs-createrepo. It was used for guided settup of a darcs repository and a corresponding user account to accept patches from signed emails. (issue14, Jason Dagit) * Print out the patch name when a test fails. (Zachary P. Landau). * Bugfix for --sendmail-command in Windows (Esa Ilari Vuokko). * Make apply --verify work with GnuPG in Windows (Esa Ilari Vuokko) * Bugfix for handling of absolute paths in Windows (issue47, Will Glozer) -- Tommy Pettersson Sun, 19 Feb 2006 23:19:19 GMT darcs (1.0.5) * Fixes for Windows (Will Glozer). * Adapt makefile to work with current ghc 6.4 (Will Glozer). * --help and --list-commands ignore other options (issue34, Eric Kow). * Fix apply with --verify for patch bundles signed by GnuPG in Windows (Esa Ilari Vuokko). * Make patch selection options together with --context work again (Daniel Bünzli). * Make option --commands outside of a repository work again (issue9, David Roundy). * Bugfix for pushing with ssh under Windows (issue15, Will Glozer). * Fix superfluous input bug in test suite (Florian Weimer). * Many English and markup fixes (Dave Love). -- Tommy Pettersson Sun, 07 Dec 2005 11:27:30 GMT darcs (1.0.4) * Fixed a bug in the external conflict resolution code. (bug #577, David Roundy) * Fixed a bug which made apply sometimes (but rarely) fail to check the the hash on patch bundles corrupted in just the wrong way. (David Roundy) * Added a simple check to darcs replace that avoids tokenizing lines that don't contain the token we're replacing. I feel a bit bad about introducing an optimization this late in the release cycle, but it makes a huge difference, and really should be safe. (David Roundy---famous last words) * Fixed bug where darcs didn't honor the SSH_PORT environment variable when calling sftp. (bug #576, fix suggested by Nicolas Frisby) * Avoid putting a wrongly-named directory in the tarball generated by darcs dist, if the name we wanted already exists in $TMPDIR. (Simon McVittie) * Fixed bug which caused "pull_firsts_middles called badly" errors when running record with --ask-deps flag. (bug #476, David Roundy) * Fixed bug where 'darcs changes --context' created a context that contained escapes that prevented its use with send. (bug #544, David Roundy) * Make interactive push/pull/send/apply respect the --summary option by printing each patch as if you had hit 'x'. (David Roundy, bug #512) * Fix bug when calling whatsnew --summary when a file without a trailing newline has been deleted. (David Roundy) * Fix --set-scripts-executable to work again. This feature had been broken since version 1.0.3. (David Roundy) * Simple (safe) fix for a bug which caused darcs to run out of file descriptors when pulling over 1000 patches. (David Roundy) * Fix bug in perl parts of test suite which led to spurious warning messages. (David Roundy) * Fix bug in configure when compiling darcs from tarball on a system that has no darcs present. (David Roundy) * Fix bug that shows up when recording in a repository lacking a pristine tree. (David Roundy) -- David Roundy Sun, 13 Nov 2005 13:44:31 GMT darcs (1.0.4pre4) * Fix error in install target of makefile, which was introduced in 1.0.4pre3. (Andres Loeh) * Fix problem where make install modified the permissions on system directories. (David Roundy, bug #494) * Fix bug in display when whatsnew is given "-l" twice. (David Roundy, bug #501) * Added support for --posthook to all commands. (Jason Dagit) * Made repair able to work on partial repositories. (fixes bug #189) * Changed the delimiter in the long-comment file from ***DARCS*** to ***END OF DESCRIPTION*** and clarified its meaning a bit. (Jason Dagit and David Roundy) * Added code to allow darcs to apply some patch bundles that have had carriage returns added to their line endings. (David Roundy, bug #291) * Make darcs accept command line flags in any order, rather than requiring that they precede file, directory or repository arguments. Fixes bug #477 (David Roundy) * Modified darcs get to display patch numbers rather than a bunch of dots while applying patches during a darcs get. Also added similar feedback to the check and repair commands. (Mat Lavin, bug #212) * Made revert --all not ask for confirmation, so it can be used in scripting, as one would use pull --all or record --all. (Jani Monoses) * Added file ChangeLog.README explaining how to add entries to the changelog. (Mark Stosberg and David Roundy) * Fixed incompatibility with somewhat older versions of libcurl. (Kannan Goundan) * Fixed bug that showed up when after editing a long comment, the long comment file is empty. (David Roundy, bug #224) -- David Roundy Sun, 01 Sep 2005 11:04:18 GMT darcs (1.0.4pre2) * (EXPERIMENTAL) Added support for reading and writing to git repositories. There remain efficiency issues with the handling of git merges and darcs is not yet able to either create a new git repository, or to pull from a remote git repository. See building darcs chapter in manual for instructions on building darcs with git support. (Juliusz Chroboczek, configuration contributed by Wim Lewis) * Add new "query manifest" command to list files and/or directories in repository. Add some related infrastucture to support "subcommands". (Florian Weimer) * Make configure properly detect that we're on windows when building under mingw. (David Roundy) * Fixed bug #208: error when specifying pulling from a relative default repository if we are ourselves within a subdirectory of our repository. (David Roundy) * Change internal mechanism for writing the "pending" file to be (hopefully) more robust. (David Roundy, original idea by Ian Lynagh) * Fixed a bug that caused get --partial to fail sometimes. (David Roundy) * Made push/pull --verbose --dry-run now display contents of patches, analogous to the behavior of changes --verbose. (Jim Radford) * Various build system cleanups. (Peter Simons) -- David Roundy Sun, 31 Jul 2005 12:10:29 GMT darcs (1.0.4pre1) * Performance improvement: Several commands now read patches lazily, which reduces memory usage. A test of 'darcs check' on the Linux kernel repository showed the memory usage was nearly cut in half, from about 700 Megs to 400. Coded by David Roundy. * New feature: darcs put, the easiest way to create a remote repo, symmetric with 'darcs get'. Coded by Josef Svenningsson. * Performance improvement: RT#222: darcs performs better on files with massive changes. Coded by Benedikt Schmidt. * New Feature: darcs optimize now has "--modernize-patches" and "--reorder-patches" flags. See the manual for details. * Performance improvement: Using 'darcs diff' is now exponentially faster when comparing specific files in the working directory to the most recent copy in the repo. Coded by kannan@cakoose.com. -- David Roundy Sun, 18 Jul 2005 11:22:34 GMT darcs (1.0.3) * Fixed bug #396: error when specifying a removed file on the command line of darcs record. -- Tomasz Zielonka Sun, 24 May 2005 21:51:27 GMT darcs (1.0.3rc2) * Internals: darcs' ChangeLog is automatically generated from repo history and a database of ChangeLog entries (Tomasz Zielonka) * Fixed: RT#370: --tags work in unpull and unrecord (Tommy Pettersson) * New feature: added support for displaying patches with pager when selecting patches (Benedikt Schmidt) * New feature: new match type "exact" (John Goerzen) * Feature: unrevert accepts --all and --interactive options (Jani Monoses) * Fixed: darcs works with nvi (Benedikt Schmidt) -- Tomasz Zielonka Sun, 15 May 2005 08:56:17 GMT darcs (1.0.3rc1) * New Feature: darcs.cgi now uses appropriate caching headers. This will make repeated calls to the same pages by cache-aware browsers much faste in some cases. It also means that darcs.cgi can be usefully combined with a cache-aware proxy for even better performance. (Will Glozer) * New feature: more control over color and escaping in printed patches, alternative color scheme, escaping of trailing spaces (Tommy Pettersson) * Fixed: fixed bug manifesting with failed createDirectory (David Roundy) * Internals: RT#255, several welcome refactors were made to the test suite, including comprehensible shell test script output, improved portability, and easier maintenance. (Michael Schwern). * New Feature: RT#245: Using --look-for-adds with 'whatsnew' implies --summary. This should save some typing for the common case. (Karel Gardas, Mark Stosberg) * New Feature: RT#231: darcs gives better feedback now if you try to record nonexistent files or directories. (Karel Gardas, Mark Stosberg) * New feature: send accepts --sendmail-command that allows to customize the command used for sending patch bundles (Benedikt Schmidt) * Fixed: RT#266: Adding a non-existent dir and file gives the expected message now. (Tomasz Zielonka). * Fixed: RT#10, a missed conflict resolution case. More accurately, we noticed at had been fixed some point. A regression test for it was added. (Tomasz Zielonka, Mark Stosberg) * New feature: darcs tag can now accept the tag name on the command line (RT#143). (Josef Svenningsson, Mark Stosberg, David Roundy) * New feature: unrecord and unpull have a more powerful interface similar to 'darcs pull'. This allows for multiple patch selection. Coded by Tommy Pettersson. * Bug fix: RT#305: Removed '--patch' from the 'changes', which conflicted with the new '--patches' option. * New feature: Automatically add parent directories for darcs add. (RT#20) Coded by Benedikt Schmidt. * Add helpful diagnostic message when there is a failure while pulling (RT#201) -- Tomasz Zielonka Sun, 26 Apr 2005 00:25:54 GMT darcs (1.0.2) * No changes from 1.0.2rc4. -- David Roundy Fri, 4 Feb 2005 07:33:09 -0500 darcs (1.0.2rc4) * More documentation improvements, plus one clearer error message. * Fixed (new since 1.0.1) bug which broke darcs repair. * Fixed problem with makefile which caused spurious relinkings. * Fixed bug in new optimize --relink command, which could cause repository corruption. -- David Roundy Wed, 2 Feb 2005 06:24:19 -0500 darcs (1.0.2rc3) * Documentation improvements related to Juliusz new code. * Fixed longstanding leaks in zlib/threads code. * Fixed some bugs in the new optimize --relink code. * Fixed bug in darcs diff when the repository name is empty. -- David Roundy Sat, 29 Jan 2005 07:28:39 -0500 darcs (1.0.2rc2) * Fixed bug on win32 when there are spaces in a repositories path and an external program (i.e. ssh) is called. (Will Glozer) -- David Roundy Thu, 27 Jan 2005 06:46:37 -0500 darcs (1.0.2rc1) * Added experimental support for repositories without a "pristine tree" This is the new name for the cache stored in _darcs/current/. (Juliusz Chroboczek) * Added an optimize --relink command to save disk space when using multiple repositories. (Juliusz Chroboczek) * Ignore conflict markers in the boring and binaries files. * Fixed bug in get --partial when patches are in an unusual order. (Andrew Johnson) * Fixed bug which caused a crash on a local get of a repository owned by another user. * Fixed bug in changes/annotate that shows up when a directory has been moved. * Allow ncurses in addition to curses in configure. * Added --set-scripts-executable option. (Karel Gardas) * Added configure option to fix path to sendmail even if it's not present. * Made bash completion more robust regarding shell special chars. * Added konquerer workaround to cgi annotate. (Will Glozer) * Addressed bug #114 - provide a better error when you accidently try to pull from yourself. (Mark Stosberg) * Made a few documentation improvements. * Made http user agent reflect the darcs and libcurl version. * Fixed commute bug in merger code. * Fixed bug in decoding mime messages. -- David Roundy Wed, 26 Jan 2005 08:51:24 -0500 darcs (1.0.1) * Made darcs changes --context work on an empty repo. * Fixed bug in relative directories as arguments to pull/push. * Fixed bug leading to extraneous changes in pending. * Fixed bug #137 - XML escaping for >. * Fixed gui code to compile with wxhaskell 0.8 (but it's still buggy). -- David Roundy Tue, 14 Dec 2004 08:16:10 -0500 darcs (1.0.1rc3) * Made it so adding and removing a file doesn't leave changes in pending. * Fixed bug in creating the file to be edited for the long comment. * Made "bug in get_extra" message explain possible cause of the problem, which is related to a bug in commutation that made it into version 1.0.0. * Fixed stubborn bug in annotate. * Fixed problem when unrecording binary file patches. -- David Roundy Sat, 11 Dec 2004 14:23:53 -0500 darcs (1.0.1rc2) * Various optimizations. * darcs now supports an arbitrary number of transport protocols through the use new environment variables. See DARCS_GET_FOO in the 'Configuring Darcs' chapter in the manual for more details. * darcs now supports an arbitrary number of concurrent connections when communicating with remote repos. See the documentation for DARCS_MGET_FOO in the 'Configuring Darcs' chapter in the manual for more details. -- David Roundy Wed, 8 Dec 2004 08:02:48 -0500 darcs (1.0.1rc1) * Fixed bug in commutation of adjacent hunks which have either no new or no old lines. * Numerous newline fixes for windows. * On windows, use MAPI to resolve to and from addresses. * Fixed problem where the --cc was ignored in apply if the patch succeeded. -- David Roundy Wed, 1 Dec 2004 06:24:08 -0500 darcs (1.0.1pre1) * Changed apply to by default refuse to apply patches that would lead to conflicts. * Removed the old darcs_cgi script, in favor of the darcs.cgi script. * Fixed changes to work better in partial repositories. * Set stdin and stdout to binary mode to fix end of line problems with push under windows. * Made send create proper MIME email. * Removed reportbug command, really wasn't necesary, and didn't work well. Report bugs by an email to bugs@darcs.net, which creates a ticket in our BTS. * Allow darcs to work with a password protected proxy. * Get multiple files with a single wget call when darcs is compiled without libcurl support. * Use sftp instead of scp to copy patches via ssh -- this reuses a single connection for better speed. * Made _darcs/current polymorphic (but not really documented). * Made optimize --uncompress work with --partial repos. * Various minor interface improvements. * Made changes work better when specifying a file, and working in a partial repository. * Fixed bug in causing "Fail: _darcs/patches/unrevert: removeFile: does not exist (No such file or directory)". Resolves bugs #57, #61. -- David Roundy Sun, 21 Nov 2004 08:29:24 -0500 darcs (1.0.0) * Fixed compile error when antimemoize is enabled. * Fixed bug that showed up when dealing with international characters in filenames. * Various documentation improvements. -- David Roundy Mon, 8 Nov 2004 06:12:08 -0500 darcs (1.0.0rc4) * Use autoconf to check for working install program. * Renamed rerecord to amend-record in a futile attempt to avoid confusion. * Made pull accept the --repodir option. * Fixed off-by-one error in annotate that kept users from seeing "deleted" version. * Check filesystem semantics at runtime to avoid using mmap on windows filesystems. * Fixed darcs.cgi to work properly when browsing history of renamed files. * Use anonymous file handle for temporary files in darcs.cgi -- fixes a temporary file leak and potentially improves security. * Added --summary option to commands that accept --dry-run. * Made pull prompt for confirmation when there is a conflict with unrecorded changes. * Made unrevert interactive. * Don't try to generate a new name on get if name was given explicitely. * Always mark conflicts, even if there's an obvious solution. * Quote conflict attribute values in xml output. * Fail if the user gives a newline in the patch name. * Fixed bug where new files didn't show up in darcs diff. * Really fix newlines in whatsnew -u. * Fixed bug in handling of tags in changes and annotate. * Fixed bug in default options containing "--". * Fixed various other build problems in 1.0.0rc3. * Fixed embarrassing failure-to-compile-on-windows bug. -- David Roundy Mon, 1 Nov 2004 05:19:01 -0500 darcs (1.0.0rc3) * Fixed bug leading to creation of empty "hunk" patches. * Fixed bug in rollback when there are pending changes. * Fixed push bug when default apply is --interactive. * Fixed a bug where "darcs pull --list-options" would try to complete to "home/.../darcs_repo" instead of "/home/.../darcs_repo". * Fixed flushing bug in darcs.cgi. * Fixed commutation bug with renames and file adds/removals. * Made --summary indicate conflicted changes. * Fixed generation of extra hunk in diff algorithm. * Added X-Mail-Originator header to emails sent by darcs. * Fixed a couple of bugs in the resolve command. * Added new cgi diff command to produce unified diff. * Notify when there are conflicts on push. * Added 'a' key to say yes to all remaining changes for interactive commands. * Automatically generate AUTHORS file from repo history. * Made pull --quiet actually quiet. * Fixed bugs in whatsnew -ls, and distinguished between manually added files and automatically added files. * Fixed bug in darcs --commands when called outside a repo. -- David Roundy Sun, 3 Oct 2004 07:45:05 -0400 darcs (1.0.0rc2) * Added support for comments in prefs files. * Added new --enable-antimemoize compile option which reduces memory usage at the expense of increased computational time. * Added a new command: "reportbug" * Fixed a bug that prevented applying of a patch bundle to an "unoptimized" repo. * Fixed bug where asking for changes to a nonexistent file in a subdirectory would show the patch that created or renamed that subdirectory. * Improved the robustness of unrevert. Now actions that will make unrevert impossible should warn the user. * Fixed bug when moving files or directories to the root directory of repo. * Various changes to make the --logfile way of specifying the patch name and comments in record more friendly: - Allows editing of the long comment even when --logfile is specified, if the --edit-long-comment option is also used. - When editing the long comment, the change summary is included below the actual text for reference, and the patch name is included in the first line (and thus may be modified). - The --logfile option is ignored if such a file doesn't exist. - A --delete-logfile option was added, which tells darcs to delete the file after doing the record. This is intended to allow you to stick a --logfile=foo option in your defaults without accidentally recording multiple patches with the same comments because you forgot to modify it. * Fixed bug leading to .hi files in tarball. * Made ctrl-C work under windows, but only "pure" windows consoles, not in cygwin shells or mingw's rxvt (room for improvement here). * Fixed bug that led to curl not being tried when darcs is not compiled with libcurl. * Added an environment variable DARCS_USE_ISPRINT for people who use non-ascii characters in their files to indicate if the haskell standard library "isPrint" function works properly on their system (which depends on locale). * Reduced the number of hunks produced by the internal diff algorithm, when there are multiple equivalent ways of interpreting a change. * Made the --from-{patch,tag,match} options inclusive, and added a --{patch,match} option to diff (which was made easier to define by the inclusiveness change, since --patch x is now equivalent to --from-patch x --to-patch x). * Added support for a second argument to get, which specifies the name of the new directory. -- David Roundy Sun, 12 Sep 2004 06:54:45 -0400 darcs (1.0.0rc1) * Remove some lazy file IO which may have been causing trouble pushing in windows and using windows shares. * Various interface improvements and improved error messages. * Fixed bug that could cause conflicts in pending when unrecording a patch that contained two non-commuting non-hunk patches. * Fixed bug in --ask-deps option of record. * Added --exact-version option which gives the precise darcs context from which darcs was compiled. * MIME fixes in patch forwarding. * Various improvements to the darcs.cgi script. * Added --reverse option to changes. * Fixed patch numbering when file or directory arguments are given to an interactive command. -- David Roundy Sun, 15 Aug 2004 07:43:30 -0400 darcs (0.9.23) * Added a rerecord command, which will add changes to an existing recorded patch * Added support for a MOTD. * Vastly improved the speed and memory use of darcs optimize --checkpoint as well as darcs record, in the case where a record consists primarily of adds. -- David Roundy Mon, 26 Jul 2004 08:11:20 -0400 darcs (0.9.22) * add preliminary --context option to changes and get. * display change number, e.g. "(1/3)" in interactive commands. * show moves in summary format. * add hash of patch bundles in darcs send. * properly support --verbose and --quiet in add. * don't display binary data to screen. * fix bug in selecting patches by pattern. * fix various locking-related bugs introduced in 0.9.21. * fix bug when specifying logfile in a subdirectory. * support backslashes for directory separators in windows. * fix file modification time bug. -- David Roundy Sat, 26 Jun 2004 07:42:05 -0400 darcs (0.9.21) * made mv work even if you've already mv'ed the file or directory. * remember configure settings when reconfiguring. * added --leave-test-directory to save the directory in which the test is run on record or check. * added HTTP redirect support (thanks Benedikt). * fixed problems when unrecording a patch with conflits. * fixed locking on nfs (thanks Juliusz). * added preliminary version of a new cgi script for browsing darcs repositories (thanks to Will Glozer for contributing this). * add and modify a number of short flag options. * fix bug in applying new order patch bundles that are GPG signed. * fix bug in diff when a tagged version was requested. -- David Roundy Sat, 12 Jun 2004 05:39:48 -0400 darcs (0.9.20) * fix bug in darcs-createrepo. * add support for DARCS_SCP and DARCS_SSH environment variables. * add XML support for --summary options of changes and annotate. * better command-line completion on commands accepting a list of files or directories. * fix bug causing empty hunk patches to lead to failures. * fix bug where --all overrode file choice in record. * fix bug when testing patches that create subdirectories within subdirectories. * preserve pending changes when pulling or applying. * give better error message in pull when patch isn't readable. * allow sendEmail with no "to", just "cc" recipients. This should fix the trouble with trying to --reply to a patch coming from a push rather than a send. -- David Roundy Wed, 5 May 2004 06:01:48 -0400 darcs (0.9.19) * fix bugs leading to failures in the wxhaskell interface. * fix bug that caused darcs diff to fail. * fixed bug in get that lead to _darcs/current/_darcs directories. * improved error reporting in several situations. * fixed bug when pulling or pushing into an empty repo. * added --summary option to changes to summarize the changes made in each patch. -- David Roundy Fri, 9 Apr 2004 07:19:34 -0400 darcs (0.9.18) * added support for sending email from windows using the MAPI interface. This code attaches the patch bundle in base64-encoded form, which darcs can't currently decode (expect that in the next release), but the patch bundle can be manually applied if a mail program does the decoding. * renamed "darcs push" to "darcs send" and added a new "darcs push" command roughly equivalent to the old "darcs push --and-apply". * removed support for setting up a test suite by simple creating a file named "darcs_test". You now should use setpref to define the test suite command. * fixed some problems when working in a --partial repository. * lots of code was cleaned up. We have enabled the -Wall compiler flag and are in the process of eliminating all the warnings. This should make the code more friendly to new developers, and also helps with the next bullet point: * improved handling of errors--informative failure messages are more likely than they were before. * by default only check changes made since last checkpoint--this greatly speeds up check. * add --quiet option. Some commands don't yet support this. If there's a command you want to quiet down, let us know. * several performance enhancements: improved SHA1 performance, faster check and get on repositories with a long history and improved performance with very large files. -- David Roundy Thu, 1 Apr 2004 05:43:18 -0500 darcs (0.9.17) * fixed bug in darcs apply that made the --no-test option fail. * fixed bug that caused darcs to set file permissions to be non-world-readable. * darcs record and whatsnew can now accept file or directory arguments and limit their actions to changes in those files or directories. * darcs changes now can accept file or directory arguments and limit itself to changes affecting those files or directories. -- David Roundy Sat, 21 Feb 2004 08:12:34 -0500 darcs (0.9.16) * Add --sign-as=KEYID option to push command. * make optimize split up inventory for faster pulls * Allow use of a different make command for tests, such as gmake * Can now put prefs that would normally go in _darcs/prefs (defaults, binaries and boring) in ~/.darcs/ to set the prefs for all your repositories at once. * add primitive xml output to annotate of directory. * When pushing a patch, add the list of changes in the description. * refuse to rollback a patch twice, since that would cause problems. * make darcs diff accept optional arguments indicating files and directories to diff. * preserve permissions on files in working directory. * put docs in ...share/doc/darcs not share/darcs/doc. * add support for multiple-choice options. This means that you can now set your default option in _darcs/prefs/defaults, and then override that default on the command line. * shortened --use-external-merge-tool option to --external-merge * more "boring" patterns. -- David Roundy Tue, 10 Feb 2004 07:08:14 -0500 darcs (0.9.15) * next step repository format transition--we use the new patch filenames. * fix handling of text files with no trailing newline--this will cause some trouble. Darcs will require that you convert your repository using convert-repo. This will leave you with a bunch of changes regarding trailing newlines which you will either want to record or revert. * the windows support is somewhat improved. * added simple "repair" command that can repair some kinds of inconsistencies in the repository. * added primitive "annotate" command to extract information about modifications to files and directories. * fixed handling of darcs mv to allow moving to directories in a more intuitive manner. * handling of binary files was dramatically improved in both memory and cpu usage. * added autoconf testing framework to clean up code dealing with different versions of ghc, features that don't exist on windows, bugs that only exist on windows, etc. * don't accept invalid flags. * add more patterns to boring and binary. * use autoconf test to handle posix signals and windows '\\' handling. * switch to using new patch filenames. * XML formatted output for 'changes' command * add support for unidiff-like whatsnew output. * fix bug in RTS memory calculation for large RAM size * add rollback command. * improve checkpointing support. * add diff-opts option to darcs diff. * add support for building docs using htlatex or hevea rather than latex2html. * use locking whereever it is needed. * add safe (atomic) writing of inventory files. -- David Roundy Fri, 12 Dec 2003 07:59:54 -0500 darcs (0.9.14) * darcs changes now shows times formatted according to current locale. * add support for automatically treating files containing ^Z or '\0' as binary. * add experimental checkpointing, allowing get to only download the recent change history. * allow darcs to be called within subdirectories of a repository. * make default be to compress patches. * add --summary option to whatsnew. * add trackdown command. * fix bug in darcs dist --verbose. * make darcs diff have closer behavior to cvs diff. In particular, darcs diff with no arguments now gives you the difference between the working directory and the latest recorded version. * support external graphical merge tools. * fix bug where binary patch is created even with no change. * support darcs -v for version. Also mention the darcs version in the usage mesage. * ignore empty lines in boring file and binary file. * preserve pending changes (e.g. file adds or darcs replaces) across revert and record. * create repositories with new patch filename format. The new repo format is now created alongside the old format, but the old format is read. There is a tool called convert-repo that will convert an old format repo to have both formats. * use iso format for dates in record. * New patch-selecting interface. This patch only uses the new routine for revert, since it's not particularly well tested. The text method now allows one to go back and edit previous patches. The idea is that eventually all commands that need the user to select a subset of patches will use this routine. * use hash for cgi cache file names. * add preliminary experimental GUI support using wxhaskell. * remember author name after first record in a repo. * add unrevert command. * always match full pathnames when checking boringness or binaryness. * rewrite replace tokenizer for more speed. * make darcs compile with ghc 6.2 and later. * fix some bugs in darcs diff. * make --and-apply work locally as well as via ssh. Also added a --and-apply-as that uses sudo to run the apply command as a different user. -- David Roundy Mon, 10 Nov 2003 07:08:20 -0500 darcs (0.9.13) * Various performance enhancements. * add --pipe option to tag and record, which causes them to prompt for all their input, including date. This can be useful when creating repository converters. * remove '-t' short command line option for '--to' and the '-o' short option for '--reponame'. * remove the darcs-patcher program. The functionality of the darcs-patcher program is taken over by the darcs apply command. Several fancy features have been added, as described in the Apply section of the manual. * support spaces and (maybe) unicode in filenames. * updates to win32 support * push via ssh * add --without-libcurl option to configure * include DarcsURL in push email. * add support for reading and writing gzipped patch files. * allow multiple --to addresses on push, and also support --cc for additional addresses. * when pulling or pushing from lastrepo, say where lastrepo is. * only save lastrepo in get if the source repo wasn't a relative directory path. -- David Roundy darcs (0.9.12) * add manual section on building darcs. * improve scaling of checking for and resolving conflicts, which was an O(n^2) function. * escape ESC char when printing patches. * don't reorder patches unless necesary--this avoids an O(n^2) operation which was making a darcs record very slow when a lot of files were added. * fix default regexps for boring file (Thanks Trevor!) * replace now ignores files that aren't in the repo. * make darcs add refuse to add files whose subdirectories don't exist. * implement support for binary files. * added support for running external programs to fetch files. * fix conflict resolution bug from 0.9.11. * make the patcher run the test prior to applying. * add repo locking. * Fix bug when pulling from a repo containing just one patch (thanks Peter). * install cgi script in cgi-bin directory. -- David Roundy darcs (0.9.11) * A rewrite of the configure code and makefile (thanks to Peter Simons). * Added several new repository configuration options including a setpref command which allows you to set preferences options that are pulled from repo to repo. * Yet another rewrite of the merging code. * User can now revert changes on a change-by-change basis. * Yet another major improvement in speed and memory consumption. * Add a darcs diff command to compare two versions. -- David Roundy Mon, 30 Jun 2003 06:42:10 -0400 darcs (0.9.10) * Added a way to configure the default values for options to darcs commands. See Appendix B of manual. * darcs push and pull now default to pulling and pushing from the most recently accessed repository (if you don't specify a repo). * Numerous bugfixes. -- David Roundy Wed, 21 May 2003 07:08:40 -0400 darcs (0.9.9) * Created a way to have a "centralized server". (See darcs-patcher chapter in manual). * Added new darcs-server package. * Switch to new repository format. Note that your repo will only be converted to the new format if you use certain commands such as unpull. You can recognize the new format by the presence of a _darcs/inventories/ directory. * Add the ability to sign patches sent with push using gnupg and to verify those signatures when applying. (This is the authentication basis for the above-mentioned server). * Fix bug in application of a file rename patch. -- David Roundy Thu, 8 May 2003 06:58:42 -0400 darcs (0.9.8) * Fix rare bug in check when files happen to be a multiple of 1024 bytes in length. * Fix bug in reading patch ids with long comments from local files. * Prepare for a change in the repository format. The format doesn't change for this version, but version 0.9.8 is able to read the new repository format. -- David Roundy Wed, 30 Apr 2003 08:54:18 -0400 darcs (0.9.7) * Fix a couple of rename conflict bugs. * Add new test suite framework, along with several tests. * Several major optimizations for speed and memory. * Added --ignore-times option to not assume that when a file modification time hasn't changed the file itself hasn't changed. -- David Roundy Sat, 26 Apr 2003 07:57:01 -0400 darcs (0.9.6) * Fixed a couple of bugs in the merging of conflicting renames. * Added an interface to include long comments when recording. * Improve the interface of pull, allowing for viewing the patches before pulling them. * Include zsh command completion examples with docs. * Massively improved responsiveness in command completion. * Use packed strings to save memory. * Fixed a bug that shows up in empty repos. * Fixed multiple bugs in the mv command. -- David Roundy Thu, 17 Apr 2003 09:34:34 -0400 darcs (0.9.5) * Improve merge of creation of files and directories with the same name. * Add darcs push and apply commands, which are the beginning of work towards supporting a "centralized server" concept a la CVS. However, they are also useful for a "Linus" style workflow, based on emailing patches. In theory they could also be used to provide a smart server that could server pulls using less bandwidth. * Add an unpull command analagous to unrecord, but which removes the patches from the working directory also. * Enable the mv command, since the mv patches have now been supported by a couple of versions. * Include zsh_completion code, thanks to Aaron Denney . -- David Roundy Wed, 9 Apr 2003 07:52:01 -0400 darcs (0.9.4) * Speed up whatsnew and record in the case where there are huge numbers of extra files in the working directory. * Small (~10%) speedup in get. -- David Roundy Fri, 4 Apr 2003 09:08:38 -0500 darcs (0.9.3) * Optimized whatsnew and record by seting modification time of "current" files equal to that of working files if they are identical, so I won't have to check again if the working one hasn't been changed. * Rewrite file renaming code (no creation). * Add support for replacing tokens in files. * Make cgi output work more accurately, and point out which files were modified by each patch. * Add a caching feature to the cgi script to speed things up a bit. * Turn on creation of dependencies when recording. * Add a 'tag' command. * Rewrote the 'pull' code to hopefully speed it up (and in any case to greatly simplify it). -- David Roundy Thu, 3 Apr 2003 07:08:05 -0500 darcs (0.9.2) * Add build dependency on tetex and latex2html * Have internal diff code properly respond to deleted files and directories. * Create file and directory rename patch types. (no creation--which means that I am waiting to create commands to create such patches until later, to avoid backward compatibility issues of repos.) * Add support for patch dependencies. (no creation) * Add support for token replacement patches. (no creation) -- David Roundy Thu, 27 Mar 2003 07:59:09 -0500 darcs (0.9.1) * Make darcs get --verbose actually be verbose (which is important because it takes so long that the user might be afraid it's hanging. * Speed up the merge in complicated cases, possibly dramatically. * Add a darcs remove command. -- David Roundy Mon, 10 Mar 2003 09:48:55 -0500 darcs 0.9.0 * Initial Release. -- David Roundy Wed, 3 Mar 2003 13:51:58 -0500 Local variables: mode: outline outline-regexp: "[dD]\\| +\\*+" paragraph-separate: "[ ]*$" end: darcs-2.14.5/COPYING0000644000000000000000000004310307346545000012124 0ustar0000000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. darcs-2.14.5/GNUmakefile0000755000000000000000000000116007346545000013143 0ustar0000000000000000# Good for tags. DARCS_FILES = $(wildcard src/[A-Z]*.hs src/*/[A-Z]*.hs src/*/*/[A-Z]*.hs) \ $(wildcard src/*/*/*/[A-Z]*.hs src/*/*/*/*/[A-Z]*.hs) \ $(wildcard darcs/[A-Z]*.hs) \ $(wildcard harness/[A-Z]*.hs harness/*/[A-Z]*.hs) \ $(wildcard harness/*/*/[A-Z]*.hs harness/*/*/*/[A-Z]*.hs) \ $(wildcard harness/*/*/*/*/[A-Z]*.hs) tags: $(DARCS_FILES) src/*.c hasktags -c $(filter %.lhs %.hs,$^) ctags -a $(filter %.c,$^) # TAGS is for etags, whereas tags is for ctags TAGS: $(DARCS_FILES) src/*.c hasktags -e $(filter %.lhs %.hs,$^) etags -a $(filter %.c,$^) clean: rm -f TAGS tags darcs-2.14.5/README.md0000755000000000000000000000445707346545000012364 0ustar0000000000000000Darcs ===== [Darcs](http://darcs.net) is a distributed version control system written in Haskell. Getting started =============== Compiling --------- The easiest way to build darcs is by using cabal-install version 3.2 or later. A plain ``` > cabal build ``` or ``` > cabal install ``` should work out of the box with any ghc version from 8.0 up to 8.10. Run the test suite ------------------ It is currently not possible to run the full test suite from the source distribution that you get from hackage. Instead you need to be in a clone of the darcs source code repository. This is because the tests depend on an old version of shelly that was patched to work with newer ghc versions and bundled with Darcs. It is not part of the source distribution to avoid 'cabal install' also trying to install our patched version of shelly. ``` > cabal build --enable-tests > cabal test --test-show-details=direct ``` Using ----- To clone a repository via HTTP and send patches by mail: ``` > darcs clone --lazy http://darcs.net > # edit files... > darcs add my_new_file > darcs record -m "my changes" > darcs send ``` To clone via SSH and push patches: ``` > darcs clone user@hub.darcs.net:user/repo > # edit files... > darcs add my_new_file > darcs record -m "my changes" > darcs push ``` To create a project and start working: ``` > darcs init my_project > cd my_project > # create and edit files... > darcs add my_new_file > darcs record -m "initial version" ``` Pull new patches from upstream: ``` > darcs pull ``` Concise and up-to-date documentation is available from darcs itself: ``` > darcs help # list all commands > darcs help command # help for specific command > darcs command --help # dito ``` Reporting bugs ============== Please send bug reports to . This will automatically add your report to the bug tracker. If you are unsure or just have a question or a comment, you can subscribe to darcs-users@darcs.net and post your question or comments there. See http://darcs.net/MailingLists for details. Hacking ======= Please consult for information about how to contribute to Darcs. Or send an email to darcs-devel@darcs.net or to darcs-users@darcs.net. The wiki can be downloaded with the command: ``` > darcs clone --lazy http://darcs.net/darcs-wiki ``` darcs-2.14.5/Setup.hs0000644000000000000000000002424107346545000012527 0ustar0000000000000000-- copyright (c) 2008 Duncan Coutts -- portions copyright (c) 2008 David Roundy -- portions copyright (c) 2007-2009 Judah Jacobson {-# OPTIONS_GHC -Wno-deprecations #-} {-# LANGUAGE CPP #-} import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks ) import Distribution.ModuleName( toFilePath ) import Distribution.PackageDescription ( PackageDescription(executables, testSuites), Executable(exeName) , emptyBuildInfo , TestSuite(testBuildInfo) , updatePackageDescription , cppOptions, ccOptions , library, libBuildInfo, otherModules ) import Distribution.Package ( packageVersion ) import Distribution.Version( Version ) import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..), absoluteInstallDirs ) import Distribution.Simple.InstallDirs (mandir, CopyDest (NoCopyDest)) import Distribution.Simple.Setup (buildVerbosity, copyDest, copyVerbosity, fromFlag, haddockVerbosity, installVerbosity, sDistVerbosity, replVerbosity ) #if MIN_VERSION_Cabal(3,0,0) import Distribution.Simple.BuildPaths ( autogenPackageModulesDir ) #else import Distribution.Simple.BuildPaths ( autogenModulesDir ) #endif import Distribution.System ( OS(Windows), buildOS ) import Distribution.Simple.Utils (copyFiles, createDirectoryIfMissingVerbose, rawSystemStdout, #if MIN_VERSION_Cabal(3,0,0) rewriteFileEx #else rewriteFile #endif ) import Distribution.Verbosity ( Verbosity, silent ) import Distribution.Text ( display ) import Control.Monad ( unless, void, when ) import System.Directory ( doesDirectoryExist, doesFileExist ) import System.IO ( openFile, IOMode(..) ) import System.Process (runProcess) import Data.List( isInfixOf, lines ) import System.FilePath ( () ) import Foreign.Marshal.Utils ( with ) import Foreign.Storable ( peek ) import Foreign.Ptr ( castPtr ) import Data.Monoid ( mappend ) import Data.Word ( Word8, Word32 ) import qualified Control.Exception as Exception #if MIN_VERSION_Cabal(3,0,0) autogenModulesDir = autogenPackageModulesDir rewriteFile = rewriteFileEx silent #endif catchAny :: IO a -> (Exception.SomeException -> IO a) -> IO a catchAny f h = Exception.catch f (\e -> h (e :: Exception.SomeException)) main :: IO () main = defaultMainWithHooks $ simpleUserHooks { buildHook = \ pkg lbi hooks flags -> let verb = fromFlag $ buildVerbosity flags in commonBuildHook buildHook pkg lbi hooks verb >>= ($ flags), haddockHook = \ pkg lbi hooks flags -> let verb = fromFlag $ haddockVerbosity flags in commonBuildHook haddockHook pkg lbi hooks verb >>= ($ flags) , replHook = \pkg lbi hooks flags args -> let verb = fromFlag $ replVerbosity flags in commonBuildHook replHook pkg lbi hooks verb >>= (\f -> f flags args) , postBuild = \ _ _ _ lbi -> buildManpage lbi, postCopy = \ _ flags pkg lbi -> installManpage pkg lbi (fromFlag $ copyVerbosity flags) (fromFlag $ copyDest flags), postInst = \ _ flags pkg lbi -> installManpage pkg lbi (fromFlag $ installVerbosity flags) NoCopyDest, #if !MIN_VERSION_Cabal(3,0,0) sDistHook = \ pkg lbi hooks flags -> do let pkgVer = packageVersion pkg verb = fromFlag $ sDistVerbosity flags x <- versionPatches verb pkgVer y <- context verb rewriteFile "release/distributed-version" $ show x rewriteFile "release/distributed-context" $ show y putStrLn "about to hand over" let pkg' = pkg { library = sanity (library pkg) } sanity (Just lib) = Just $ lib { libBuildInfo = sanity' $ libBuildInfo lib } sanity _ = error "eh" sanity' bi = bi { otherModules = [ m | m <- otherModules bi, toFilePath m /= "Version" ] } sDistHook simpleUserHooks pkg' lbi hooks flags , #endif postConf = \_ _ _ _ -> return () --- Usually this checked for external C --- dependencies, but we already have performed such --- check in the confHook } -- | For @./Setup build@ and @./Setup haddock@, do some unusual -- things, then invoke the base behaviour ("simple hook"). commonBuildHook :: (UserHooks -> PackageDescription -> LocalBuildInfo -> t -> a) -> PackageDescription -> LocalBuildInfo -> t -> Verbosity -> IO a commonBuildHook runHook pkg lbi hooks verbosity = do (version, state) <- determineVersion verbosity pkg -- Create our own context file. generateVersionModule verbosity lbi version state -- Add custom -DFOO[=BAR] flags to the cpp (for .hs) and cc (for .c) -- invocations, doing a dance to make the base hook aware of them. littleEndian <- testEndianness let args = ("-DPACKAGE_VERSION=" ++ show' version) : [arg | (arg, True) <- -- include fst iff snd. [-- We have MAPI iff building on/for Windows. ("-DHAVE_MAPI", buildOS == Windows), ("-DLITTLEENDIAN", littleEndian), ("-DBIGENDIAN", not littleEndian)]] bi = emptyBuildInfo { cppOptions = args, ccOptions = args } hbi = (Just bi, [(exeName exe, bi) | exe <- executables pkg]) pkg' = updatePackageDescription hbi pkg -- updatePackageDescription doesn't handle test suites so we -- need to do this manually updateTestSuiteBI bi' testSuite = testSuite { testBuildInfo = bi' `mappend` testBuildInfo testSuite } pkg'' = pkg' { testSuites = map (updateTestSuiteBI bi) (testSuites pkg') } lbi' = lbi { localPkgDescr = pkg'' } return $ runHook simpleUserHooks pkg'' lbi' hooks where show' :: String -> String -- Petr was worried that we might show' = show -- allow non-String arguments. testEndianness :: IO Bool testEndianness = with (1 :: Word32) $ \p -> do o <- peek $ castPtr p return $ o == (1 :: Word8) -- --------------------------------------------------------------------- -- man page -- --------------------------------------------------------------------- buildManpage :: LocalBuildInfo -> IO () buildManpage lbi = do let darcs = buildDir lbi "darcs/darcs" manpage = buildDir lbi "darcs/darcs.1" darcsExists <- doesFileExist darcs when darcsExists $ do manpageHandle <- openFile manpage WriteMode void $ runProcess darcs ["help","manpage"] Nothing Nothing Nothing (Just manpageHandle) Nothing installManpage :: PackageDescription -> LocalBuildInfo -> Verbosity -> CopyDest -> IO () installManpage pkg lbi verbosity copy = do let manpage = buildDir lbi "darcs/darcs.1" manpageExists <- doesFileExist manpage when manpageExists $ do copyFiles verbosity (mandir (absoluteInstallDirs pkg lbi copy) "man1") [(buildDir lbi "darcs", "darcs.1")] -- --------------------------------------------------------------------- -- version module -- --------------------------------------------------------------------- determineVersion :: Verbosity -> PackageDescription -> IO (String, String) determineVersion verbosity pkg = do let darcsVersion = packageVersion pkg numPatches <- versionPatches verbosity darcsVersion return (display darcsVersion, versionStateString numPatches) where versionStateString :: Maybe Int -> String versionStateString Nothing = "unknown" versionStateString (Just 0) = "release" versionStateString (Just 1) = "+ 1 patch" versionStateString (Just n) = "+ " ++ show n ++ " patches" versionPatches :: Verbosity -> Version -> IO (Maybe Int) versionPatches verbosity darcsVersion = do numPatchesDarcs <- do out <- rawSystemStdout verbosity "darcs" ["log", "-a", "--from-tag", display darcsVersion, "--count"] case reads out of ((n,_):_) -> return $ Just ((n :: Int) - 1) _ -> return Nothing `catchAny` \_ -> return Nothing numPatchesDist <- parseFile versionFile return $ case (numPatchesDarcs, numPatchesDist) of (Just x, _) -> Just x (Nothing, Just x) -> Just x (Nothing, Nothing) -> Nothing where versionFile = "release/distributed-version" generateVersionModule :: Verbosity -> LocalBuildInfo -> String -> String -> IO () generateVersionModule verbosity lbi version state = do let dir = autogenModulesDir lbi createDirectoryIfMissingVerbose verbosity True dir ctx <- context verbosity hash <- weakhash verbosity rewriteFile (dir "Version.hs") $ unlines ["module Version where" ,"version, weakhash, context :: String" ,"version = \"" ++ version ++ " (" ++ state ++ ")\"" ,"weakhash = " ++ case hash of Just x -> show x Nothing -> show "not available" ,"context = " ++ case ctx of Just x -> show x Nothing -> show "context not available" ] weakhash :: Verbosity -> IO (Maybe String) weakhash verbosity = do inrepo <- doesDirectoryExist "_darcs" unless inrepo $ fail "Not a repository." out <- rawSystemStdout verbosity "darcs" ["show", "repo"] let line = filter ("Weak Hash:" `isInfixOf`) $ lines out return $ case (length line) of 0 -> Nothing _ -> Just $ last $ words $ head line `catchAny` \_ -> return Nothing context :: Verbosity -> IO (Maybe String) context verbosity = do contextDarcs <- do inrepo <- doesDirectoryExist "_darcs" unless inrepo $ fail "Not a repository." out <- rawSystemStdout verbosity "darcs" ["log", "-a", "--context"] return $ Just out `catchAny` \_ -> return Nothing contextDist <- parseFile contextFile return $ case (contextDarcs, contextDist) of (Just x, _) -> Just x (Nothing, Just x) -> Just x (Nothing, Nothing) -> Nothing where contextFile = "release/distributed-context" parseFile :: (Read a) => String -> IO (Maybe a) parseFile f = do exist <- doesFileExist f if exist then do content <- readFile f -- ^ ratify readFile: we don't care here. case reads content of ((s,_):_) -> return s _ -> return Nothing else return Nothing darcs-2.14.5/contrib/0000755000000000000000000000000007346545000012530 5ustar0000000000000000darcs-2.14.5/contrib/_darcs.zsh0000755000000000000000000000217407346545000014520 0ustar0000000000000000#compdef darcs ## Darcs completion for zsh. ## ## Originally derived from a version by ## Copyright (C) 2009 Nicolas Pouillard local -a darcs_options darcs_non_options darcs_arguments if (($CURRENT == 2)); then compadd -- $(darcs --commands) else case "${words[2]}"; in get|clone) _urls ;; esac case "${words[$CURRENT]}"; in /*|./*|\~*|../*) _files ;; -*) # advanced zsh (array) parameter expansion fu: # - ${(f)...} means split into array elements at line endings # instead of white space # - ${arr:#pat} drops elements matching pat from arr, whereas # ${(M)arr:#pat} drops non-matching elements # - ${arr/pat/repl} replaces pat with repl for all elements of arr darcs_arguments=(${(f)"$(words[$CURRENT]=--list-options && $words 2>/dev/null)"}) darcs_options=(${${(M)darcs_arguments:#-*}/;/:}) _describe '' darcs_options ;; *) darcs_arguments=(${(f)"$(words[$CURRENT]=--list-options && $words 2>/dev/null)"}) darcs_non_options=(${darcs_arguments:#-*}) _multi_parts -i -S ' ' / darcs_non_options ;; esac fi darcs-2.14.5/contrib/cygwin-wrapper.bash0000755000000000000000000002011707346545000016351 0ustar0000000000000000#! /bin/bash DIRNAME=`dirname "${0}"` if [ "${DIRNAME:0:1}" = "/" ] ; then DARCSPACKAGEDIR="${DIRNAME}" else DARCSPACKAGEDIR="${PWD}/${DIRNAME}" fi # If the DARCSPACKAGEDIR assignment above doesn't work for some funny reason, # you could set these variables by hand. Or fix the script to work # automatically and submit a patch. # Should be set to the full Cygwin path to the directory containing the # putty executables. putty_binary_dir="${DARCSPACKAGEDIR}" # Should be set to the full Cygwin path to the directory containing the # Windows binary "darcs.exe". darcs_binary_dir="$putty_binary_dir" # Should be set to the full Cygwin path to the Windows binary # "darcs.exe". darcs_binary="${darcs_binary_dir}/realdarcs.exe" #--------------------------------------------------------------------- # Darcs Wrapper for Cygwin # # A Bash script that allows Cywin paths on the command line when using # a version of Darcs compiled for Windows. Darcs will still use still # Windows paths internally. # #--------------------------------------------------------------------- # Usage # # Edit this file and set the variables above. Then, rename this # script to "darcs" and put it in your PATH somewhere before the # original binary. # # Darcs needs to launch itself for some operations and so the original # binary needs to be in your Windows PATH. Do not rename it. # #--------------------------------------------------------------------- # Known Issues # # This script is just a stopgap measure. Things don't work perfectly. # We really need a Cygwin build of Darcs. # # No path conversion is performed on: # - Any preferences set with "setpref" # - The "COMMAND" argument to "darcs trackdown" # # When Darcs launches external programs, it uses a Windows system call # to do so. This means you may not be able to run "hash bang" scripts # directly. For example, to run the Bash script "myscript", you'll # have to tell Darcs to run "bash myscript". # # -------------------------------------------------------------------- PATH="$putty_binary_dir:$darcs_binary_dir:${PATH}" debug=false cmd="$1" # Print each argument to stderr on a separate line. Then exit. function die() { local line for line in "$@"; do echo "$line" > /dev/stderr done exit 2 } # Make sure 'darcs_binary_dir' is set. if [ ! -d "$darcs_binary_dir" ]; then die "Please edit this script and set the 'darcs_binary_dir' variable" \ "to refer to a valid directory." \ " script path = '$0'" \ " darcs_binary_dir = '$darcs_binary_dir'" fi # Special case for when the first argument is an option. if expr match "$cmd" '-' > /dev/null; then if $debug; then # echo "SIMPLE CASE:" for arg in "$@"; do echo " arg = '$arg'" done else # echo about to exec -a darcs "$darcs_binary" "$@" exec -a darcs "$darcs_binary" "$@" fi fi # Shift off the darcs command name shift function is_opaque_opt() { local opt for opt in "${opaque_binary_opts[@]}"; do if [ "$opt" == "$1" ]; then return 0 fi done return 1 } function is_file_opt() { local opt for opt in "${file_binary_opts[@]}"; do if [ "$opt" == "$1" ]; then return 0 fi done return 1 } # Options are not dealt with in a command-specific way. AFAIK, Darcs # doesn't use the same option in two different ways, so we should be # fine. # List of "opaque" binary options. These are options where we don't # treat the option argument like a file. declare -a opaque_binary_opts=( \ '--repo-name' \ '--to-match' '--to-patch' '--to-tag' '--to-hash' \ '--from-match' '--from-patch' '--from-tag' '--from-hash' \ '-t' '--tag' '--tags' '--tag-name' \ '-p' '--patch' '--patches' \ '-m' '--patch-name' \ '-h' '--hash' \ '--matches' '--match' \ '--token-chars' \ '-A' '--author' '--from' '--to' '--cc' \ '--sign-as' '--creator-hash' \ '--last' '--diff-opts' \ '-d' '--dist-name' \ '--log-file' \ '--apply-as' \ ) # List of binary options that take file arguments that need to be converted. declare -a file_binary_opts=( \ '--repodir' '--repo' '--sibling' \ '--context' \ '--logfile' '-o' '--output' \ '--external-merge' \ '--sign-ssl' '--verify' '--verify-ssl' \ ) # -------------------------------------------------------------------- # The three command categories. We only use the first one, but the # others are listed to make sure we've covered everything. Luckily, # there aren't any commands that have some args that need to be # converted and some that don't. # Commands whose arguments are file paths that need to be translated. cmds_convert_nonoption_args='|clone|pull|push|send|apply' # Commands who's arguments should be left alone. File paths that # refer to files in the repo should NOT be converted because they # are relative paths, which Darcs will handle just fine. Cygwin # sometimes makes them absolute paths, which confuses Darcs. #cmds_no_convert_nonoption_paths='|add|remove|mv|replace|record|whatsnew|log|setpref|test|amend|revert|diff|annotate' # Commands that don't accept non-option arguments #cmds_no_nonoption_args='|initialize|tag|optimize|rollback|unrecord|unpull|dist|repair' # See if we need to convert the non-option args for the current # command. This matches some prefix of one of the commands in the # list. The match may not be unambiguous, we can rely on Darcs to # deal with that correctly. if expr match "$cmds_convert_nonoption_args" ".*|$cmd" > /dev/null; then convert_nonoption_args=true else convert_nonoption_args=false fi function convert_path() { # echo "converting path ${*} ..." >> /tmp/log if expr match "$1" '[-@._A-Za-z0-9]*:' > /dev/null; then # Some sort of URL or remote ssh pathname ("xxx:/") echo "$1" # echo "converting path ${*} ... to ${1}" >> /tmp/log elif [ "$1" == '.' ]; then # Compensate for stupid 'cygpath' behavior. echo '.' # echo "converting path ${*} ... to ." >> /tmp/log else cygpath -wl -- "$1" # echo "converting path ${*} ... to `cygpath -wl -- ${1}`" >> /tmp/log fi } declare -a params=("$cmd") num_nonoption_args=0 while [ $# -gt 0 ]; do arg=$1 shift if expr match "$arg" '-' > /dev/null; then # It's an option. Check to see if it's an opaque binary option. if expr match "$arg" '.*=' > /dev/null; then # The option has an '=' in it. opt=`expr match "$arg" '\([^=]*\)'` opt_arg=`expr match "$arg" '[^=]*=\(.*\)'` if is_opaque_opt "$opt"; then true; elif is_file_opt "$opt"; then opt_arg=`convert_path "$opt_arg"` else die "darcs-wrapper: I don't think '$opt' accepts an argument." \ "[ If it does, then there is a bug in the wrapper script. ]" fi params[${#params[*]}]="$opt=$opt_arg" else # The option doesn't have an '=' opt="$arg" if is_opaque_opt "$opt"; then if [ $# -eq 0 ]; then die "darcs-wrapper: I think '$arg' requires an argument." \ "[ If it doesn't, then there is a bug in the wrapper script. ]" fi opt_arg="$1" shift params[${#params[*]}]="$opt" params[${#params[*]}]="$opt_arg" elif is_file_opt "$opt"; then if [ $# -eq 0 ]; then die "darcs-wrapper: I think '$arg' requires an argument." \ "[ If it doesn't, then there is a bug in the wrapper script. ]" fi opt_arg=`convert_path "$1"` shift params[${#params[*]}]="$opt" params[${#params[*]}]="$opt_arg" else params[${#params[*]}]="$opt" fi fi else if $convert_nonoption_args; then arg=`convert_path "$arg"` fi params[${#params[*]}]="$arg" (( num_nonoption_args += 1 )) fi done # DEBUG if $debug; then echo "ARGS:" for arg in "${params[@]}"; do echo " arg = '$arg'" done else # echo about to exec -a darcs "$darcs_binary" "${params[@]}" exec -a darcs "$darcs_binary" "${params[@]}" fi darcs-2.14.5/contrib/darcs-errors.hlint0000755000000000000000000000255007346545000016203 0ustar0000000000000000-- The problem with Prelude readFile is that it's based on hGetContents, which -- is lazy by definition. This also means that unless you force consumption of -- the produced list, it will keep an fd open for the file, possibly -- indefinitely. This is called a fd leak. Other than being annoying and if done -- often, leading to fd exhaustion and failure to open any new files (which is -- usually fatal), it also prevents the file to be unlinked (deleted) on win32. -- On the other hand, *strict* bytestring version of readFile will read the whole -- file into a contiguous buffer, *close the fd* and return. This is perfectly -- safe with regards to fd leaks. Btw., this is *not* the case with lazy -- bytestring variant of readFile, so that one is unsafe as well. error "Avoid Prelude.readFile" = Prelude.readFile ==> Data.ByteString.readFile error "Avoid hGetContents" = System.IO.hGetContents ==> Data.ByteString.hGetContents error "Avoid BL.hGetContents" = Data.ByteString.Lazy.hGetContents ==> Data.ByteString.hGetContents error "Avoid BL.hGetContents" = Data.ByteString.Lazy.Char8.hGetContents ==> Data.ByteString.hGetContents -- error "Avoid BL.readFile" = Data.ByteString.Lazy.Char8.readFile ==> Data.ByteString.readFile -- error "Avoid BL.readFile" = Data.ByteString.Lazy.readFile ==> Data.ByteString.readFile darcs-2.14.5/contrib/darcs_completion0000755000000000000000000000476007346545000016012 0ustar0000000000000000#-*- mode: shell-script;-*- # darcs command line completion. # Copyright 2002 "David Roundy" # This archive should be copied in the directory /etc/bash_completion.d/ _darcs() { local cur cur=${COMP_WORDS[COMP_CWORD]} COMPREPLY=() if (($COMP_CWORD == 1)); then COMPREPLY=( $( darcs --commands | command grep "^$cur" ) ) return 0 fi # Store the whole command line substituting the (possibly empty) # to-be-completed word with '--list-options'. local -a words=("${COMP_WORDS[@]}") words[$COMP_CWORD]="--list-options" # Options are processed from left to right, so avoid to display the help # page when trying to complete a command line that includes '--help'. It # could be tricked by things like '--repodir --hell', but, come on... you # don't deserve a working completion if you name a directory '--hell'. for w in "${words[@]}"; do case "$w" in (--he*) return 0;; esac done # So that the following "command-output to array" operation splits only at # newlines, not at each space, tab or newline. local IFS=$'\n' COMPREPLY=( $( "${words[@]}" 2>/dev/null |\ command grep "^${cur//./\\.}" | cut -d ';' -f 1) ) # Then, we adapt the resulting strings to be reusable by bash. If we don't # do this, in the case where we have two repositories named # ~/space in there-0.1 and ~/space in there-0.2, the first completion will # give us: # bash> darcs push ~/space in there-0. # ~/space in there-0.1 ~/space in there-0.2 # and we have introduced two spaces in the command line (if we try to # recomplete that, it won't find anything, as it doesn't know anything # starting with "there-0."). # printf %q will gracefully add the necessary backslashes. # # Bash also interprets colon as a separator. If we didn't handle it # specially, completing http://example.org/repo from http://e would # give us: # bash> darcs pull http:http://example.org/repo # An option would be to require the user to escape : as \: and we # would do the same here. Instead, we return only the part after # the last colon that is already there, and thus fool bash. The # downside is that bash only shows this part to the user. local i=${#COMPREPLY[*]} local colonprefixes=${cur%"${cur##*:}"} while [ $((--i)) -ge 0 ]; do COMPREPLY[$i]=`printf %q "${COMPREPLY[$i]}"` COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} done return 0 } complete -F _darcs -o default darcs darcs-2.14.5/contrib/runHLint.sh0000755000000000000000000000063107346545000014632 0ustar0000000000000000#!/bin/bash hlint --hint=contrib/darcs-errors.hlint --cpp-simple ./src hlint --cpp-simple ./src # --cpp-simple is to avoid issues with MIN_VERSION # see https://github.com/ndmitchell/hlint/issues/53 # using it creates other problems since #if are ignored.. # When the above bug is solved we can use: # hlint --hint=contrib/darcs-errors.hlint --cpp-include=./src ./src # hlint --cpp-include=./src ./src darcs-2.14.5/contrib/update_roundup.pl0000755000000000000000000000520407346545000016127 0ustar0000000000000000#!/usr/bin/perl use strict; use warnings; # A script to update the status of an issue in a Roundup bug tracker # based on the format of a darcs patch name. # It is intended to be run from a darcs posthook. # The format we look for is: # resolved issue123 # in the first line of the patch. use Getopt::Long; use MIME::Lite; use XML::Simple; my $UPDATE_STRING="status=resolved"; if (scalar(@ARGV) == 1) { $UPDATE_STRING=$ARGV[0]; } unless ($ENV{DARCS_PATCHES_XML}) { die "DARCS_PATCHES_XML was expected to be set in the environment, but was not found. Are you running this from a Darcs 2.0 or newer posthook?" } my $xml = eval { XMLin($ENV{DARCS_PATCHES_XML}, forcearray=>['patch']); }; die "hmmm.. we couldn't parse your XML. The error was: $@" if $@; # $xml structure returned looks like this: # 'patch' => { # 'resolved issue123: adding t.t' => { # 'hash' => '20080215033723-20bb4-54f935f89817985a3e98f3de8e8ac9dad5e8e0e5.gz', # 'inverted' => 'False', # 'date' => '20080215033723', # 'author' => 'Mark Stosberg ', # 'local_date' => 'Thu Feb 14 22:37:23 EST 2008' # }, # 'some other patch' => { ... }, for my $patch_name (keys %{ $xml->{patch} }) { my $issue_re = qr/resolved? \s+ (issue ?\d+)/msxi; next unless ($patch_name =~ $issue_re); my $issue = $1; my $patch = $xml->{patch}{$patch_name}; # Using the Command Line would be a simpler alternative. # my $out = `roundup-admin -i /var/lib/roundup/trackers/darcs set $issue status=resolved`; # warn "unexpected output: $out" if $out; my $author = $patch->{author}; # If the Author name contains an @ sign, we take it to be an e-mail address. # Otherwise, we default to darcs-devel as the sender. my $email = ($author =~ m/\@/) ? $author : 'darcs-devel@darcs.net'; my $comment = $patch->{comment} ? "\n$patch->{comment}" : ''; my $patch_name_minus_status = $patch_name; $patch_name_minus_status =~ s/$issue_re(:?\s?)//; # Each patches can potentially update the status of a different issue, so generates a different e-mail my $msg = MIME::Lite->new( From => 'noreply@darcs.net', To =>'bugs@lists.osuosl.org', #To =>'mark@stosberg.com', Subject =>"[$issue] [$UPDATE_STRING]", Type =>'text/plain', Data => qq!The following patch sent by $email updated issue $issue with $UPDATE_STRING * $patch_name $comment ! ); $msg->send; # An alternative to actually sending, for debugging. # use File::Slurp; # write_file("msg-$patch->{hash}.out",$msg->as_string); } darcs-2.14.5/contrib/upload.cgi0000755000000000000000000000755307346545000014515 0ustar0000000000000000#!/usr/bin/perl use strict; use File::Temp qw/ tempdir tempfile /; # this is a sample cgi script to accept darcs patches via POST # it simply takes patches and sends them using sendmail or # places them in a Maildir style mailbox. my $tmp_dir; # temporary directory, when placing patches to maildir # files are linked from $tmp_dir to $maildir $tmp_dir = "/tmp"; # target email addresses--leave blank to use To: header in patch contents. my $target_email; # target repository for patch testing. Leave blank to use DarcsURL header # in patch contents. my $target_repo; my $sendmail_cmd; # command to send patches with $sendmail_cmd = "/usr/sbin/sendmail -i -t $target_email"; my $maildir; # maildir to put patches to, replace sendmail #$maildir = "/tmp/maildir"; my $patch_test_cmd; # command to test patches with $patch_test_cmd = "darcs apply --dry-run --repodir 'TARGETREPO' 'TARGETPATCH'"; my $repo_clone_cmd; # command to clone testing repo # used only when $target_repo is blank $repo_clone_cmd = "darcs clone --lazy --repodir 'TARGETDIR' 'TARGETREPO'"; sub error_page { my ($m) = @_; print "Status: 500 Error accepting patch\n"; print "Content-Type: text/plain\n\n"; print($m || "There was an error processing your request"); print "\n"; exit 0; } sub success_page { print "Content-Type: text/plain\n\n"; print "Thank you for your contribution!\n"; exit 0; } if ($ENV{CONTENT_TYPE} eq 'message/rfc822') { my $m = start_message() or error_page("could not create temporary file"); my $fh = $m->{fh}; my ($totalbytes, $bytesread, $buffer); do { $bytesread = read(STDIN, $buffer, 1024); print $fh $buffer; $totalbytes += $bytesread; } while ($bytesread); my $r = end_message($m); $r ? error_page($r) : success_page(); } elsif ($ENV{CONTENT_TYPE}) { error_page("invalid content type, I expect something of message/rfc822"); } else { error_page("This url is for accepting darcs patches."); } sub maildir_file { my ($tmp_file) = @_; my $base_name = sprintf("patch-%d-%d-0000", $$, time()); my $count = 0; until (link("$tmp_file", "$maildir/$base_name")) { $base_name =~ s/-(\d+)$/"-" . (1 + $1)/e; return undef if $count++ > 100; } return "$maildir/$base_name"; } sub start_message { my ($fh, $fname) = tempfile("$tmp_dir/dpatch".'X'x8, UNLINK => 1) or return undef; return { fh => $fh, filename => $fname }; } sub end_message { my ($m) = @_; close $m->{fh} or return "$!: $m->{filename} - Could not close filehandle"; unless ($target_repo) { # Look for DarcsURL header my $darcsurl; open(MF,$m->{filename}) or return "$!: $m->{filename} - Could not open file"; while () { if (/^DarcsURL: (.+)$/) { $darcsurl = $1; last; } } close(MF); return "Could not find DarcsURL header" unless $darcsurl; my $test_dir = tempdir(CLEANUP => 1).'/repo' or return "$!: Could not create test directory"; $repo_clone_cmd =~ s/TARGETDIR/$test_dir/; $repo_clone_cmd =~ s/TARGETREPO/$darcsurl/; system("$repo_clone_cmd >/dev/null 2>/dev/null") == 0 or return "Could not clone target repo: '$repo_clone_cmd' failed"; $target_repo = $test_dir; } $patch_test_cmd =~ s/TARGETREPO/$target_repo/; $patch_test_cmd =~ s/TARGETPATCH/$m->{filename}/; system("$patch_test_cmd >/dev/null 2>/dev/null") == 0 or return "Patch is not valid: '$patch_test_cmd' failed"; if ($maildir) { maildir_file("$m->{filename}") or return "$!: Could not create a new file in maildir"; } else { system("$sendmail_cmd < '$m->{filename}'") == 0 or return "$!: Could not send mail"; } return 0; } darcs-2.14.5/darcs.cabal0000644000000000000000000005460107346545000013156 0ustar0000000000000000cabal-version: 1.24 Name: darcs version: 2.14.5 License: GPL-2 License-file: COPYING Author: David Roundy , Maintainer: Stability: Experimental Category: Development Synopsis: a distributed, interactive, smart revision control system Description: Darcs is a free, open source revision control system. It is: . * Distributed: Every user has access to the full command set, removing boundaries between server and client or committer and non-committers. . * Interactive: Darcs is easy to learn and efficient to use because it asks you questions in response to simple commands, giving you choices in your work flow. You can choose to record one change in a file, while ignoring another. As you update from upstream, you can review each patch name, even the full "diff" for interesting patches. . * Smart: Originally developed by physicist David Roundy, darcs is based on a unique algebra of patches. . This smartness lets you respond to changing demands in ways that would otherwise not be possible. Learn more about spontaneous branches with darcs. . * Please note that hackage does not correctly display the license. It is meant to be "GPL-2.0-or-later". Homepage: http://darcs.net/ Build-Type: Custom extra-source-files: -- C files src/*.c src/*.h src/win32/send_email.c src/win32/send_email.h src/win32/sys/mman.h contrib/cygwin-wrapper.bash contrib/darcs_completion contrib/darcs-errors.hlint contrib/_darcs.zsh contrib/runHLint.sh contrib/update_roundup.pl contrib/upload.cgi README.md CHANGELOG -- release data release/distributed-version release/distributed-context -- testsuite tests/data/*.tgz tests/data/README tests/data/*.dpatch tests/data/example_binary.png tests/data/convert/darcs1/*.dpatch tests/data/convert/darcs2/*.dpatch tests/*.sh tests/README.test_maintainers.txt tests/bin/*.hs tests/network/sshlib tests/network/*.sh tests/lib harness/hstestdata.zip GNUmakefile source-repository head type: darcs location: http://darcs.net/ flag curl description: Use libcurl for HTTP support. -- in future this could extend to any other external libraries, -- e.g. libiconv flag pkgconfig description: Use pkgconfig to configure libcurl default: False flag static description: Build static binary default: False flag terminfo description: Use the terminfo package for enhanced console support. flag threaded description: Use threading and SMP support. default: True flag executable description: Build darcs executable default: True manual: True flag rts default: False flag warn-as-error default: False manual: True description: Build with warnings-as-errors -- ---------------------------------------------------------------------- -- setup -- ---------------------------------------------------------------------- custom-setup setup-depends: base >= 4.9 && < 4.15, Cabal >= 1.24, process >= 1.2.3.0 && < 1.7, filepath >= 1.4.1 && < 1.5.0.0, directory >= 1.2.6.2 && < 1.4 -- ---------------------------------------------------------------------- -- darcs library -- ---------------------------------------------------------------------- Library default-language: Haskell2010 hs-source-dirs: src include-dirs: src exposed-modules: Darcs.Patch Darcs.Patch.Annotate Darcs.Patch.Apply Darcs.Patch.ApplyMonad Darcs.Patch.ApplyPatches Darcs.Patch.Bracketed Darcs.Patch.Bracketed.Instances Darcs.Patch.Bundle Darcs.Patch.Choices Darcs.Patch.Commute Darcs.Patch.CommuteFn Darcs.Patch.Conflict Darcs.Patch.Debug Darcs.Patch.Depends Darcs.Patch.Dummy Darcs.Patch.Effect Darcs.Patch.FileHunk Darcs.Patch.Index.Monad Darcs.Patch.Index.Types Darcs.Patch.Format Darcs.Patch.Info Darcs.Patch.Inspect Darcs.Patch.Invert Darcs.Patch.Match Darcs.Patch.Matchable Darcs.Patch.Merge Darcs.Patch.MonadProgress Darcs.Patch.Named Darcs.Patch.Named.Wrapped Darcs.Patch.PatchInfoAnd Darcs.Patch.Permutations Darcs.Patch.Prim Darcs.Patch.Prim.Class Darcs.Patch.Prim.V1 Darcs.Patch.Prim.V1.Apply Darcs.Patch.Prim.V1.Coalesce Darcs.Patch.Prim.V1.Commute Darcs.Patch.Prim.V1.Core Darcs.Patch.Prim.V1.Details Darcs.Patch.Prim.V1.Read Darcs.Patch.Prim.V1.Show Darcs.Patch.Prim.FileUUID Darcs.Patch.Prim.FileUUID.ObjectMap Darcs.Patch.Prim.FileUUID.Apply Darcs.Patch.Prim.FileUUID.Coalesce Darcs.Patch.Prim.FileUUID.Commute Darcs.Patch.Prim.FileUUID.Core Darcs.Patch.Prim.FileUUID.Details Darcs.Patch.Prim.FileUUID.Read Darcs.Patch.Prim.FileUUID.Show Darcs.Patch.Progress Darcs.Patch.Read Darcs.Patch.Rebase Darcs.Patch.Rebase.Container Darcs.Patch.Rebase.Fixup Darcs.Patch.Rebase.Item Darcs.Patch.Rebase.Name Darcs.Patch.Rebase.Viewing Darcs.Patch.ReadMonads Darcs.Patch.RegChars Darcs.Patch.Repair Darcs.Patch.RepoPatch Darcs.Patch.RepoType Darcs.Patch.Set Darcs.Patch.Show Darcs.Patch.Split Darcs.Patch.Summary Darcs.Patch.SummaryData Darcs.Patch.TokenReplace Darcs.Patch.TouchesFiles Darcs.Patch.Type Darcs.Patch.Viewing Darcs.Patch.V1 Darcs.Patch.V1.Apply Darcs.Patch.V1.Commute Darcs.Patch.V1.Core Darcs.Patch.V1.Prim Darcs.Patch.V1.Read Darcs.Patch.V1.Show Darcs.Patch.V1.Viewing Darcs.Patch.V2 Darcs.Patch.V2.Non Darcs.Patch.V2.Prim Darcs.Patch.V2.RepoPatch Darcs.Patch.Witnesses.Eq Darcs.Patch.Witnesses.Ordered Darcs.Patch.Witnesses.Sealed Darcs.Patch.Witnesses.Show Darcs.Patch.Witnesses.Unsafe Darcs.Patch.Witnesses.WZipper Darcs.Prelude Darcs.Repository Darcs.Repository.ApplyPatches Darcs.Repository.Cache Darcs.Repository.Clone Darcs.Repository.Create Darcs.Repository.PatchIndex Darcs.Repository.Diff Darcs.Repository.Flags Darcs.Repository.Format Darcs.Repository.HashedIO Darcs.Repository.Hashed Darcs.Repository.Inventory Darcs.Repository.Identify Darcs.Repository.Job Darcs.Repository.Merge Darcs.Repository.InternalTypes Darcs.Repository.Match Darcs.Repository.Old Darcs.Repository.Packs Darcs.Repository.Pending Darcs.Repository.Prefs Darcs.Repository.Rebase Darcs.Repository.Repair Darcs.Repository.Resolution Darcs.Repository.State Darcs.Repository.Test Darcs.Repository.Working Darcs.UI.ApplyPatches Darcs.UI.Commands Darcs.UI.Commands.Add Darcs.UI.Commands.Amend Darcs.UI.Commands.Annotate Darcs.UI.Commands.Apply Darcs.UI.CommandsAux Darcs.UI.Commands.Clone Darcs.UI.Commands.Convert Darcs.UI.Commands.Diff Darcs.UI.Commands.Dist Darcs.UI.Commands.GZCRCs Darcs.UI.Commands.Help Darcs.UI.Commands.Init Darcs.UI.Commands.Log Darcs.UI.Commands.MarkConflicts Darcs.UI.Commands.Move Darcs.UI.Commands.Optimize Darcs.UI.Commands.Pull Darcs.UI.Commands.Push Darcs.UI.Commands.Rebase Darcs.UI.Commands.Record Darcs.UI.Commands.Remove Darcs.UI.Commands.Repair Darcs.UI.Commands.Replace Darcs.UI.Commands.Revert Darcs.UI.Commands.Rollback Darcs.UI.Commands.Send Darcs.UI.Commands.SetPref Darcs.UI.Commands.Show Darcs.UI.Commands.ShowAuthors Darcs.UI.Commands.ShowContents Darcs.UI.Commands.ShowDependencies Darcs.UI.Commands.ShowFiles Darcs.UI.Commands.ShowIndex Darcs.UI.Commands.ShowPatchIndex Darcs.UI.Commands.ShowRepo Darcs.UI.Commands.ShowTags Darcs.UI.Commands.Tag Darcs.UI.Commands.Test Darcs.UI.Commands.TransferMode Darcs.UI.Commands.Util Darcs.UI.Commands.Util.Tree Darcs.UI.Commands.Unrecord Darcs.UI.Commands.Unrevert Darcs.UI.Commands.WhatsNew Darcs.UI.Completion Darcs.UI.Email Darcs.UI.External Darcs.UI.Defaults Darcs.UI.Flags Darcs.UI.Options Darcs.UI.Options.All Darcs.UI.Options.Core Darcs.UI.Options.Flags Darcs.UI.Options.Iso Darcs.UI.Options.Markdown Darcs.UI.Options.Matching Darcs.UI.Options.Util Darcs.UI.PatchHeader Darcs.UI.PrintPatch Darcs.UI.RunCommand Darcs.UI.SelectChanges Darcs.UI.TheCommands Darcs.UI.Usage Darcs.Util.AtExit Darcs.Util.ByteString Darcs.Util.CommandLine Darcs.Util.Compat Darcs.Util.DateMatcher Darcs.Util.DateTime Darcs.Util.Diff Darcs.Util.Diff.Myers Darcs.Util.Diff.Patience Darcs.Util.Download Darcs.Util.Download.Request Darcs.Util.Download.HTTP Darcs.Util.Encoding Darcs.Util.English Darcs.Util.Exception Darcs.Util.Exec Darcs.Util.External Darcs.Util.File Darcs.Util.Global Darcs.Util.Hash Darcs.Util.Index Darcs.Util.IsoDate Darcs.Util.Lock Darcs.Util.Path Darcs.Util.Printer Darcs.Util.Printer.Color Darcs.Util.Progress Darcs.Util.Prompt Darcs.Util.Ratified Darcs.Util.Show Darcs.Util.SignalHandler Darcs.Util.Ssh Darcs.Util.Text Darcs.Util.Tree Darcs.Util.Tree.Hashed Darcs.Util.Tree.Monad Darcs.Util.Tree.Plain Darcs.Util.URL Darcs.Util.Workaround autogen-modules: Version other-modules: Version Darcs.Util.Download.Curl c-sources: src/atomic_create.c src/maybe_relink.c src/umask.c src/system_encoding.c -- see http://bugs.darcs.net/issue1037 cc-options: -D_REENTRANT if os(windows) hs-source-dirs: src/win32 include-dirs: src/win32 other-modules: Darcs.Util.CtrlC Darcs.Util.Encoding.Win32 -- These are kept outside the Darcs.* namespace as System.Posix -- is well-established and its just trying to simulate that -- TODO try to abstract this out better System.Posix System.Posix.Files System.Posix.IO cpp-options: -DWIN32 c-sources: src/win32/send_email.c build-depends: Win32 >= 2.3.1 && < 2.4 else build-depends: unix >= 2.7.1.0 && < 2.8 build-depends: base >= 4.9 && < 4.15, stm >= 2.1 && < 2.6, binary >= 0.5 && < 0.10, containers >= 0.5.6.2 && < 0.7, regex-compat-tdfa >= 0.95.1 && < 0.96, regex-applicative >= 0.2 && < 0.4, mtl >= 2.2.1 && < 2.3, transformers >= 0.4.2.0 && < 0.6, parsec >= 3.1.9 && < 3.2, fgl >= 5.5.2.3 && < 5.8, graphviz >= 2999.18.1 && < 2999.20.1, html >= 1.0.1.2 && < 1.1, filepath >= 1.4.1 && < 1.5.0.0, haskeline >= 0.7.2 && < 0.9, cryptohash >= 0.11 && < 0.12, base16-bytestring >= 0.1 && < 0.2, utf8-string >= 1 && < 1.1, vector >= 0.11 && < 0.13, tar >= 0.5 && < 0.6, data-ordlist == 0.4.*, attoparsec >= 0.13.0.1 && < 0.14, zip-archive >= 0.3 && < 0.5, async >= 2.0.2 && < 2.3, sandi >= 0.4 && < 0.6, unix-compat >= 0.4.2 && < 0.6, bytestring >= 0.10.6 && < 0.11, old-time >= 1.1.0.3 && < 1.2, time >= 1.5.0.1 && < 1.10, text >= 1.2.1.3 && < 1.3, directory >= 1.2.6.2 && < 1.4, process >= 1.2.3.0 && < 1.7, array >= 0.5.1.0 && < 0.6, random >= 1.1 && < 1.2, hashable >= 1.2.3.3 && < 1.4, mmap >= 0.5.9 && < 0.6, zlib >= 0.6.1.2 && < 0.7.0.0, network-uri == 2.6.*, network >= 2.6 && < 3.2, HTTP >= 4000.2.20 && < 4000.4 if flag(warn-as-error) ghc-options: -Werror ghc-options: -Wall -funbox-strict-fields -fwarn-tabs if flag(curl) cpp-options: -DHAVE_CURL c-sources: src/hscurl.c cc-options: -DHAVE_CURL if flag(pkgconfig) pkgconfig-depends: libcurl else extra-libraries: curl includes: curl/curl.h -- The terminfo package cannot be built on Windows. if flag(terminfo) && !os(windows) build-depends: terminfo >= 0.4.0.2 && < 0.5 cpp-options: -DHAVE_TERMINFO default-extensions: BangPatterns PatternGuards GADTSyntax ExistentialQuantification TypeOperators FlexibleContexts FlexibleInstances ScopedTypeVariables KindSignatures DataKinds ConstraintKinds RankNTypes TypeFamilies NoMonoLocalBinds -- ---------------------------------------------------------------------- -- darcs itself -- ---------------------------------------------------------------------- Executable darcs if !flag(executable) buildable: False else buildable: True default-language: Haskell2010 main-is: darcs.hs hs-source-dirs: darcs if flag(warn-as-error) ghc-options: -Werror if impl(ghc >= 8.2) ghc-options: -Wno-missing-home-modules ghc-options: -Wall -funbox-strict-fields -fwarn-tabs if flag(threaded) ghc-options: -threaded if flag(static) ghc-options: -static -optl-static -optl-pthread if flag(rts) ghc-options: -rtsopts -- see http://bugs.darcs.net/issue1037 cc-options: -D_REENTRANT build-depends: darcs, base -- ---------------------------------------------------------------------- -- unit test driver -- ---------------------------------------------------------------------- test-suite darcs-test buildable: True type: exitcode-stdio-1.0 default-language: Haskell2010 main-is: test.hs hs-source-dirs: harness if os(windows) cpp-options: -DWIN32 build-depends: Win32 >= 2.3.1 && < 2.4 build-depends: darcs, base, array, bytestring, cmdargs >= 0.10.10 && < 0.11, containers, filepath, mtl, transformers, shelly >= 1.6.8 && < 1.10, split >= 0.2.2 && < 0.3, text, directory, FindBin >= 0.0.5 && < 0.1, QuickCheck >= 2.8.2 && < 2.14, HUnit >= 1.3 && < 1.7, test-framework >= 0.8.1.1 && < 0.9, test-framework-hunit >= 0.3.0.2 && < 0.4, test-framework-quickcheck2 >= 0.3.0.3 && < 0.4, zip-archive -- note for windows we can't allow 1.9 or above until -- https://github.com/gregwebs/Shelly.hs/issues/176 -- and possibly -- https://github.com/gregwebs/Shelly.hs/issues/177 -- are dealt with if os(windows) build-depends: shelly < 1.7.2 -- list all unit test modules not exported by libdarcs; otherwise Cabal won't -- include them in the tarball other-modules: Darcs.Test.Email Darcs.Test.HashedStorage Darcs.Test.Patch.Check Darcs.Test.Patch.Examples.Set1 Darcs.Test.Patch.Examples.Set2Unwitnessed Darcs.Test.Patch.WSub Darcs.Test.Patch.Info Darcs.Test.Patch.Properties.V1Set1 Darcs.Test.Patch.Properties.V1Set2 Darcs.Test.Patch.Properties.Generic Darcs.Test.Patch.Properties.GenericUnwitnessed Darcs.Test.Patch.Properties.Check Darcs.Test.Patch.Properties.RepoPatchV2 Darcs.Test.Patch.Arbitrary.Generic Darcs.Test.Patch.Arbitrary.PrimV1 Darcs.Test.Patch.Arbitrary.PrimFileUUID Darcs.Test.Patch.Arbitrary.RepoPatchV1 Darcs.Test.Patch.Arbitrary.RepoPatchV2 Darcs.Test.Patch.Rebase Darcs.Test.Patch.RepoModel Darcs.Test.Patch.Selection Darcs.Test.Patch.Utils Darcs.Test.Patch.V1Model Darcs.Test.Patch.FileUUIDModel Darcs.Test.Patch.WithState Darcs.Test.Patch Darcs.Test.Misc Darcs.Test.Misc.CommandLine Darcs.Test.Misc.Encoding Darcs.Test.Repository.Inventory Darcs.Test.Util.TestResult Darcs.Test.Util.QuickCheck if flag(warn-as-error) ghc-options: -Werror if impl(ghc >= 8.2) ghc-options: -Wno-missing-home-modules ghc-options: -Wall -funbox-strict-fields -fwarn-tabs -fno-warn-orphans if flag(threaded) ghc-options: -threaded if flag(rts) ghc-options: -rtsopts -- see http://bugs.darcs.net/issue1037 cc-options: -D_REENTRANT default-extensions: GADTSyntax ExistentialQuantification TypeOperators FlexibleContexts FlexibleInstances ScopedTypeVariables KindSignatures DataKinds ConstraintKinds RankNTypes TypeFamilies NoMonoLocalBinds darcs-2.14.5/darcs/0000755000000000000000000000000007346545000012164 5ustar0000000000000000darcs-2.14.5/darcs/darcs.hs0000644000000000000000000000573207346545000013623 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE CPP #-} -- | -- Module : Main -- Copyright : 2002-2003 David Roundy -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Main ( main ) where import Prelude () import Darcs.Prelude import Control.Exception ( AssertionFailed(..), handle ) import System.Exit ( exitWith, ExitCode(..) ) import System.Environment ( getArgs ) import Darcs.UI.RunCommand ( runTheCommand ) import Darcs.UI.Commands.Help ( helpCmd, listAvailableCommands, printVersion, commandControlList ) import Darcs.Util.AtExit ( withAtexit, atexit ) import Darcs.Repository( reportBadSources ) import Darcs.Util.SignalHandler ( withSignalsHandled ) import Darcs.UI.External ( setDarcsEncodings ) import Darcs.Util.Exec ( ExecException(..) ) import Darcs.Util.Path ( getCurrentDirectory ) import Version ( version, context, weakhash ) execExceptionHandler :: ExecException -> IO a execExceptionHandler (ExecException cmd args redirects reason) = do putStrLn . unlines $ [ "Failed to execute external command: " ++ unwords (cmd:args) , "Lowlevel error: " ++ reason , "Redirects: " ++ show redirects ] exitWith $ ExitFailure 3 main :: IO () main = withAtexit . withSignalsHandled . handleExecFail . handleAssertFail $ do atexit reportBadSources setDarcsEncodings argv <- getArgs here <- getCurrentDirectory let runHelpCmd = helpCmd (here, here) [] [] -- Explicitly handle no-args and special "help" arguments. case argv of [] -> printVersion >> runHelpCmd ["-h"] -> runHelpCmd ["--help"] -> runHelpCmd ["--commands"] -> listAvailableCommands ["-v"] -> putStrLn version ["-V"] -> putStrLn version ["--version"] -> putStrLn version ["--exact-version"] -> printExactVersion _ -> runTheCommand commandControlList (head argv) (tail argv) where handleExecFail = handle execExceptionHandler handleAssertFail = handle $ \(AssertionFailed e) -> bug e printExactVersion = do putStrLn $ "darcs compiled on " ++ __DATE__ ++ ", at " ++ __TIME__ ++ "\n" putStrLn $ "Weak Hash: " ++ weakhash putStrLn context darcs-2.14.5/harness/Darcs/Test/0000755000000000000000000000000007346545000014506 5ustar0000000000000000darcs-2.14.5/harness/Darcs/Test/Email.hs0000644000000000000000000001102707346545000016072 0ustar0000000000000000-- Copyright (C) 2002-2005,2007 David Roundy -- Copyright (C) 2009 Reinier Lamers -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | This module contains unit tests of the code in 'Darcs.Email' -- -- These tests check whether the emails generated by darcs meet a few criteria. -- We check for line length and non-ASCII characters. We apparently do not have -- to check for CR-LF newlines because that's handled by sendmail. module Darcs.Test.Email ( testSuite ) where import Data.Char ( isPrint ) import qualified Data.ByteString as B ( length, unpack, null, head, pack, cons, empty, foldr, ByteString ) import qualified Data.ByteString.Char8 as BC ( unlines ) import Test.Framework ( Test, testGroup ) import Test.Framework.Providers.QuickCheck2 ( testProperty ) import Test.QuickCheck ( Arbitrary(..) ) import Darcs.Util.Printer ( text, renderPS, packedString ) import Darcs.UI.Email ( makeEmail, readEmail, formatHeader, prop_qp_roundtrip ) testSuite :: Test testSuite = testGroup "Darcs.Email" [ emailParsing , emailHeaderNoLongLines , emailHeaderAsciiChars , emailHeaderLinesStart , emailHeaderNoEmptyLines , emailCodecRoundtrip ] -- | Checks that darcs can read the emails it generates emailParsing :: Test emailParsing = testProperty "Checking that email can be parsed" $ \bs -> BC.unlines (B.empty:bs++[B.empty,B.empty]) == readEmail (renderPS $ makeEmail "reponame" [] (Just (text "contents\n")) Nothing (packedString $ BC.unlines bs) (Just "filename")) -- | Check that formatHeader never creates lines longer than 78 characters -- (excluding the carriage return and line feed) emailHeaderNoLongLines :: Test emailHeaderNoLongLines = testProperty "Checking email header line length" $ \field value -> let cleanField = cleanFieldString field in not $ any (>78) $ map B.length $ bsLines $ formatHeader cleanField value -- Check that an email header does not contain non-ASCII characters -- formatHeader doesn't escape field names, there is no such thing as non-ascii -- field names afaik emailHeaderAsciiChars :: Test emailHeaderAsciiChars = testProperty "Checking email for illegal characters" $ \field value -> let cleanField = cleanFieldString field in not (any (>127) (B.unpack (formatHeader cleanField value))) -- Check that header the second and later lines of a header start with a space emailHeaderLinesStart :: Test emailHeaderLinesStart = testProperty "Checking for spaces at start of folded email header lines" $ \field value -> let headerLines = bsLines (formatHeader cleanField value) cleanField = cleanFieldString field in all (\l -> B.null l || B.head l == 32) (tail headerLines) -- Checks that there are no lines in email headers with only whitespace emailHeaderNoEmptyLines :: Test emailHeaderNoEmptyLines = testProperty "Checking that there are no empty lines in email headers" $ \field value -> let headerLines = bsLines (formatHeader cleanField value) cleanField = cleanFieldString field in all (not . B.null) headerLines --(not . B.null . B.filter (not . (`elem` [10, 32, 9]))) headerLines instance Arbitrary B.ByteString where arbitrary = fmap B.pack arbitrary emailCodecRoundtrip :: Test emailCodecRoundtrip = testProperty "Checking that quoted printable en- then decoding is id" $ prop_qp_roundtrip bsLines :: B.ByteString -> [B.ByteString] bsLines = finalizeFold . B.foldr splitAtLines (B.empty, []) where splitAtLines 10 (thisLine, prevLines) = (B.empty, thisLine:prevLines) splitAtLines c (thisLine, prevLines) = (B.cons c thisLine, prevLines) finalizeFold (lastLine, otherLines) = lastLine : otherLines cleanFieldString :: String -> String cleanFieldString = filter (\c -> isPrint c && c < '\x80' && c /= ':') darcs-2.14.5/harness/Darcs/Test/HashedStorage.hs0000644000000000000000000005604207346545000017572 0ustar0000000000000000{-# LANGUAGE ScopedTypeVariables, FlexibleInstances #-} module Darcs.Test.HashedStorage( tests ) where import Prelude hiding ( filter, readFile, writeFile, lookup, (<$>) ) import qualified Prelude import qualified Data.ByteString.Lazy.Char8 as BLC import qualified Data.ByteString.Char8 as BC import System.Directory( doesFileExist, removeFile, doesDirectoryExist ) import System.FilePath( () ) import Control.Monad.Identity import Control.Monad.Trans( lift ) import Control.Applicative( (<$>) ) import Codec.Archive.Zip( extractFilesFromArchive, toArchive ) import Data.Maybe import Data.Word import Data.List( sort, intercalate, intersperse ) import Darcs.Util.Path hiding ( setCurrentDirectory ) import Darcs.Util.Lock ( withTempDir ) import Darcs.Util.Tree hiding ( lookup ) import Darcs.Util.Index import Darcs.Util.Tree.Hashed import Darcs.Util.Hash import Darcs.Util.Tree.Monad hiding ( tree, createDirectory ) import Darcs.Util.Tree.Plain import System.Mem( performGC ) import qualified Data.Set as S import Test.HUnit hiding ( path ) import Test.Framework( testGroup ) import qualified Test.Framework as TF ( Test ) import Test.QuickCheck import Test.Framework.Providers.HUnit import Test.Framework.Providers.QuickCheck2 ------------------------ -- Test Data -- blobs :: [(AnchoredPath, BLC.ByteString)] blobs = [ (floatPath "foo_a", BLC.pack "a\n") , (floatPath "foo_dir/foo_a", BLC.pack "a\n") , (floatPath "foo_dir/foo_b", BLC.pack "b\n") , (floatPath "foo_dir/foo_subdir/foo_a", BLC.pack "a\n") , (floatPath "foo space/foo\nnewline", BLC.pack "newline\n") , (floatPath "foo space/foo\\backslash", BLC.pack "backslash\n") , (floatPath "foo space/foo_a", BLC.pack "a\n") ] files :: [AnchoredPath] files = map fst blobs dirs :: [AnchoredPath] dirs = [ floatPath "foo_dir" , floatPath "foo_dir/foo_subdir" , floatPath "foo space" ] emptyStub :: TreeItem IO emptyStub = Stub (return emptyTree) NoHash testTree :: Tree IO testTree = makeTree [ (makeName "foo", emptyStub) , (makeName "subtree", SubTree sub) , (makeName "substub", Stub getsub NoHash) ] where sub = makeTree [ (makeName "stub", emptyStub) , (makeName "substub", Stub getsub2 NoHash) , (makeName "x", SubTree emptyTree) ] getsub = return sub getsub2 = return $ makeTree [ (makeName "file", File emptyBlob) , (makeName "file2", File $ Blob (return $ BLC.pack "foo") NoHash) ] equals_testdata :: Tree IO -> IO () equals_testdata t = sequence_ [ do isJust (findFile t p) @? show p ++ " in tree" ours <- readBlob (fromJust $ findFile t p) ours @?= stored | (p, stored) <- blobs ] >> sequence_ [ isJust (Prelude.lookup p blobs) @? show p ++ " extra in tree" | (p, File _) <- list t ] --------------------------- -- Test list -- tests :: [TF.Test] tests = [ testGroup "Darcs.Util.Hash" hash , testGroup "Darcs.Util.Tree" tree , testGroup "Darcs.Util.Index" index , testGroup "Darcs.Util.Tree.Monad" monad , testGroup "Hashed Storage" hashed ] -------------------------- -- Tests -- hashed :: [TF.Test] hashed = [ testCase "plain has all files" have_files , testCase "pristine has all files" have_pristine_files , testCase "pristine has no extras" pristine_no_extra , testCase "pristine file contents match" pristine_contents , testCase "plain file contents match" plain_contents , testCase "writePlainTree works" write_plain ] where check_file t f = assertBool ("path " ++ show f ++ " is missing in tree " ++ show t) (isJust $ find t f) check_files = forM_ files . check_file pristine_no_extra = extractRepoAndRun $ do t <- readDarcsPristine "." >>= expand forM_ (list t) $ \(path,_) -> assertBool (show path ++ " is extraneous in tree") (path `elem` (dirs ++ files)) have_files = extractRepoAndRun ( readPlainTree "." >>= expand >>= check_files ) have_pristine_files = extractRepoAndRun ( readDarcsPristine "." >>= expand >>= check_files ) pristine_contents = extractRepoAndRun $ do t <- readDarcsPristine "." >>= expand equals_testdata t plain_contents = extractRepoAndRun $ do t <- expand =<< filter nondarcs `fmap` readPlainTree "." equals_testdata t write_plain = extractRepoAndRun $ do orig <- readDarcsPristine "." >>= expand writePlainTree orig "_darcs/plain" t <- expand =<< readPlainTree "_darcs/plain" equals_testdata t index :: [TF.Test] index = [ testCase "index versioning" check_index_versions , testCase "index listing" check_index , testCase "index content" check_index_content , testProperty "xlate32" prop_xlate32 , testProperty "xlate64" prop_xlate64 , testProperty "align bounded" prop_align_bounded , testProperty "align aligned" prop_align_aligned ] where pristine = readDarcsPristine "." >>= expand build_index = do x <- pristine exist <- doesFileExist "_darcs/index" performGC -- required in win32 to trigger file close when exist $ removeFile "_darcs/index" idx <- updateIndex =<< updateIndexFrom "_darcs/index" darcsTreeHash x return (x, idx) check_index = extractRepoAndRun $ do (pris, idx) <- build_index (sort $ map fst $ list idx) @?= (sort $ map fst $ list pris) check_blob_pair p x y = do a <- readBlob x b <- readBlob y assertEqual ("content match on " ++ show p) a b check_index_content = extractRepoAndRun $ do (_, idx) <- build_index plain <- readPlainTree "." x <- sequence $ zipCommonFiles check_blob_pair plain idx assertBool "files match" (length x > 0) check_index_versions = extractRepoAndRun $ do performGC -- required in win32 to trigger file close Prelude.writeFile "_darcs/index" "nonsense index... do not crash!" valid <- indexFormatValid "_darcs/index" assertBool "index format invalid" $ not valid prop_xlate32 x = (xlate32 . xlate32) x == x where _types = x :: Word32 prop_xlate64 x = (xlate64 . xlate64) x == x where _types = x :: Word64 prop_align_bounded (bound, x) = bound > 0 && bound < 1024 && x >= 0 ==> align bound x >= x && align bound x < x + bound where _types = (bound, x) :: (Int, Int) prop_align_aligned (bound, x) = bound > 0 && bound < 1024 && x >= 0 ==> align bound x `rem` bound == 0 where _types = (bound, x) :: (Int, Int) tree :: [TF.Test] tree = [ testCase "modifyTree" check_modify , testCase "complex modifyTree" check_modify_complex , testCase "modifyTree removal" check_modify_remove , testCase "expand" check_expand , testCase "expandPath" check_expand_path , testCase "expandPath of sub" check_expand_path_sub , testCase "diffTrees" check_diffTrees , testCase "diffTrees identical" check_diffTrees_ident , testProperty "expandPath" prop_expandPath , testProperty "shapeEq" prop_shape_eq , testProperty "expandedShapeEq" prop_expanded_shape_eq , testProperty "expand is identity" prop_expand_id , testProperty "filter True is identity" prop_filter_id , testProperty "filter False is empty" prop_filter_empty , testProperty "restrict both ways keeps shape" prop_restrict_shape_commutative , testProperty "restrict is a subtree of both" prop_restrict_subtree , testProperty "overlay keeps shape" prop_overlay_shape , testProperty "overlay is superset of over" prop_overlay_super ] where blob x = File $ Blob (return (BLC.pack x)) (sha256 $ BLC.pack x) name = makeName check_modify = let t = makeTree [(name "foo", blob "bar")] modify = modifyTree t (floatPath "foo") (Just $ blob "bla") in do x <- readBlob $ fromJust $ findFile t (floatPath "foo") y <- readBlob $ fromJust $ findFile modify (floatPath "foo") assertEqual "old version" x (BLC.pack "bar") assertEqual "new version" y (BLC.pack "bla") assertBool "list has foo" $ isJust (Prelude.lookup (floatPath "foo") $ list modify) length (list modify) @?= 1 check_modify_complex = let t = makeTree [ (name "foo", blob "bar") , (name "bar", SubTree t1) ] t1 = makeTree [ (name "foo", blob "bar") ] modify = modifyTree t (floatPath "bar/foo") (Just $ blob "bla") in do foo <- readBlob $ fromJust $ findFile t (floatPath "foo") foo' <- readBlob $ fromJust $ findFile modify (floatPath "foo") bar_foo <- readBlob $ fromJust $ findFile t (floatPath "bar/foo") bar_foo' <- readBlob $ fromJust $ findFile modify (floatPath "bar/foo") assertEqual "old foo" foo (BLC.pack "bar") assertEqual "old bar/foo" bar_foo (BLC.pack "bar") assertEqual "new foo" foo' (BLC.pack "bar") assertEqual "new bar/foo" bar_foo' (BLC.pack "bla") assertBool "list has bar/foo" $ isJust (Prelude.lookup (floatPath "bar/foo") $ list modify) assertBool "list has foo" $ isJust (Prelude.lookup (floatPath "foo") $ list modify) length (list modify) @?= length (list t) check_modify_remove = let t1 = makeTree [(name "foo", blob "bar")] t2 :: Tree Identity = makeTree [ (name "foo", blob "bar") , (name "bar", SubTree t1) ] modify1 = modifyTree t1 (floatPath "foo") Nothing modify2 = modifyTree t2 (floatPath "bar") Nothing file = findFile modify1 (floatPath "foo") subtree = findTree modify2 (floatPath "bar") in do assertBool "file is gone" (isNothing file) assertBool "subtree is gone" (isNothing subtree) no_stubs t = null [ () | (_, Stub _ _) <- list t ] path = floatPath "substub/substub/file" badpath = floatPath "substub/substub/foo" check_expand = do x <- expand testTree assertBool "no stubs in testTree" $ not (no_stubs testTree) assertBool "stubs in expanded tree" $ no_stubs x assertBool "path reachable" $ path `elem` (map fst $ list x) assertBool "badpath not reachable" $ badpath `notElem` (map fst $ list x) check_expand_path = do test_exp <- expand testTree t <- expandPath testTree path t' <- expandPath test_exp path t'' <- expandPath testTree $ floatPath "substub/x" assertBool "path not reachable in testTree" $ path `notElem` (map fst $ list testTree) assertBool "path reachable in t" $ path `elem` (map fst $ list t) assertBool "path reachable in t'" $ path `elem` (map fst $ list t') assertBool "path reachable in t (with findFile)" $ isJust $ findFile t path assertBool "path reachable in t' (with findFile)" $ isJust $ findFile t' path assertBool "path not reachable in t''" $ path `notElem` (map fst $ list t'') assertBool "badpath not reachable in t" $ badpath `notElem` (map fst $ list t) assertBool "badpath not reachable in t'" $ badpath `notElem` (map fst $ list t') check_expand_path_sub = do t <- expandPath testTree $ floatPath "substub" t' <- expandPath testTree $ floatPath "substub/stub" t'' <- expandPath testTree $ floatPath "subtree/stub" assertBool "leaf is not a Stub" $ isNothing (findTree testTree $ floatPath "substub") assertBool "leaf is not a Stub" $ isJust (findTree t $ floatPath "substub") assertBool "leaf is not a Stub (2)" $ isJust (findTree t' $ floatPath "substub/stub") assertBool "leaf is not a Stub (3)" $ isJust (findTree t'' $ floatPath "subtree/stub") check_diffTrees = extractRepoAndRun $ do Prelude.writeFile "foo_dir/foo_a" "b\n" working_plain <- filter nondarcs `fmap` readPlainTree "." working <- updateIndex =<< updateIndexFrom "_darcs/index" darcsTreeHash working_plain pristine <- readDarcsPristine "." (working', pristine') <- diffTrees working pristine let foo_work = findFile working' (floatPath "foo_dir/foo_a") foo_pris = findFile pristine' (floatPath "foo_dir/foo_a") working' `shapeEq` pristine' @? show working' ++ " `shapeEq` " ++ show pristine' assertBool "foo_dir/foo_a is in working'" $ isJust foo_work assertBool "foo_dir/foo_a is in pristine'" $ isJust foo_pris foo_work_c <- readBlob (fromJust foo_work) foo_pris_c <- readBlob (fromJust foo_pris) BLC.unpack foo_work_c @?= "b\n" BLC.unpack foo_pris_c @?= "a\n" assertEqual "working' tree is minimal" 2 (length $ list working') assertEqual "pristine' tree is minimal" 2 (length $ list pristine') check_diffTrees_ident = do pristine <- readDarcsPristine "." (t1, t2) <- diffTrees pristine pristine assertBool "t1 is empty" $ null (list t1) assertBool "t2 is empty" $ null (list t2) prop_shape_eq x = no_stubs x ==> x `shapeEq` x where _types = x :: Tree Identity prop_expanded_shape_eq x = runIdentity $ expandedShapeEq x x where _types = x :: Tree Identity prop_expand_id x = no_stubs x ==> runIdentity (expand x) `shapeEq` x where _types = x :: Tree Identity prop_filter_id x = runIdentity $ expandedShapeEq x $ filter (\_ _ -> True) x where _types = x :: Tree Identity prop_filter_empty x = runIdentity $ expandedShapeEq emptyTree $ filter (\_ _ -> False) x where _types = x :: Tree Identity prop_restrict_shape_commutative (t1, t2) = no_stubs t1 && no_stubs t2 && not (restrict t1 t2 `shapeEq` emptyTree) ==> restrict t1 t2 `shapeEq` restrict t2 t1 where _types = (t1 :: Tree Identity, t2 :: Tree Identity) prop_restrict_subtree (t1, t2) = no_stubs t1 && not (restrict t1 t2 `shapeEq` emptyTree) ==> let restricted = S.fromList (map fst $ list $ restrict t1 t2) orig1 = S.fromList (map fst $ list t1) orig2 = S.fromList (map fst $ list t2) in and [restricted `S.isSubsetOf` orig1, restricted `S.isSubsetOf` orig2] where _types = (t1 :: Tree Identity, t2 :: Tree Identity) prop_overlay_shape (t1 :: Tree Identity, t2) = (Just LT == runIdentity (t2 `cmpExpandedShape` t1)) ==> runIdentity $ (t1 `overlay` t2) `expandedShapeEq` t1 prop_overlay_super (t1 :: Tree Identity, t2) = (Just LT == runIdentity (t2 `cmpExpandedShape` t1)) && no_stubs t2 ==> Just EQ == (runIdentity $ restrict t2 (t1 `overlay` t2) `cmpTree` t2) prop_expandPath (TreeWithPath t p) = notStub $ find (runIdentity $ expandPath t p) p where notStub (Just (Stub _ _)) = False notStub Nothing = error "Did not exist." notStub _ = True hash :: [TF.Test] hash = [ testProperty "decodeBase16 . encodeBase16 == id" prop_base16 ] where prop_base16 x = (decodeBase16 . encodeBase16) x == x monad :: [TF.Test] monad = [ testCase "path expansion" check_virtual , testCase "rename" check_rename ] where check_virtual = virtualTreeMonad run testTree >> return () where run = do file <- readFile (floatPath "substub/substub/file") file2 <- readFile (floatPath "substub/substub/file2") lift $ BLC.unpack file @?= "" lift $ BLC.unpack file2 @?= "foo" check_rename = do (_, t) <- virtualTreeMonad run testTree t' <- darcsAddMissingHashes =<< expand t forM_ [ (p, i) | (p, i) <- list t' ] $ \(p,i) -> assertBool ("have hash: " ++ show p) $ itemHash i /= NoHash where run = do rename (floatPath "substub/substub/file") (floatPath "substub/file2") ---------------------------------- -- Arbitrary instances -- instance Arbitrary BLC.ByteString where arbitrary = BLC.pack `fmap` arbitrary instance Arbitrary Hash where arbitrary = sized hash' where hash' 0 = return NoHash hash' _ = SHA256 . BC.pack <$> sequence [ arbitrary | _ <- [1..32] :: [Int] ] instance (Monad m) => Arbitrary (TreeItem m) where arbitrary = sized tree' where tree' 0 = oneof [ return (File emptyBlob), return (SubTree emptyTree) ] tree' n = oneof [ file n, subtree n ] file 0 = return (File emptyBlob) file _ = do content <- arbitrary return (File $ Blob (return content) NoHash) subtree n = do branches <- choose (1, n) let sub name = do t <- tree' ((n - 1) `div` branches) return (makeName $ show name, t) sublist <- mapM sub [0..branches] oneof [ tree' 0 , return (SubTree $ makeTree sublist) , return $ (Stub $ return (makeTree sublist)) NoHash ] instance (Monad m) => Arbitrary (Tree m) where arbitrary = do item <- arbitrary case item of File _ -> arbitrary Stub _ _ -> arbitrary SubTree t -> return t data TreeWithPath = TreeWithPath (Tree Identity) AnchoredPath deriving (Show) instance Arbitrary TreeWithPath where arbitrary = do t <- arbitrary p <- oneof $ return (AnchoredPath []) : (map (return . fst) $ list (runIdentity $ expand t)) return $ TreeWithPath t p --------------------------- -- Other instances -- instance Show (Blob m) where show (Blob _ h) = "Blob " ++ show h instance Show (TreeItem m) where show (File f) = "File (" ++ show f ++ ")" show (Stub _ h) = "Stub _ " ++ show h show (SubTree s) = "SubTree (" ++ show s ++ ")" instance Show (Tree m) where show t = "Tree " ++ show (treeHash t) ++ " { " ++ (concat . intersperse ", " $ itemstrs) ++ " }" where itemstrs = map show $ listImmediate t instance Show (Int -> Int) where show f = "[" ++ intercalate ", " (map val [1..20]) ++ " ...]" where val x = show x ++ " -> " ++ show (f x) ----------------------- -- Test utilities -- shapeEq :: Tree m -> Tree m -> Bool shapeEq a b = Just EQ == cmpShape a b expandedShapeEq :: (Monad m, Functor m) => Tree m -> Tree m -> m Bool expandedShapeEq a b = (Just EQ ==) <$> cmpExpandedShape a b cmpcat :: [Maybe Ordering] -> Maybe Ordering cmpcat (x:y:rest) | x == y = cmpcat (x:rest) | x == Just EQ = cmpcat (y:rest) | y == Just EQ = cmpcat (x:rest) | otherwise = Nothing cmpcat [x] = x cmpcat [] = Just EQ -- empty things are equal cmpTree :: (Monad m, Functor m) => Tree m -> Tree m -> m (Maybe Ordering) cmpTree x y = do x' <- expand x y' <- expand y con <- contentsEq x' y' return $ cmpcat [cmpShape x' y', con] where contentsEq a b = cmpcat <$> sequence (zipTrees cmp a b) cmp _ (Just (File a)) (Just (File b)) = do a' <- readBlob a b' <- readBlob b return $ Just (compare a' b') cmp _ _ _ = return (Just EQ) -- neutral cmpShape :: Tree m -> Tree m -> Maybe Ordering cmpShape t r = cmpcat $ zipTrees cmp t r where cmp _ (Just a) (Just b) = a `item` b cmp _ Nothing (Just _) = Just LT cmp _ (Just _) Nothing = Just GT cmp _ Nothing Nothing = Just EQ item (File _) (File _) = Just EQ item (SubTree s) (SubTree p) = s `cmpShape` p item _ _ = Nothing cmpExpandedShape :: (Monad m) => Tree m -> Tree m -> m (Maybe Ordering) cmpExpandedShape a b = do x <- expand a y <- expand b return $ x `cmpShape` y nondarcs :: AnchoredPath -> TreeItem m -> Bool nondarcs (AnchoredPath (x:_)) _ | x == makeName "_darcs" = False | otherwise = True nondarcs (AnchoredPath []) _ = True readDarcsPristine :: FilePath -> IO (Tree IO) readDarcsPristine dir = do let darcs = dir "_darcs" h_inventory = darcs "hashed_inventory" repo <- doesDirectoryExist darcs unless repo $ fail $ "Not a darcs repository: " ++ dir isHashed <- doesFileExist h_inventory if isHashed then do inv <- BC.readFile h_inventory let thelines = BC.split '\n' inv case thelines of [] -> return emptyTree (pris_line:_) -> do let thehash = decodeDarcsHash $ BC.drop 9 pris_line thesize = decodeDarcsSize $ BC.drop 9 pris_line when (thehash == NoHash) $ fail $ "Bad pristine root: " ++ show pris_line readDarcsHashed (darcs "pristine.hashed") (thesize, thehash) else do have_pristine <- doesDirectoryExist $ darcs "pristine" have_current <- doesDirectoryExist $ darcs "current" case (have_pristine, have_current) of (True, _) -> readPlainTree $ darcs "pristine" (False, True) -> readPlainTree $ darcs "current" (_, _) -> fail "No pristine tree is available!" extractRepoAndRun :: IO a -> IO a extractRepoAndRun action = do zipFile <- toArchive . BLC.fromStrict <$> BC.readFile "harness/hstestdata.zip" withTempDir "_test_playground" $ \_ -> do extractFilesFromArchive [] zipFile action darcs-2.14.5/harness/Darcs/Test/Misc.hs0000644000000000000000000001251207346545000015736 0ustar0000000000000000-- Copyright (C) 2002-2005,2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Test.Misc ( testSuite ) where import Darcs.Util.ByteString ( unpackPSFromUTF8, fromHex2PS, fromPS2Hex , propHexConversion , prop_unlinesPS_linesPS_left_inverse , prop_linesPS_length , prop_unlinesPS_length , spec_betweenLinesPS , betweenLinesPS ) import Darcs.Util.Diff.Myers ( shiftBoundaries ) import Darcs.Test.Misc.CommandLine ( commandLineTestSuite ) import qualified Darcs.Test.Misc.Encoding as Encoding import qualified Data.ByteString.Char8 as BC ( unpack, pack, last ) import qualified Data.ByteString as B ( ByteString, pack, empty, null ) import Data.Char ( ord ) import Data.Array.Base import Control.Monad.ST import Test.HUnit ( assertBool, assertEqual, assertFailure ) import Test.Framework.Providers.QuickCheck2 ( testProperty ) import Test.Framework.Providers.HUnit ( testCase ) import Test.Framework ( Test, testGroup ) import Test.QuickCheck testSuite :: Test testSuite = testGroup "" [ byteStringUtilsTestSuite , lcsTestSuite , commandLineTestSuite , Encoding.testSuite ] -- ---------------------------------------------------------------------- -- * Darcs.Util.ByteString -- ---------------------------------------------------------------------- byteStringUtilsTestSuite :: Test byteStringUtilsTestSuite = testGroup "Darcs.Util.ByteString" [ testCase "UTF-8 packing and unpacking preserves 'hello world'" (assertBool "" (unpackPSFromUTF8 (BC.pack "hello world") == "hello world")) , testCase "Checking that hex packing and unpacking preserves 'hello world'" (assertEqual "" (BC.unpack (fromHex2PS $ fromPS2Hex $ BC.pack "hello world")) "hello world") , testProperty "Checking that hex conversion works" propHexConversion , testProperty "unlinesPS is left inverse of linesPS" prop_unlinesPS_linesPS_left_inverse , testProperty "linesPS length property" prop_linesPS_length , testProperty "unlinesPS length property" prop_unlinesPS_length , testProperty "betweenLinesPS behaves like its spec" prop_betweenLinesPS ] -- tweak the probabilities in favor of newline characters instance Arbitrary B.ByteString where arbitrary = fmap B.pack $ listOf $ frequency [ (1, return (fromIntegral (ord '\n'))) , (4, arbitrary) ] -- betweenLinesPS and spec_betweenLinesPS are equivalent only -- if certain conditions are met prop_betweenLinesPS :: B.ByteString -> B.ByteString -> B.ByteString -> Property prop_betweenLinesPS start end ps = not (B.null start) && not (B.null end) && (B.null ps || BC.last ps == '\n') ==> betweenLinesPS start end ps == spec_betweenLinesPS start end ps -- ---------------------------------------------------------------------- -- * LCS -- Here are a few quick tests of the shiftBoundaries function. -- ---------------------------------------------------------------------- lcsTestSuite :: Test lcsTestSuite = testGroup "LCS" [ testCase "lcs code" (mapM_ assertFailure showLcsTests) ] showLcsTests :: [String] showLcsTests = concatMap checkKnownShifts knownShifts checkKnownShifts :: ([Int],[Int],String,String,[Int],[Int]) -> [String] checkKnownShifts (ca, cb, sa, sb, ca', cb') = runST ( do ca_arr <- newListArray (0, length ca) $ toBool (0:ca) cb_arr <- newListArray (0, length cb) $ toBool (0:cb) let p_a = listArray (0, length sa) $ B.empty:(toPS sa) p_b = listArray (0, length sb) $ B.empty:(toPS sb) shiftBoundaries ca_arr cb_arr p_a 1 1 shiftBoundaries cb_arr ca_arr p_b 1 1 ca_res <- fmap (fromBool . tail) $ getElems ca_arr cb_res <- fmap (fromBool . tail) $ getElems cb_arr return $ if ca_res == ca' && cb_res == cb' then [] else ["shiftBoundaries failed on "++sa++" and "++sb++" with " ++(show (ca,cb))++" expected "++(show (ca', cb')) ++" got "++(show (ca_res, cb_res))++"\n"]) where toPS = map (\c -> if c == ' ' then B.empty else BC.pack [c]) toBool = map (>0) fromBool = map (\b -> if b then 1 else 0) knownShifts :: [([Int],[Int],String,String,[Int],[Int])] knownShifts = [([0,0,0],[0,1,0,1,0],"aaa","aaaaa", [0,0,0],[0,0,0,1,1]), ([0,1,0],[0,1,1,0],"cd ","c a ", [0,1,0],[0,1,1,0]), ([1,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,1,1,1,1,1,0,0,0], "fg{} if{}","dg{} ih{} if{}", [1,0,0,0,0,0,0,0,0],[1,0,0,0,0,1,1,1,1,1,0,0,0,0]), -- prefer empty line at end ([0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,1,1,1,1,1,0,0,0], "fg{} if{}","fg{} ih{} if{}", [0,0,0,0,0,0,0,0,0],[0,0,0,0,0,1,1,1,1,1,0,0,0,0]), -- prefer empty line at end ([],[1,1],"","aa",[],[1,1]), ([1,1],[],"aa","",[1,1],[])] darcs-2.14.5/harness/Darcs/Test/Misc/0000755000000000000000000000000007346545000015401 5ustar0000000000000000darcs-2.14.5/harness/Darcs/Test/Misc/CommandLine.hs0000644000000000000000000000261107346545000020123 0ustar0000000000000000module Darcs.Test.Misc.CommandLine ( commandLineTestSuite ) where import Test.HUnit ( assertEqual, assertFailure ) import Test.Framework.Providers.HUnit ( testCase ) import Test.Framework ( Test, testGroup ) import Darcs.Util.CommandLine ( parseCmd ) formatTable :: [(Char, String)] formatTable = [('s',""), ('a',""), ('d',"date") ] testParser :: (String, ([String], Bool)) -> Test testParser (s, ok) = testCase ("Parse: " ++ show s) $ case parseCmd formatTable s of Left e -> assertFailure $ "Parser failed with: " ++ show e Right res -> assertEqual ("Parsing: " ++ show s) ok res testCases :: [(String, ([String], Bool))] testCases = [("a b",(["a","b"], False)), ("a b %<",(["a","b"], True)), ("a b %< ",(["a","b"], True)), ("\"arg0 contains spaces \\\"quotes\\\"\" b", (["arg0 contains spaces \"quotes\"","b"],False)), ("a %s %<",(["a",""], True)), ("\"%d\"", (["date"], False)), ("\"d %d\"", (["d date"], False)), ("\\\a", (["\\\a"], False)), ("\"\\\a\"", (["\a"], False)), ("\"/foo:%d\"", (["/foo:date"], False)) ] commandLineTestSuite :: Test commandLineTestSuite = testGroup "Darcs.Util.CommandLine" $ map testParser testCases darcs-2.14.5/harness/Darcs/Test/Misc/Encoding.hs0000644000000000000000000000211207346545000017457 0ustar0000000000000000module Darcs.Test.Misc.Encoding ( testSuite ) where import qualified Data.ByteString as B import Control.Monad import Data.Word import System.IO.Unsafe import Darcs.Util.Encoding import Test.Framework ( Test, testGroup ) import Test.Framework.Providers.QuickCheck2 ( testProperty ) import Test.QuickCheck decodeThenEncode :: B.ByteString -> B.ByteString decodeThenEncode = unsafePerformIO . (decode >=> encode) testSuite :: Test testSuite = testGroup "Darcs.Util.Encoding" [ testProperty "decode then encode roundtrips" propDecodeThenEncodeRoundTrip ] -- could use the bytestring-arbitrary package, -- but the shrinking isn't as effective as 'shrinkList shrink' newtype MyByteString = MBS { _mbsBytes :: [Word8] } deriving Show instance Arbitrary MyByteString where arbitrary = MBS <$> sized (\n -> vectorOf (100*n) arbitrary) shrink (MBS ws) = MBS <$> shrinkList shrink ws toBS :: MyByteString -> B.ByteString toBS (MBS ws) = B.pack ws propDecodeThenEncodeRoundTrip :: MyByteString -> Bool propDecodeThenEncodeRoundTrip mbs = let bstr = toBS mbs in decodeThenEncode bstr == bstr darcs-2.14.5/harness/Darcs/Test/Patch.hs0000644000000000000000000005156107346545000016111 0ustar0000000000000000{-# LANGUAGE AllowAmbiguousTypes #-} -- Copyright (C) 2002-2005,2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Test.Patch ( testSuite ) where import Data.Maybe( isNothing ) import Test.Framework ( Test, testGroup ) import Test.Framework.Providers.HUnit ( testCase ) import Test.Framework.Providers.QuickCheck2 ( testProperty ) import Test.QuickCheck.Arbitrary( Arbitrary ) import Test.QuickCheck( Testable ) import Test.HUnit ( assertBool ) import Darcs.Test.Util.TestResult ( TestResult, isOk, fromMaybe ) import Darcs.Test.Patch.Utils ( testConditional ) import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Witnesses.Eq ( Eq2, unsafeCompare ) import Darcs.Patch.Witnesses.Show import Darcs.Patch.Prim( PrimPatch, coalesce, FromPrim, PrimOf ) import qualified Darcs.Patch.Prim.FileUUID as FileUUID ( Prim ) import Darcs.Patch.RepoPatch ( RepoPatch ) import Darcs.Patch.Type ( PatchType(..) ) import Darcs.Patch.V1 as V1 ( RepoPatchV1 ) import qualified Darcs.Patch.V1.Prim as V1 ( Prim ) import qualified Darcs.Patch.V2.Prim as V2 ( Prim ) import Darcs.Patch.V2.RepoPatch ( isConsistent, isForward, RepoPatchV2 ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Invert ( Invert ) import Darcs.Patch.Merge( Merge ) import Darcs.Patch.Show ( ShowPatchBasic ) import Darcs.Patch.Apply( Apply, ApplyState ) import Darcs.Test.Patch.Arbitrary.Generic import qualified Darcs.Test.Patch.Arbitrary.PrimV1 as P1 import Darcs.Test.Patch.Arbitrary.PrimFileUUID() import Darcs.Test.Patch.Arbitrary.RepoPatchV1 () import Darcs.Test.Patch.Arbitrary.RepoPatchV2 import Darcs.Test.Patch.Arbitrary.PrimV1 () import Darcs.Test.Patch.RepoModel import Darcs.Test.Patch.WithState( WithState, WithStartState ) import qualified Darcs.Test.Patch.Info import qualified Darcs.Test.Patch.Selection import qualified Darcs.Test.Patch.Examples.Set1 as Ex import qualified Darcs.Test.Patch.Examples.Set2Unwitnessed as ExU import Darcs.Test.Patch.Properties.Check( Check(..) ) import qualified Darcs.Test.Patch.Properties.V1Set1 as Prop1 import qualified Darcs.Test.Patch.Properties.V1Set2 as Prop2 import qualified Darcs.Test.Patch.Properties.Generic as PropG import qualified Darcs.Test.Patch.Properties.RepoPatchV2 as PropR import qualified Darcs.Test.Patch.Properties.GenericUnwitnessed as PropU import qualified Darcs.Test.Patch.Rebase as Rebase import qualified Darcs.Test.Patch.WSub as WSub type Prim1 = V1.Prim type Prim2 = V2.Prim newtype TestGenerator thing gen = TestGenerator (forall t ctx . ((forall wXx wYy . thing wXx wYy -> t) -> (gen ctx -> t))) newtype TestCondition thing = TestCondition (forall wYy wZz . thing wYy wZz -> Bool) newtype TestCheck thing t = TestCheck (forall wYy wZz . thing wYy wZz -> t) -- arbitraryThing :: (forall wXx wYy . thing wXx wYy -> t) -> (thing wA wB -> t) arbitraryThing :: x -> TestGenerator thing (thing x) arbitraryThing _ = TestGenerator (\f p -> f p) -- | Run a test function on a set of data, using HUnit. The test function should -- return @Nothing@ upon success and a @Just x@ upon failure. testCases :: Show a => String -- ^ The test name -> (a -> TestResult) -- ^ The test function -> [a] -- ^ The test data -> Test testCases name test datas = testCase name (assertBool assertName res) where assertName = "Boolean assertion for \"" ++ name ++ "\"" res = and $ map (isOk . test) datas unit_V1P1:: [Test] unit_V1P1 = [ testCases "known commutes" Prop1.checkCommute Ex.knownCommutes , testCases "known non-commutes" Prop1.checkCantCommute Ex.knownCantCommutes , testCases "known merges" Prop1.checkMerge Ex.knownMerges , testCases "known merges (equiv)" Prop1.checkMergeEquiv Ex.knownMergeEquivs , testCases "known canons" Prop1.checkCanon Ex.knownCanons , testCases "merge swaps" Prop1.checkMergeSwap Ex.mergePairs2 , testCases "the patch validation works" Prop1.tTestCheck Ex.validPatches , testCases "commute/recommute" (PropG.recommute commute) Ex.commutePairs , testCases "merge properties: merge either way valid" Prop1.tMergeEitherWayValid Ex.mergePairs , testCases "merge properties: merge swap" PropG.mergeEitherWay Ex.mergePairs , testCases "primitive patch IO functions" (Prop1.tShowRead eqFLUnsafe) Ex.primitiveTestPatches , testCases "IO functions (test patches)" (Prop1.tShowRead eqFLUnsafe) Ex.testPatches , testCases "IO functions (named test patches)" (Prop1.tShowRead unsafeCompare) Ex.testPatchesNamed , testCases "primitive commute/recommute" (PropG.recommute commute) Ex.primitiveCommutePairs ] unit_V2P1 :: [Test] unit_V2P1 = [ testCases "coalesce commute" (PropU.coalesceCommute WSub.coalesce) ExU.primPermutables , testCases "prim recommute" (PropU.recommute WSub.commute) ExU.commutables , testCases "prim patch and inverse commute" (PropU.patchAndInverseCommute WSub.commute) ExU.commutables , testCases "prim inverses commute" (PropU.commuteInverses WSub.commute) ExU.commutables , testCases "FL prim recommute" (PropU.recommute WSub.commute) ExU.commutablesFL , testCases "FL prim patch and inverse commute" (PropU.patchAndInverseCommute WSub.commute) ExU.commutablesFL , testCases "FL prim inverses commute" (PropU.commuteInverses WSub.commute) $ ExU.commutablesFL , testCases "fails" (PropU.commuteFails WSub.commute) ([] :: [(Prim2 WSub.:> Prim2) wX wY]) , testCases "read and show work on Prim" PropU.show_read ExU.primPatches , testCases "read and show work on RepoPatchV2" PropU.show_read ExU.repov2Patches , testCases "example flattenings work" PropU.consistentTreeFlattenings ExU.repov2PatchLoopExamples , testCases "V2 merge input consistent" (PropU.mergeArgumentsConsistent isConsistent) ExU.repov2Mergeables , testCases "V2 merge input is forward" (PropU.mergeArgumentsConsistent isForward) ExU.repov2Mergeables , testCases "V2 merge output is forward" (PropU.mergeConsistent isForward) ExU.repov2Mergeables , testCases "V2 merge output consistent" (PropU.mergeConsistent isConsistent) ExU.repov2Mergeables , testCases "V2 merge either way" PropU.mergeEitherWay ExU.repov2Mergeables , testCases "V2 merge and commute" PropU.mergeCommute ExU.repov2Mergeables , testCases "V2 recommute" (PropU.recommute WSub.commute) ExU.repov2Commutables , testCases "V2 inverses commute" (PropU.commuteInverses WSub.commute) ExU.repov2Commutables , testCases "V2 permutivity" (PropU.permutivity WSub.commute) ExU.repov2NonduplicateTriples , testCases "V2 partial permutivity" (PropU.partialPermutivity WSub.commute) ExU.repov2NonduplicateTriples ] qc_prim :: forall prim wX wY wA model. (PrimPatch prim, ArbitraryPrim prim, Show2 prim , model ~ ModelOf prim, RepoModel model , RepoState model ~ ApplyState (PrimOf prim) , Show1 (ModelOf prim) , Check prim, PrimOf prim ~ prim , FromPrim prim , MightBeEmptyHunk prim , MightHaveDuplicate prim , Show1 (prim wA) , Arbitrary (Sealed ((prim :> prim) wA)) , Arbitrary (Sealed ((prim :> prim :> prim) wA)) , Arbitrary (Sealed (prim wA)) , Arbitrary (Sealed (FL prim wA)) , Arbitrary (Sealed ((FL prim :> FL prim) wA)) , Arbitrary (Sealed (WithState model prim wA)) , Arbitrary (Sealed (WithState model (FL prim) wA)) , Arbitrary (Sealed2 (WithState model (prim :> prim))) , Arbitrary (Sealed ((WithState model (prim :> prim)) wA)) , Arbitrary (Sealed ((WithState model (FL prim :> FL prim)) wA)) ) => prim wX wY -> [Test] qc_prim p = -- The following fails because of setpref patches... -- testProperty "prim inverse doesn't commute" (inverseDoesntCommute :: Prim -> Maybe Doc) (if runCoalesceTests p then [ testProperty "prim coalesce effect preserving... " (unseal2 $ PropG.coalesceEffectPreserving coalesce :: Sealed2 (WithState model (prim :> prim)) -> TestResult) ] else []) ++ concat [ pair_properties (undefined :: prim wX wY) "arbitrary" arbitraryThing' , pair_properties (undefined :: FL prim wX wY) "arbitrary FL" arbitraryThing' , coalesce_properties (undefined :: prim wX wY) "arbitrary" arbitraryThing' , nonrpv2_commute_properties (undefined :: prim wX wY) "arbitrary" arbitraryThing' , nonrpv2_commute_properties (undefined :: FL prim wX wY) "arbitrary FL" arbitraryThing' , patch_properties (undefined :: prim wX wA) "arbitrary" arbitraryThing' , patch_properties (undefined :: FL prim wX wA) "arbitrary FL" arbitraryThing' , patch_repo_properties (undefined :: prim wX wA) "arbitrary" arbitraryThing' , patch_repo_properties (undefined :: FL prim wX wA) "arbitrary FL" arbitraryThing' , pair_repo_properties (undefined :: prim wX wA) "arbitrary" arbitraryThing' , pair_repo_properties (undefined :: FL prim wX wA) "arbitrary FL" arbitraryThing' ] where arbitraryThing' = arbitraryThing (undefined :: wA) -- bind the witness for generator consistentV2 :: RepoPatchV2 Prim2 wX wY -> TestResult consistentV2 = fromMaybe . isConsistent commuteRepoPatchV2s :: (RepoPatchV2 Prim2 :> RepoPatchV2 Prim2) wX wY -> Maybe ((RepoPatchV2 Prim2 :> RepoPatchV2 Prim2) wX wY) commuteRepoPatchV2s = commute qc_V2P1 :: [Test] qc_V2P1 = [ testProperty "tree flattenings are consistent... " (PropR.propConsistentTreeFlattenings :: Sealed (WithStartState (ModelOf Prim2) (Tree Prim2)) -> Bool) , testProperty "with quickcheck that RepoPatchV2 patches are consistent... " (unseal $ P1.patchFromTree $ consistentV2) -- permutivity ---------------------------------------------------------------------------- , testConditional "permutivity" (unseal $ P1.commuteTripleFromTree notDuplicatestriple) (unseal $ P1.commuteTripleFromTree $ PropG.permutivity commuteRepoPatchV2s) , testConditional "partial permutivity" (unseal $ P1.commuteTripleFromTree notDuplicatestriple) (unseal $ P1.commuteTripleFromTree $ PropG.partialPermutivity commuteRepoPatchV2s) , testConditional "nontrivial permutivity" (unseal $ P1.commuteTripleFromTree (\t -> nontrivialTriple t && notDuplicatestriple t)) (unseal $ P1.commuteTripleFromTree $ (PropG.permutivity commuteRepoPatchV2s)) ] qc_V2 :: forall prim wXx wYy . (PrimPatch prim, Show1 (ModelOf prim), RepoModel (ModelOf prim), ArbitraryPrim prim, Show2 prim, RepoState (ModelOf prim) ~ ApplyState prim) => prim wXx wYy -> [Test] qc_V2 _ = [ testProperty "readPatch and showPatch work on RepoPatchV2... " (unseal $ patchFromTree $ (PropG.show_read :: RepoPatchV2 prim wX wY -> TestResult)) , testProperty "readPatch and showPatch work on FL RepoPatchV2... " (unseal2 $ (PropG.show_read :: FL (RepoPatchV2 prim) wX wY -> TestResult)) , testProperty "we can do merges using QuickCheck" (isNothing . (PropG.propIsMergeable :: Sealed (WithStartState (ModelOf prim) (Tree prim)) -> Maybe (Tree (RepoPatchV2 prim) wX))) ] ++ concat [ merge_properties (undefined :: RepoPatchV2 prim wX wY) "tree" (TestGenerator mergePairFromTree) , merge_properties (undefined :: RepoPatchV2 prim wX wY) "twfp" (TestGenerator mergePairFromTWFP) , pair_properties (undefined :: RepoPatchV2 prim wX wY) "tree" (TestGenerator commutePairFromTree) , pair_properties (undefined :: RepoPatchV2 prim wX wY) "twfp" (TestGenerator commutePairFromTWFP) , patch_properties (undefined :: RepoPatchV2 prim wX wY) "tree" (TestGenerator patchFromTree) ] properties :: forall thing gen. (Show1 gen, Arbitrary (Sealed gen)) => TestGenerator thing gen -- -> forall xx yy. thing xx yy -> String -> String -> forall t. Testable t => [(String, TestCondition thing, TestCheck thing t)] -> [Test] properties (TestGenerator gen) prefix genname tests = [ cond name condition check | (name, condition, check) <- tests ] where cond :: forall testable. Testable testable => String -> TestCondition thing -> TestCheck thing testable -> Test cond t (TestCondition c) (TestCheck p) = testConditional (prefix ++ " (" ++ genname ++ "): " ++ t) (unseal $ gen c) (unseal $ gen p) type PropList what gen = String -> TestGenerator what gen -> [Test] pair_properties :: forall p gen x y . ( Show1 gen, Arbitrary (Sealed gen), MightHaveDuplicate p , Commute p, Invert p, ShowPatchBasic p, Eq2 p ) => p x y -> PropList (p :> p) gen pair_properties _ genname gen = properties gen "commute" genname [ ("recommute" , TestCondition (const True) , TestCheck (PropG.recommute commute) ) , ("nontrivial recommute" , TestCondition nontrivialCommute, TestCheck (PropG.recommute commute) ) , ("inverses commute" , TestCondition (const True) , TestCheck (PropG.commuteInverses commute) ) , ("nontrivial inverses" , TestCondition nontrivialCommute, TestCheck (PropG.commuteInverses commute) ) , ("inverse composition" , TestCondition (const True) , TestCheck PropG.inverseComposition ) ] coalesce_properties :: forall p gen x y . ( Show1 gen, Arbitrary (Sealed gen), PrimPatch p , ArbitraryPrim p, MightBeEmptyHunk p ) => p x y -> PropList (p :> p :> p) gen coalesce_properties p genname gen = properties gen "commute" genname (if runCoalesceTests p then [ ("coalesce commutes with commute", TestCondition (const True), TestCheck (PropG.coalesceCommute coalesce)) ] else []) -- The following properties do not hold for "RepoPatchV2" patches (conflictors and -- duplicates, specifically) . nonrpv2_commute_properties :: forall p gen x y . (Show1 gen, Arbitrary (Sealed gen), Commute p, Invert p, ShowPatchBasic p, Eq2 p) => p x y -> PropList (p :> p) gen nonrpv2_commute_properties _ genname gen = properties gen "commute" genname [ ("patch & inverse commute", TestCondition (const True) , TestCheck (PropG.patchAndInverseCommute commute)) , ("patch & inverse commute", TestCondition nontrivialCommute, TestCheck (PropG.patchAndInverseCommute commute)) ] patch_properties :: forall p gen x y. (Show1 gen, Arbitrary (Sealed gen), Invert p, Apply p, Eq2 p) => p x y -> PropList p gen patch_properties _ genname gen = properties gen "patch" genname [ ("inverse . inverse is id" , TestCondition (const True) , TestCheck PropG.invertSymmetry) ] patch_repo_properties :: forall p gen x y. (Show1 gen, Arbitrary (Sealed gen), Invert p, Apply p, ShowPatchBasic p, RepoModel (ModelOf (PrimOf p)), RepoState (ModelOf (PrimOf p)) ~ ApplyState p) => p x y -> PropList (WithState (ModelOf (PrimOf p)) p) gen patch_repo_properties _ genname gen = properties gen "patch/repo" genname [ ("invert rollback" , TestCondition (const True) , TestCheck PropG.invertRollback) ] pair_repo_properties :: forall p gen x y. ( Show1 gen , Arbitrary (Sealed gen) , Commute p , Apply p , ShowPatchBasic p , MightBeEmptyHunk p , RepoModel (ModelOf p) , RepoState (ModelOf p) ~ ApplyState p ) => p x y -> PropList (WithState (ModelOf p) (p :> p)) gen pair_repo_properties _ genname gen = properties gen "patch/repo" genname [ ( "commute is effect preserving" , TestCondition (const True) , TestCheck (PropG.effectPreserving commute)) ] merge_properties :: forall p gen x y. (Show1 gen, Arbitrary (Sealed gen) , Invert p, Eq2 p, Merge p, ShowPatchBasic p , MightHaveDuplicate p, Show2 p, Check p) => p x y -> PropList (p :\/: p) gen merge_properties _ genname gen = properties gen "merge" genname [ ("merge either way" , TestCondition (const True) , TestCheck PropG.mergeEitherWay ) , ("merge either way valid" , TestCondition (const True) , TestCheck Prop1.tMergeEitherWayValid) , ("nontrivial merge either way", TestCondition nontrivialMerge, TestCheck PropG.mergeEitherWay ) , ("merge commute" , TestCondition (const True) , TestCheck PropG.mergeCommute ) ] qc_V1P1 :: [Test] qc_V1P1 = [ testProperty "show and read work right" (unseal Prop2.propReadShow) ] ++ Prop2.checkSubcommutes Prop2.subcommutesInverse "patch and inverse both commute" ++ Prop2.checkSubcommutes Prop2.subcommutesNontrivialInverse "nontrivial commutes are correct" ++ Prop2.checkSubcommutes Prop2.subcommutesFailure "inverses fail" ++ [ testProperty "commuting by patch and its inverse is ok" Prop2.propCommuteInverse -- , testProperty "conflict resolution is valid... " Prop.propResolveConflictsValid , testProperty "a patch followed by its inverse is identity" Prop2.propPatchAndInverseIsIdentity , testProperty "'simple smart merge'" Prop2.propSimpleSmartMergeGoodEnough , testProperty "commutes are equivalent" Prop2.propCommuteEquivalency , testProperty "merges are valid" Prop2.propMergeValid , testProperty "inverses being valid" Prop2.propInverseValid , testProperty "other inverse being valid" Prop2.propOtherInverseValid -- The patch generator isn't smart enough to generate correct test cases for -- the following: (which will be obsoleted soon, anyhow) -- , testProperty "the order dependence of unravel... " Prop.propUnravelOrderIndependent -- , testProperty "the unravelling of three merges... " Prop.propUnravelThreeMerge -- , testProperty "the unravelling of a merge of a sequence... " Prop.propUnravelSeqMerge , testProperty "the order of commutes" Prop2.propCommuteEitherOrder , testProperty "commute either way" Prop2.propCommuteEitherWay , testProperty "the double commute" Prop2.propCommuteTwice , testProperty "merges commute and are well behaved" Prop2.propMergeIsCommutableAndCorrect , testProperty "merges can be swapped" Prop2.propMergeIsSwapable , testProperty "again that merges can be swapped (I'm paranoid) " Prop2.propMergeIsSwapable ] -- the following properties are disabled, because they routinely lead to -- exponential cases, making the tests run for ever and ever; nevertheless, -- we would expect them to hold {- ++ merge_properties (undefined :: V1.RepoPatchV1 Prim1 wX wY) "tree" mergePairFromTree ++ merge_properties (undefined :: V1.RepoPatchV1 Prim1 wX wY) "twfp" mergePairFromTWFP ++ commute_properties (undefined :: V1.RepoPatchV1 Prim1 wX wY) "tree" commutePairFromTree ++ commute_properties (undefined :: V1.RepoPatchV1 Prim1 wX wY) "twfp" commutePairFromTWFP -} -- tests (either QuickCheck or Unit) that should be run on any type of patch general_patchTests :: (RepoPatch p, ArbitraryPrim (PrimOf p), Show2 (PrimOf p)) => PatchType rt p -> [Test] general_patchTests pt = [ testGroup "Rebase patches" $ Rebase.testSuite pt ] -- | This is the big list of tests that will be run using testrunner. testSuite :: [Test] testSuite = [ testGroup "Darcs.Patch.Prim.V1 for V1" $ qc_prim (undefined :: Prim1 wX wY) -- testing both Prim1 and Prim2 here is redundant, since they differ -- only in their read/show behavior, which is not tested in qc_prim; -- we still include them because such tests might be added in the future , testGroup "Darcs.Patch.Prim.V1 for V2" $ qc_prim (undefined :: Prim2 wX wY) , testGroup "Darcs.Patch.Prim.FileUUID" $ qc_prim (undefined :: FileUUID.Prim wX wY) , testGroup "Darcs.Patch.V1 (using Prim.V1)" $ unit_V1P1 ++ qc_V1P1 ++ general_patchTests (PatchType :: PatchType rt (V1.RepoPatchV1 Prim1)) , testGroup "Darcs.Patch.V2 (using Prim.V1)" $ unit_V2P1 ++ qc_V2 (undefined :: Prim2 wX wY) ++ qc_V2P1 ++ general_patchTests (PatchType :: PatchType rt (RepoPatchV2 Prim2)) , testGroup "Darcs.Patch.V2 (using Prim.FileUUID)" $ qc_V2 (undefined :: FileUUID.Prim wX wY) ++ general_patchTests (PatchType :: PatchType rt (RepoPatchV2 FileUUID.Prim)) , Darcs.Test.Patch.Info.testSuite , Darcs.Test.Patch.Selection.testSuite ] darcs-2.14.5/harness/Darcs/Test/Patch/Arbitrary/0000755000000000000000000000000007346545000017504 5ustar0000000000000000darcs-2.14.5/harness/Darcs/Test/Patch/Arbitrary/Generic.hs0000644000000000000000000002752307346545000021425 0ustar0000000000000000{-# LANGUAGE UndecidableInstances, ScopedTypeVariables, MultiParamTypeClasses, FlexibleInstances, ViewPatterns #-} module Darcs.Test.Patch.Arbitrary.Generic ( Tree(..), TreeWithFlattenPos(..), G2(..), ArbitraryPrim(..), NullPatch(..), RepoModel(..) , MightBeEmptyHunk(..), MightHaveDuplicate(..) , flattenOne, flattenTree, mapTree, sizeTree , commutePairFromTree, mergePairFromTree , commuteTripleFromTree, mergePairFromCommutePair , commutePairFromTWFP, mergePairFromTWFP, getPairs, getTriples , patchFromTree , canonizeTree , quickCheck ) where import Control.Monad ( liftM ) import Test.QuickCheck import Darcs.Test.Patch.WithState import Darcs.Test.Patch.RepoModel import Darcs.Test.Util.QuickCheck ( bSized ) import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Witnesses.Eq import Darcs.Patch.Witnesses.Unsafe import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Merge ( Merge(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Prim ( PrimOf, PrimPatch, PrimPatchBase, FromPrim(..), PrimConstruct( anIdentity ) ) import Darcs.Patch.V2 ( RepoPatchV2 ) -- XXX this is more or less a hack --import Darcs.ColorPrinter ( errorDoc ) --import Darcs.ColorPrinter ( traceDoc ) import Darcs.Patch.Witnesses.Show --import Darcs.Util.Printer ( greenText, ($$) ) -- | Generate a patch to a certain state. class ArbitraryStateIn s p where arbitraryStateIn :: s wX -> Gen (p wX) data Tree p wX where NilTree :: Tree p wX SeqTree :: p wX wY -> Tree p wY -> Tree p wX ParTree :: Tree p wX -> Tree p wX -> Tree p wX mapTree :: (forall wY wZ . p wY wZ -> q wY wZ) -> Tree p wX -> Tree q wX mapTree _ NilTree = NilTree mapTree f (SeqTree p t) = SeqTree (f p) (mapTree f t) mapTree f (ParTree t1 t2) = ParTree (mapTree f t1) (mapTree f t2) instance Show2 p => Show (Tree p wX) where showsPrec _ NilTree = showString "NilTree" showsPrec d (SeqTree a t) = showParen (d > appPrec) $ showString "SeqTree " . showsPrec2 (appPrec + 1) a . showString " " . showsPrec (appPrec + 1) t showsPrec d (ParTree t1 t2) = showParen (d > appPrec) $ showString "ParTree " . showsPrec (appPrec + 1) t1 . showString " " . showsPrec (appPrec + 1) t2 instance Show2 p => Show1 (Tree p) where showDict1 = ShowDictClass instance Show2 p => Show1 (TreeWithFlattenPos p) where showDict1 = ShowDictClass sizeTree :: Tree p wX -> Int sizeTree NilTree = 0 sizeTree (SeqTree _ t) = 1 + sizeTree t sizeTree (ParTree t1 t2) = 1 + sizeTree t1 + sizeTree t2 -- newtype G1 l p wX = G1 { _unG1 :: l (p wX) } newtype G2 l p wX wY = G2 { unG2 :: l (p wX wY) } flattenTree :: (Merge p) => Tree p wZ -> Sealed (G2 [] (FL p) wZ) flattenTree NilTree = seal $ G2 $ return NilFL flattenTree (SeqTree p t) = mapSeal (G2 . map (p :>:) . unG2) $ flattenTree t flattenTree (ParTree (flattenTree -> Sealed gpss1) (flattenTree -> Sealed gpss2)) = seal $ G2 $ do ps1 <- unG2 gpss1 ps2 <- unG2 gpss2 ps2' :/\: ps1' <- return $ merge (ps1 :\/: ps2) -- We can't prove that the existential type in the result -- of merge will be the same for each pair of -- ps1 and ps2. map unsafeCoerceP [ps1 +>+ ps2', ps2 +>+ ps1'] instance ArbitraryState s p => ArbitraryStateIn s (Tree p) where -- Don't generate trees deeper than 6 with default QuickCheck size (0..99). -- Note if we don't put a non-zero lower bound the first generated trees will always have depth 0. arbitraryStateIn rm = bSized 3 0.035 9 $ \depth -> arbitraryTree rm depth -- | Generate a tree of patches, bounded by the depth @maxDepth@. arbitraryTree :: ArbitraryState s p => s wX -> Int -> Gen (Tree p wX) arbitraryTree rm depth | depth == 0 = return NilTree -- Note a probability of N for NilTree would imply ~(100*N)% of empty trees. -- For the purpose of this module empty trees are useless, but even when -- NilTree case is omitted there is still a small percentage of empty trees -- due to the generation of null-patches (empty-hunks) and the use of canonizeTree. | otherwise = frequency [(1, do Sealed (WithEndState p rm') <- arbitraryState rm t <- arbitraryTree rm' (depth - 1) return (SeqTree p t)) ,(3, do t1 <- arbitraryTree rm (depth - 1) t2 <- arbitraryTree rm (depth - 1) return (ParTree t1 t2))] class NullPatch p where nullPatch :: p wX wY -> EqCheck wX wY class MightBeEmptyHunk p where -- |V1 Prims support the value 'Hunk n [] []' that is treated specially in the -- commute code and ends up breaking certain tests by behaving anomalously. -- In practice they shouldn't appear in real repositories. For later, -- as yet unreleased patch types, we should eliminate them completely. -- An alternative to using this as a guard might be to avoid generating them. isEmptyHunk :: p wX wY -> Bool isEmptyHunk _ = False instance MightBeEmptyHunk (FL p) class MightHaveDuplicate p where -- |"duplicates" in V2 patches (RepoPatchV2) have lots of bugs -- that break various commute/merge properties. hasDuplicate :: p wX wY -> Bool hasDuplicate _ = False instance MightHaveDuplicate p => MightHaveDuplicate (FL p) where hasDuplicate NilFL = False hasDuplicate (p :>: ps) = hasDuplicate p || hasDuplicate ps class ( ArbitraryState (ModelOf prim) prim , NullPatch prim , PrimPatch prim , RepoModel (ModelOf prim) ) => ArbitraryPrim prim where -- hooks to disable certain kinds of tests for certain kinds of patches runCoalesceTests :: prim wX wY -> Bool runCoalesceTests _ = True hasPrimConstruct :: prim wX wY -> Bool hasPrimConstruct _ = True -- canonize a tree, removing any dead branches canonizeTree :: NullPatch p => Tree p wX -> Tree p wX canonizeTree NilTree = NilTree canonizeTree (ParTree t1 t2) | NilTree <- canonizeTree t1 = canonizeTree t2 | NilTree <- canonizeTree t2 = canonizeTree t1 | otherwise = ParTree (canonizeTree t1) (canonizeTree t2) canonizeTree (SeqTree p t) | IsEq <- nullPatch p = canonizeTree t | otherwise = SeqTree p (canonizeTree t) instance (RepoModel model, ArbitraryPrim prim, model ~ ModelOf prim, ArbitraryState model prim) => Arbitrary (Sealed (WithStartState model (Tree prim))) where arbitrary = do repo <- aSmallRepo Sealed (WithStartState rm tree) <- liftM (seal . WithStartState repo) (arbitraryStateIn repo) return $ Sealed $ WithStartState rm (canonizeTree tree) flattenOne :: (FromPrim p, Merge p) => Tree (PrimOf p) wX -> Sealed (FL p wX) flattenOne NilTree = seal NilFL flattenOne (SeqTree p (flattenOne -> Sealed ps)) = seal (fromPrim p :>: ps) flattenOne (ParTree (flattenOne -> Sealed ps1) (flattenOne -> Sealed ps2)) = --traceDoc (greenText "flattening two parallel series: ps1" $$ showPatch ps1 $$ -- greenText "ps2" $$ showPatch ps2) $ case merge (ps1 :\/: ps2) of ps2' :/\: _ -> seal (ps1 +>+ ps2') data TreeWithFlattenPos p wX = TWFP Int (Tree p wX) commutePairFromTWFP :: (FromPrim p, Merge p, PrimPatchBase p) => (forall wY wZ . (p :> p) wY wZ -> t) -> (WithStartState model (TreeWithFlattenPos (PrimOf p)) wX -> t) commutePairFromTWFP handlePair (WithStartState _ (TWFP n t)) = unseal2 handlePair $ let xs = unseal getPairs (flattenOne t) in if length xs > n && n >= 0 then xs!!n else seal2 (fromPrim anIdentity :> fromPrim anIdentity) commutePairFromTree :: (FromPrim p, Merge p, PrimPatchBase p) => (forall wY wZ . (p :> p) wY wZ -> t) -> (WithStartState model (Tree (PrimOf p)) wX -> t) commutePairFromTree handlePair (WithStartState _ t) = unseal2 handlePair $ case flattenOne t of Sealed ps -> let xs = --traceDoc (greenText "I'm flattening one to get:" $$ showPatch ps) $ getPairs ps in if null xs then seal2 (fromPrim anIdentity :> fromPrim anIdentity) else last xs commuteTripleFromTree :: (FromPrim p, Merge p, PrimPatchBase p) => (forall wY wZ . (p :> p :> p) wY wZ -> t) -> (WithStartState model (Tree (PrimOf p)) wX -> t) commuteTripleFromTree handle (WithStartState _ t) = unseal2 handle $ case flattenOne t of Sealed ps -> let xs = --traceDoc (greenText "I'm flattening one to get:" $$ showPatch ps) $ getTriples ps in if null xs then seal2 (fromPrim anIdentity :> fromPrim anIdentity :> fromPrim anIdentity) else last xs mergePairFromCommutePair :: (Commute p, Invert p) => (forall wY wZ . (p :\/: p) wY wZ -> t) -> (forall wY wZ . (p :> p) wY wZ -> t) mergePairFromCommutePair handlePair (a :> b) = case commute (a :> b) of Just (b' :> _) -> handlePair (a :\/: b') Nothing -> handlePair (b :\/: b) -- impredicativity problems mean we can't use (.) in the definitions below mergePairFromTWFP :: (FromPrim p, Merge p, Invert p, PrimPatchBase p) => (forall wY wZ . (p :\/: p) wY wZ -> t) -> (WithStartState model (TreeWithFlattenPos (PrimOf p)) wX -> t) mergePairFromTWFP x = commutePairFromTWFP (mergePairFromCommutePair x) mergePairFromTree :: (FromPrim p, Merge p, Invert p, PrimPatchBase p) => (forall wY wZ . (p :\/: p) wY wZ -> t) -> (WithStartState model (Tree (PrimOf p)) wX -> t) mergePairFromTree x = commutePairFromTree (mergePairFromCommutePair x) patchFromCommutePair :: (Commute p, Invert p) => (forall wY wZ . p wY wZ -> t) -> (forall wY wZ . (p :> p) wY wZ -> t) patchFromCommutePair handle (_ :> b) = handle b patchFromTree :: (FromPrim p, Merge p, Invert p, PrimPatchBase p) => (forall wY wZ . p wY wZ -> t) -> (WithStartState model (Tree (PrimOf p)) wX -> t) patchFromTree x = commutePairFromTree (patchFromCommutePair x) instance Show2 p => Show (TreeWithFlattenPos p wX) where showsPrec d (TWFP n t) = showParen (d > appPrec) $ showString "TWFP " . showsPrec (appPrec + 1) n . showString " " . showsPrec1 (appPrec + 1) t getPairs :: FL p wX wY -> [Sealed2 (p :> p)] getPairs NilFL = [] getPairs (_:>:NilFL) = [] getPairs (a:>:b:>:c) = seal2 (a:>b) : getPairs (b:>:c) getTriples :: FL p wX wY -> [Sealed2 (p :> p :> p)] getTriples NilFL = [] getTriples (_:>:NilFL) = [] getTriples (_:>:_:>:NilFL) = [] getTriples (a:>:b:>:c:>:d) = seal2 (a:>b:>c) : getTriples (b:>:c:>:d) instance (ArbitraryPrim prim, RepoModel (ModelOf prim), model ~ ModelOf prim, ArbitraryState model prim) => Arbitrary (Sealed (WithStartState model (TreeWithFlattenPos prim))) where arbitrary = do Sealed (WithStartState rm t) <- arbitrary let num = unseal (length . getPairs) (flattenOneRP t) if num == 0 then return $ Sealed $ WithStartState rm $ TWFP 0 NilTree else do n <- choose (0, num - 1) return $ Sealed $ WithStartState rm $ TWFP n t where -- just used to get the length. In principle this should be independent of the patch type. flattenOneRP :: Tree prim wX -> Sealed (FL (RepoPatchV2 prim) wX) flattenOneRP = flattenOne darcs-2.14.5/harness/Darcs/Test/Patch/Arbitrary/PrimFileUUID.hs0000644000000000000000000002270007346545000022237 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses, OverloadedStrings #-} module Darcs.Test.Patch.Arbitrary.PrimFileUUID where import Prelude () import Darcs.Prelude import qualified Darcs.Test.Patch.Arbitrary.Generic as T ( commuteTripleFromTree, commutePairFromTree, commutePairFromTWFP , mergePairFromTree, mergePairFromTWFP , patchFromTree ) import Darcs.Test.Patch.Arbitrary.Generic import Darcs.Test.Patch.RepoModel import Control.Monad ( liftM ) import Test.QuickCheck import Darcs.Test.Patch.WithState import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Witnesses.Eq import Darcs.Patch.Witnesses.Unsafe import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Prim.FileUUID () import Darcs.Patch.Prim.FileUUID.Core ( Prim(..), Location(..), Hunk(..), UUID(..) ) import Darcs.Patch.RepoPatch ( RepoPatch ) import Darcs.Test.Patch.FileUUIDModel import Darcs.Test.Util.QuickCheck ( notIn, maybeOf ) import Darcs.Patch.Prim import qualified Data.ByteString as B import Data.Maybe ( fromJust, isJust ) import qualified Data.Map as M import Darcs.Util.Hash( Hash(..) ) patchFromTree :: (RepoPatch p, PrimOf p ~ Prim) => (forall wY wZ . p wY wZ -> t) -> WithStartState FileUUIDModel (Tree Prim) wX -> t patchFromTree = T.patchFromTree mergePairFromTree :: (RepoPatch p, PrimOf p ~ Prim) => (forall wY wZ . (p :\/: p) wY wZ -> t) -> WithStartState FileUUIDModel (Tree Prim) wX -> t mergePairFromTree = T.mergePairFromTree mergePairFromTWFP :: (RepoPatch p, PrimOf p ~ Prim) => (forall wY wZ . (p :\/: p) wY wZ -> t) -> WithStartState FileUUIDModel (TreeWithFlattenPos Prim) wX -> t mergePairFromTWFP = T.mergePairFromTWFP commutePairFromTWFP :: (RepoPatch p, PrimOf p ~ Prim) => (forall wY wZ . (p :> p) wY wZ -> t) -> WithStartState FileUUIDModel (TreeWithFlattenPos Prim) wX -> t commutePairFromTWFP = T.commutePairFromTWFP commutePairFromTree :: (RepoPatch p, PrimOf p ~ Prim) => (forall wY wZ . (p :> p) wY wZ -> t) -> WithStartState FileUUIDModel (Tree Prim) wX -> t commutePairFromTree = T.commutePairFromTree commuteTripleFromTree :: (RepoPatch p, PrimOf p ~ Prim) => (forall wY wZ . (p :> p :> p) wY wZ -> t) -> WithStartState FileUUIDModel (Tree Prim) wX -> t commuteTripleFromTree = T.commuteTripleFromTree type instance ModelOf Prim = FileUUIDModel instance ArbitraryPrim Prim where runCoalesceTests _ = False hasPrimConstruct _ = False instance MightBeEmptyHunk Prim instance MightHaveDuplicate Prim instance NullPatch Prim where nullPatch Identity = IsEq nullPatch (Hunk _ (H _ old new)) | old == new = unsafeCoerceP IsEq nullPatch _ = NotEq -- instance Show1 (TreeWithFlattenPos Prim) where -- showDict1 = ShowDictClass -- WithState and propFail are handy for debugging arbitrary code propFail :: Int -> Tree Prim wX -> Bool propFail n xs = sizeTree xs < n ---------------------------------------------------------------------- -- * QuickCheck generators aHunk :: B.ByteString -> Gen (Hunk wX wY) aHunk content = do pos <- choose (0, B.length content) oldLen <- choose (0, B.length content - pos) new <- scale (`div` 8) aContent let old = B.take oldLen $ B.drop pos $ content return $ H pos old new aTextHunk :: (UUID, Object Fail) -> Gen (Prim wX wY) aTextHunk (uuid, (Blob text _)) = do h <- aHunk (unFail text) return $ Hunk uuid h aTextHunk _ = impossible aManifest :: UUID -> (UUID, Object Fail) -> Gen (Prim wX wY) aManifest uuid (dirId, Directory dir) = do filename <- aFilename `notIn` (M.keys dir) return $ Manifest uuid (L dirId filename) aManifest _ _ = impossible aDemanifest :: UUID -> Location -> Gen (Prim wX wY) aDemanifest uuid loc = return $ Demanifest uuid loc -- | Generates any type of 'Prim' patch, except binary and setpref patches. aPrim :: FileUUIDModel wX -> Gen (WithEndState FileUUIDModel (Prim wX) wY) aPrim repo = do mbFile <- maybeOf repoFiles -- some file, not necessarily manifested dir <- elements repoDirs -- some directory, not necessarily manifested -- note, the root directory always exists and is never manifested nor demanifested mbDemanifested <- maybeOf notManifested -- something manifested mbManifested <- maybeOf manifested -- something not manifested fresh <- anUUID `notIn` repoIds repo -- a fresh uuid let whenjust m x = if isJust m then x else 0 whenfile = whenjust mbFile whendemanifested = whenjust mbDemanifested whenmanifested = whenjust mbManifested patch <- frequency [ ( whenfile 12, aTextHunk $ fromJust mbFile ) -- edit an existing file , ( 2, aTextHunk (fresh, Blob (return "") NoHash) ) -- edit a new file , ( whendemanifested 2 -- manifest an existing object , aManifest (fromJust mbDemanifested) dir ) , ( whenmanifested 2 , uncurry aDemanifest $ fromJust mbManifested ) ] let repo' = unFail $ repoApply repo patch return $ WithEndState patch repo' where manifested = [ (uuid, (L dirid name)) | (dirid, Directory dir) <- repoDirs , (name, uuid) <- M.toList dir ] notManifested = [ uuid | (uuid, _) <- nonRootObjects , not (uuid `elem` map fst manifested) ] repoFiles = [ (uuid, Blob x y) | (uuid, Blob x y) <- repoObjects repo ] repoDirs = [ (uuid, Directory x) | (uuid, Directory x) <- repoObjects repo ] nonRootObjects = filter notRoot $ repoObjects repo where notRoot (uuid, _) = uuid == rootId ---------------------------------------------------------------------- -- *** Pairs of primitive patches -- Try to generate commutable pairs of hunks hunkPair :: (UUID, Object Fail) -> Gen ((Prim :> Prim) wX wY) hunkPair (uuid, (Blob file _)) = do h1@(H off1 old1 new1) <- aHunk (unFail file) (delta, content') <- selectChunk h1 (unFail file) H off2' old2 new2 <- aHunk content' let off2 = off2' + delta return (Hunk uuid (H off1 old1 new1) :> Hunk uuid (H off2 old2 new2)) where selectChunk (H off old new) content = elements [prefix, suffix] where prefix = (0, B.take off content) suffix = (off + B.length new, B.drop (off + B.length old) content) hunkPair _ = impossible aPrimPair :: FileUUIDModel wX -> Gen (WithEndState FileUUIDModel ((Prim :> Prim) wX) wY) aPrimPair repo = do mbFile <- maybeOf repoFiles frequency [ ( if isJust mbFile then 1 else 0 , do p1 :> p2 <- hunkPair $ fromJust mbFile let repo' = unFail $ repoApply repo p1 repo'' = unFail $ repoApply repo' p2 return $ WithEndState (p1 :> p2) repo'' ) , ( 1 , do Sealed wesP <- arbitraryState repo return $ unsafeCoerceP1 wesP ) ] where repoFiles = [ (uuid, Blob x y) | (uuid, Blob x y) <- repoObjects repo ] ---------------------------------------------------------------------- -- Arbitrary instances ourSmallRepo :: Gen (FileUUIDModel wX) ourSmallRepo = aSmallRepo instance ArbitraryState FileUUIDModel Prim where arbitraryState s = seal <$> aPrim s instance Arbitrary (Sealed2 (FL (WithState FileUUIDModel Prim))) where arbitrary = do repo <- ourSmallRepo liftM (unseal (seal2 . wesPatch)) $ arbitraryState repo instance Arbitrary (Sealed2 Prim) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed (Prim x)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 (Prim :> Prim)) where arbitrary = do repo <- ourSmallRepo WithEndState pp _ <- aPrimPair repo return $ seal2 pp instance Arbitrary (Sealed ((Prim :> Prim) wA)) where arbitrary = do repo <- ourSmallRepo WithEndState pp _ <- aPrimPair repo return $ seal pp instance Arbitrary (Sealed2 (Prim :> Prim :> Prim)) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed ((Prim :> Prim :> Prim) a)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 (FL Prim)) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed ((FL Prim) wA)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 (FL Prim :> FL Prim)) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed ((FL Prim :> FL Prim) wA)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 (WithState FileUUIDModel Prim)) where arbitrary = makeWS2Gen ourSmallRepo instance Arbitrary (Sealed (WithState FileUUIDModel Prim wA)) where arbitrary = makeWSGen ourSmallRepo instance Arbitrary (Sealed (WithState FileUUIDModel (FL Prim) wA)) where arbitrary = makeWSGen ourSmallRepo instance Arbitrary (Sealed2 (WithState FileUUIDModel (Prim :> Prim))) where arbitrary = do repo <- ourSmallRepo WithEndState pp repo' <- aPrimPair repo return $ seal2 $ WithState repo pp repo' instance Arbitrary (Sealed (WithState FileUUIDModel (Prim :> Prim) a)) where arbitrary = do repo <- ourSmallRepo WithEndState pp repo' <- aPrimPair repo return $ seal $ WithState repo pp repo' instance Arbitrary (Sealed2 (WithState FileUUIDModel (FL Prim))) where arbitrary = makeWS2Gen ourSmallRepo instance Arbitrary (Sealed2 (WithState FileUUIDModel (FL Prim :> FL Prim))) where arbitrary = makeWS2Gen ourSmallRepo instance Arbitrary (Sealed (WithState FileUUIDModel (FL Prim :> FL Prim) a)) where arbitrary = makeWSGen ourSmallRepo darcs-2.14.5/harness/Darcs/Test/Patch/Arbitrary/PrimV1.hs0000644000000000000000000004225607346545000021167 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses #-} module Darcs.Test.Patch.Arbitrary.PrimV1 where import qualified Darcs.Test.Patch.Arbitrary.Generic as T ( commuteTripleFromTree, commutePairFromTree, commutePairFromTWFP , mergePairFromTree, mergePairFromTWFP , patchFromTree ) import Prelude () import Darcs.Prelude import Darcs.Test.Patch.Arbitrary.Generic import Darcs.Test.Patch.RepoModel import Control.Monad ( liftM ) import Test.QuickCheck import Darcs.Test.Patch.WithState import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Witnesses.Eq import Darcs.Patch.Witnesses.Unsafe import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Prim.V1.Core ( FilePatchType( Hunk ), isIdentity ) import qualified Darcs.Patch.Prim.V1.Core as Prim ( Prim( FP ) ) import qualified Darcs.Patch.V1.Prim as V1 ( Prim(..) ) import qualified Darcs.Patch.V2.Prim as V2 ( Prim(..) ) import Darcs.Patch.RepoPatch ( RepoPatch ) import Darcs.Patch.FileHunk( IsHunk( isHunk ), FileHunk(..) ) import Darcs.Test.Patch.V1Model import Darcs.Util.Path import qualified Darcs.Util.Tree as UT ( Tree ) import Darcs.Test.Util.QuickCheck ( alpha, notIn, maybeOf ) import Darcs.UI.Commands.Replace ( defaultToks ) import Darcs.Patch.Prim import Darcs.Patch.Apply ( ApplyState ) import qualified Data.ByteString.Char8 as BC import Data.Maybe ( fromJust, isJust ) type Prim1 = V1.Prim type Prim2 = V2.Prim patchFromTree :: (RepoPatch p, PrimOf p ~ prim) => (forall wY wZ . p wY wZ -> t) -> WithStartState V1Model (Tree prim) wX -> t patchFromTree = T.patchFromTree mergePairFromTree :: (RepoPatch p, PrimOf p ~ prim) => (forall wY wZ . (p :\/: p) wY wZ -> t) -> WithStartState V1Model (Tree prim) wX -> t mergePairFromTree = T.mergePairFromTree mergePairFromTWFP :: (RepoPatch p, PrimOf p ~ prim) => (forall wY wZ . (p :\/: p) wY wZ -> t) -> WithStartState V1Model (TreeWithFlattenPos prim) wX -> t mergePairFromTWFP = T.mergePairFromTWFP commutePairFromTWFP :: (RepoPatch p, PrimOf p ~ prim) => (forall wY wZ . (p :> p) wY wZ -> t) -> WithStartState V1Model (TreeWithFlattenPos prim) wX -> t commutePairFromTWFP = T.commutePairFromTWFP commutePairFromTree :: (RepoPatch p, PrimOf p ~ prim) => (forall wY wZ . (p :> p) wY wZ -> t) -> WithStartState V1Model (Tree prim) wX -> t commutePairFromTree = T.commutePairFromTree commuteTripleFromTree :: (RepoPatch p, PrimOf p ~ prim) => (forall wY wZ . (p :> p :> p) wY wZ -> t) -> WithStartState V1Model (Tree prim) wX -> t commuteTripleFromTree = T.commuteTripleFromTree nonEmptyHunk :: (IsHunk p) => p wX wY -> Bool nonEmptyHunk p | Just (FileHunk _ _ [] []) <- isHunk p = False | otherwise = True nonEmptyHunksPair :: (IsHunk p) => (p :> p) wX wY -> Bool nonEmptyHunksPair (p1 :> p2) = nonEmptyHunk p1 && nonEmptyHunk p2 nonEmptyHunksTriple :: (IsHunk p) => (p :> p :> p) wX wY -> Bool nonEmptyHunksTriple (p1 :> p2 :> p3) = nonEmptyHunk p1 && nonEmptyHunk p2 && nonEmptyHunk p3 nonEmptyHunksFLPair :: (IsHunk p) => (FL p :> FL p) wX wY -> Bool nonEmptyHunksFLPair (ps :> qs) = allFL nonEmptyHunk ps && allFL nonEmptyHunk qs type instance ModelOf Prim1 = V1Model type instance ModelOf Prim2 = V1Model instance ArbitraryPrim Prim1 instance ArbitraryPrim Prim2 instance NullPatch Prim2 where nullPatch (V2.Prim (Prim.FP _ fp)) = nullPatch fp nullPatch p | IsEq <- isIdentity (V2.unPrim p) = IsEq nullPatch _ = NotEq instance NullPatch Prim1 where nullPatch (V1.Prim (Prim.FP _ fp)) = nullPatch fp nullPatch p | IsEq <- isIdentity (V1.unPrim p) = IsEq nullPatch _ = NotEq instance NullPatch FilePatchType where nullPatch (Hunk _ [] []) = unsafeCoerceP IsEq -- is this safe? nullPatch _ = NotEq instance MightBeEmptyHunk Prim1 where isEmptyHunk (V1.Prim (Prim.FP _ (Hunk _ [] []))) = True isEmptyHunk _ = False instance MightBeEmptyHunk Prim2 where isEmptyHunk (V2.Prim (Prim.FP _ (Hunk _ [] []))) = True isEmptyHunk _ = False instance MightHaveDuplicate Prim1 instance MightHaveDuplicate Prim2 instance Arbitrary (Sealed2 (FL (WithState V1Model Prim1))) where arbitrary = do repo <- ourSmallRepo liftM (unseal (seal2 . wesPatch)) $ arbitraryState repo instance Arbitrary (Sealed2 (FL (WithState V1Model Prim2))) where arbitrary = do repo <- ourSmallRepo liftM (unseal (seal2 . wesPatch)) $ arbitraryState repo -- instance Show1 (TreeWithFlattenPos Prim) where -- showDict1 = ShowDictClass -- WithState and propFail are handy for debugging arbitrary code propFail :: Int -> Tree prim wX -> Bool propFail n xs = sizeTree xs < n ---------------------------------------------------------------------- -- * QuickCheck generators ---------------------------------------------------------------------- -- ** FilePatchType generators aHunk :: Content -> Gen (Int, [BC.ByteString], [BC.ByteString]) aHunk content = sized $ \n -> do pos <- choose (1, contentLen+1) let prefixLen = pos-1 restLen = contentLen-prefixLen oldLen <- frequency [ (75, choose (0, min restLen n)) -- produces small hunks common in real editing , (25, choose (0, min 10 restLen)) ] -- newLen choice aims to cover all possibilities, that is, -- remove less/the same/more than added and empty the file. newLen <- frequency [ ( 54 , choose (1,min 1 n) ) , ( if oldLen /= 0 then 42 else 0 , choose (1,min 1 oldLen) ) , ( if oldLen /= 0 then 2 else 0 , return oldLen ) , ( if oldLen /= 0 then 2 else 0 , return 0 ) ] new <- vectorOf newLen aLine let old = take oldLen $ drop prefixLen $ content return (pos, old, new) where contentLen = length content aTokReplace :: Content -> Gen (String, String, String) aTokReplace [] = do w <- vectorOf 1 alpha w' <- vectorOf 1 alpha return (defaultToks, w, w') aTokReplace content = do let fileWords = concatMap BC.words content wB <- elements fileWords w' <- alphaBS `notIn` fileWords return (defaultToks, BC.unpack wB, BC.unpack w') where alphaBS = do x <- alpha; return $ BC.pack [x] ---------------------------------------------------------------------- -- ** Prim generators aHunkP :: forall prim wX wY . PrimPatch prim => (AnchoredPath,File) -> Gen (prim wX wY) aHunkP (path,file) = do (pos, old, new) <- aHunk content return $ hunk (ap2fp path) pos old new where content = fileContent file aTokReplaceP :: forall prim wX wY . PrimPatch prim => (AnchoredPath,File) -> Gen (prim wX wY) aTokReplaceP (path,file) = do (tokchars, old, new) <- aTokReplace content return $ tokreplace (ap2fp path) tokchars old new where content = fileContent file anAddFileP :: forall prim wX wY . PrimPatch prim => (AnchoredPath,Dir) -> Gen (prim wX wY) anAddFileP (path,dir) = do newFilename <- aFilename `notIn` existing let newPath = path `appendPath` newFilename return $ addfile (ap2fp newPath) where existing = map fst $ filterFiles $ dirContent dir aRmFileP :: forall prim wX wY . PrimPatch prim => AnchoredPath -- ^ Path of an empty file -> prim wX wY aRmFileP path = rmfile (ap2fp path) anAddDirP :: forall prim wX wY . PrimPatch prim => (AnchoredPath,Dir) -> Gen (prim wX wY) anAddDirP (path,dir) = do newDirname <- aDirname `notIn` existing let newPath = path `appendPath` newDirname return $ adddir (ap2fp newPath) where existing = map fst $ filterDirs $ dirContent dir aRmDirP :: forall prim wX wY . PrimPatch prim => AnchoredPath -- ^ Path of an empty directory -> prim wX wY aRmDirP path = rmdir (ap2fp path) aMoveP :: forall prim wX wY . PrimPatch prim => Gen Name -> AnchoredPath -> (AnchoredPath,Dir) -> Gen (prim wX wY) aMoveP nameGen oldPath (dirPath,dir) = do newName <- nameGen `notIn` existing let newPath = dirPath `appendPath` newName return $ move (ap2fp oldPath) (ap2fp newPath) where existing = map fst $ dirContent dir -- | Generates any type of 'prim' patch, except binary and setpref patches. aPrim :: forall prim wX wY . (PrimPatch prim, ApplyState prim ~ RepoState V1Model) => V1Model wX -> Gen (WithEndState V1Model (prim wX) wY) aPrim repo = do mbFile <- maybeOf repoFiles mbEmptyFile <- maybeOf $ filter (isEmpty . snd) repoFiles dir <- elements (rootDir:repoDirs) mbOldDir <- maybeOf repoDirs mbEmptyDir <- maybeOf $ filter (isEmpty . snd) repoDirs patch <- frequency [ ( if isJust mbFile then 12 else 0 , aHunkP $ fromJust mbFile ) , ( if isJust mbFile then 6 else 0 , aTokReplaceP $ fromJust mbFile ) , ( 2 , anAddFileP dir ) , ( if isJust mbEmptyFile then 12 else 0 , return $ aRmFileP $ fst $ fromJust mbEmptyFile ) , ( 2 , anAddDirP dir ) , ( if isJust mbEmptyDir then 10 else 0 , return $ aRmDirP $ fst $ fromJust mbEmptyDir ) , ( if isJust mbFile then 3 else 0 , aMoveP aFilename (fst $ fromJust mbFile) dir ) , let oldPath = fst $ fromJust mbOldDir in ( if isJust mbOldDir && not (oldPath `isPrefix` fst dir) then 4 else 0 , aMoveP aDirname oldPath dir ) ] let repo' = unFail $ repoApply repo patch return $ WithEndState patch repo' where repoItems = list repo repoFiles = filterFiles repoItems repoDirs = filterDirs repoItems rootDir = (anchoredRoot,root repo) {- [COVERAGE OF aPrim] PLEASE, if you change something that may affect the coverage of aPrim then a) recalculate it, or if that is not possible; b) indicate the need to do it. Patch type ---------- 42% hunk 22% tokreplace 14% move 6% rmdir 6% addfile 6% adddir 4% rmfile -} ---------------------------------------------------------------------- -- *** Pairs of primitive patches -- Try to generate commutable pairs of hunks hunkPairP :: forall prim wX wY . PrimPatch prim => (AnchoredPath,File) -> Gen ((prim :> prim) wX wY) hunkPairP (path,file) = do (l1, old1, new1) <- aHunk content (delta, content') <- selectChunk (Hunk l1 old1 new1) content (l2', old2, new2) <- aHunk content' let l2 = l2'+delta return (hunk fpPath l1 old1 new1 :> hunk fpPath l2 old2 new2) where content = fileContent file fpPath = ap2fp path selectChunk (Hunk l old new) content_ = elements [prefix, suffix] where start = l - 1 prefix = (0, take start content_) suffix = (start + length new, drop (start + length old) content_) selectChunk _ _ = impossible aPrimPair :: forall prim wX wY . (PrimPatch prim, ArbitraryState V1Model prim, ApplyState prim ~ RepoState V1Model) => V1Model wX -> Gen (WithEndState V1Model ((prim :> prim) wX) wY) aPrimPair repo = do mbFile <- maybeOf repoFiles frequency [ ( if isJust mbFile then 1 else 0 , do p1 :> p2 <- hunkPairP $ fromJust mbFile let repo' = unFail $ repoApply repo p1 repo'' = unFail $ repoApply repo' p2 return $ WithEndState (p1 :> p2) repo'' ) , ( 1 , do Sealed wesP <- arbitraryState repo return $ unsafeCoerceP1 wesP ) ] where repoItems = list repo repoFiles = filterFiles repoItems {- [COVERAGE OF aPrimPair] PLEASE, if you change something that may affect the coverage of aPrimPair then a) recalculate it, or if that is not possible; b) indicate the need to do it. Rate of ommutable pairs ----------------------- 67% commutable Commutable coverage (for 1000 tests) ------------------- 21% hunks-B 20% hunks-A 14% file:>dir 12% file:>move 8% trivial-FP 8% hunk:>tok 4% hunks-D 3% tok:>tok 2% hunks-C 1% move:>move 1% dir:>move 1% dir:>dir 0% emptyhunk:>file -} ---------------------------------------------------------------------- -- Arbitrary instances ourSmallRepo :: Gen (V1Model wX) ourSmallRepo = aSmallRepo instance ArbitraryState V1Model Prim1 where arbitraryState s = seal <$> aPrim s instance ArbitraryState V1Model Prim2 where arbitraryState s = seal <$> aPrim s instance Arbitrary (Sealed (Prim1 wA)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed (Prim2 wA)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 Prim1) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed2 Prim2) where arbitrary = makeS2Gen ourSmallRepo arbitrarySeal2 :: (PrimPatch prim, ApplyState prim ~ UT.Tree, ArbitraryState V1Model prim) => Gen (Sealed2 (prim :> prim)) arbitrarySeal2 = do repo <- ourSmallRepo WithEndState pp _ <- aPrimPair repo return $ seal2 pp arbitrarySeal :: (PrimPatch prim, ApplyState prim ~ UT.Tree, ArbitraryState V1Model prim) => Gen (Sealed ((:>) prim prim wX)) arbitrarySeal = do repo <- ourSmallRepo WithEndState pp _ <- aPrimPair repo return $ seal pp instance Arbitrary (Sealed2 (Prim1 :> Prim1)) where arbitrary = arbitrarySeal2 instance Arbitrary (Sealed2 (Prim2 :> Prim2)) where arbitrary = arbitrarySeal2 instance Arbitrary (Sealed ((Prim1 :> Prim1) wA)) where arbitrary = arbitrarySeal instance Arbitrary (Sealed ((Prim2 :> Prim2) wA)) where arbitrary = arbitrarySeal instance Arbitrary (Sealed2 (Prim1 :> Prim1 :> Prim1)) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed ((Prim1 :> Prim1 :> Prim1) a)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 (FL Prim1)) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed ((FL Prim1) wA)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 (FL Prim1 :> FL Prim1)) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed ((FL Prim1 :> FL Prim1) wA)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 (WithState V1Model Prim1)) where arbitrary = makeWS2Gen ourSmallRepo instance Arbitrary (Sealed (WithState V1Model Prim1 wA)) where arbitrary = makeWSGen ourSmallRepo instance Arbitrary (Sealed (WithState V1Model (FL Prim1) wA)) where arbitrary = makeWSGen ourSmallRepo instance Arbitrary (Sealed2 (WithState V1Model (Prim1 :> Prim1))) where arbitrary = do repo <- ourSmallRepo WithEndState pp repo' <- aPrimPair repo return $ seal2 $ WithState repo pp repo' instance Arbitrary (Sealed (WithState V1Model (Prim1 :> Prim1) a)) where arbitrary = do repo <- ourSmallRepo WithEndState pp repo' <- aPrimPair repo return $ seal $ WithState repo pp repo' instance Arbitrary (Sealed2 (WithState V1Model (FL Prim1))) where arbitrary = makeWS2Gen ourSmallRepo instance Arbitrary (Sealed2 (WithState V1Model (FL Prim1 :> FL Prim1))) where arbitrary = makeWS2Gen ourSmallRepo instance Arbitrary (Sealed (WithState V1Model (FL Prim1 :> FL Prim1) a)) where arbitrary = makeWSGen ourSmallRepo instance Arbitrary (Sealed2 (Prim2 :> Prim2 :> Prim2)) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed ((Prim2 :> Prim2 :> Prim2) a)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 (FL Prim2)) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed ((FL Prim2) wA)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 (FL Prim2 :> FL Prim2)) where arbitrary = makeS2Gen ourSmallRepo instance Arbitrary (Sealed ((FL Prim2 :> FL Prim2) wA)) where arbitrary = makeSGen ourSmallRepo instance Arbitrary (Sealed2 (WithState V1Model Prim2)) where arbitrary = makeWS2Gen ourSmallRepo instance Arbitrary (Sealed (WithState V1Model Prim2 wA)) where arbitrary = makeWSGen ourSmallRepo instance Arbitrary (Sealed (WithState V1Model (FL Prim2) wA)) where arbitrary = makeWSGen ourSmallRepo instance Arbitrary (Sealed2 (WithState V1Model (Prim2 :> Prim2))) where arbitrary = do repo <- ourSmallRepo WithEndState pp repo' <- aPrimPair repo return $ seal2 $ WithState repo pp repo' instance Arbitrary (Sealed (WithState V1Model (Prim2 :> Prim2) a)) where arbitrary = do repo <- ourSmallRepo WithEndState pp repo' <- aPrimPair repo return $ seal $ WithState repo pp repo' instance Arbitrary (Sealed2 (WithState V1Model (FL Prim2))) where arbitrary = makeWS2Gen ourSmallRepo instance Arbitrary (Sealed2 (WithState V1Model (FL Prim2 :> FL Prim2))) where arbitrary = makeWS2Gen ourSmallRepo instance Arbitrary (Sealed (WithState V1Model (FL Prim2 :> FL Prim2) a)) where arbitrary = makeWSGen ourSmallRepo darcs-2.14.5/harness/Darcs/Test/Patch/Arbitrary/RepoPatchV1.hs0000644000000000000000000002314307346545000022137 0ustar0000000000000000-- Copyright (C) 2002-2003,2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} module Darcs.Test.Patch.Arbitrary.RepoPatchV1 () where import Prelude () import Darcs.Prelude import Test.QuickCheck import Control.Monad ( liftM, liftM2, liftM3, liftM4, replicateM ) import qualified Data.ByteString as B ( ByteString ) import qualified Data.ByteString.Char8 as BC ( pack ) import Darcs.Patch ( addfile, adddir, move, hunk, tokreplace, binary, changepref, invert, merge ) import Darcs.Patch.V1 () import Darcs.Patch.V1.Core ( RepoPatchV1(..) ) import qualified Darcs.Patch.V1.Prim as V1 ( Prim(..) ) import Darcs.Patch.Prim.V1.Core ( Prim(..) ) import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), unseal, mapSeal, Sealed2(..) ) import Darcs.Patch.Witnesses.Unsafe -- This definitely feels a bit weird to be importing Properties here, and -- probably means we want to move this elsewhere, but Darcs.Test.Patch.Check is -- already taken with something apparently only semi-related import Darcs.Test.Patch.Properties.Check( checkAPatch ) import Darcs.Test.Patch.Arbitrary.Generic ( MightHaveDuplicate ) type Patch = RepoPatchV1 V1.Prim pp :: Prim wX wY -> Patch wX wY pp = PP . V1.Prim class ArbitraryP p where arbitraryP :: Gen (Sealed (p wX)) {- TODO: there is a lot of overlap in testing between between this module and Darcs.Test.Patch.QuickCheck This module tests Prim and V1 patches, and Darcs.Test.Patch.QuickCheck tests Prim and V2 patches This module's generator covers a wider set of patch types, but is less likely to generate conflicts than Darcs.Test.Patch.QuickCheck. Until this is cleaned up, we take some care that the Arbitrary instances do not overlap and are only used for tests from the respective modules. (There are also tests in other modules that probably depend on the Arbitrary instances in this module.) -} instance Arbitrary (Sealed (Prim wX)) where arbitrary = arbitraryP instance Arbitrary (Sealed (FL Patch wX)) where arbitrary = arbitraryP -- instance Arbitrary (Sealed2 (Prim :> Prim)) where -- arbitrary = unseal Sealed2 <$> arbitraryP instance Arbitrary (Sealed2 (FL Patch)) where arbitrary = unseal Sealed2 <$> arbitraryP instance Arbitrary (Sealed2 (FL Patch :\/: FL Patch)) where arbitrary = unseal Sealed2 <$> arbitraryP instance Arbitrary (Sealed2 (FL Patch :> FL Patch)) where arbitrary = unseal Sealed2 <$> arbitraryP instance Arbitrary (Sealed2 (FL Patch :> FL Patch :> FL Patch)) where arbitrary = unseal Sealed2 <$> arbitraryP instance (ArbitraryP p1, ArbitraryP p2) => ArbitraryP (p1 :> p2) where arbitraryP = do Sealed p1 <- arbitraryP Sealed p2 <- arbitraryP return (Sealed (p1 :> p2)) instance (ArbitraryP p1, ArbitraryP p2) => ArbitraryP (p1 :\/: p2) where arbitraryP = do Sealed p1 <- arbitraryP Sealed p2 <- arbitraryP return (Sealed (unsafeCoercePEnd p1 :\/: p2)) instance ArbitraryP (FL Patch) where arbitraryP = sized arbpatch instance ArbitraryP Prim where arbitraryP = onepatchgen instance MightHaveDuplicate (RepoPatchV1 prim) hunkgen :: Gen (Sealed (Prim wX)) hunkgen = do i <- frequency [(1,choose (0,5)),(1,choose (0,35)), (2,return 0),(3,return 1),(2,return 2),(1,return 3)] j <- frequency [(1,choose (0,5)),(1,choose (0,35)), (2,return 0),(3,return 1),(2,return 2),(1,return 3)] if i == 0 && j == 0 then hunkgen else Sealed <$> liftM4 hunk filepathgen linenumgen (replicateM i filelinegen) (replicateM j filelinegen) tokreplacegen :: Gen (Sealed (Prim wX)) tokreplacegen = do f <- filepathgen o <- tokengen n <- tokengen if o == n then return $ Sealed $ tokreplace f "A-Za-z" "old" "new" else return $ Sealed $ tokreplace f "A-Za-z_" o n twofilegen :: (forall wY . FilePath -> FilePath -> Prim wX wY) -> Gen (Sealed (Prim wX)) twofilegen p = do n1 <- filepathgen n2 <- filepathgen if n1 /= n2 && checkAPatch (p n1 n2) then return $ Sealed $ p n1 n2 else twofilegen p chprefgen :: Gen (Sealed (Prim wX)) chprefgen = do f <- oneof [return "color", return "movie"] o <- tokengen n <- tokengen if o == n then return $ Sealed $ changepref f "old" "new" else return $ Sealed $ changepref f o n simplepatchgen :: Gen (Sealed (Prim wX)) simplepatchgen = frequency [(1,liftM (Sealed . addfile) filepathgen), (1,liftM (Sealed . adddir) filepathgen), (1,liftM3 (\x y z -> Sealed (binary x y z)) filepathgen arbitrary arbitrary), (1,twofilegen move), (1,tokreplacegen), (1,chprefgen), (7,hunkgen) ] onepatchgen :: Gen (Sealed (Prim wX)) onepatchgen = oneof [simplepatchgen, mapSeal (invert . unsafeCoerceP) `fmap` simplepatchgen] norecursgen :: Int -> Gen (Sealed (FL Patch wX)) norecursgen 0 = mapSeal (\p -> pp p :>: NilFL) `fmap` onepatchgen norecursgen n = oneof [mapSeal (\p -> pp p :>: NilFL) `fmap` onepatchgen,flatcompgen n] arbpatch :: Int -> Gen (Sealed (FL Patch wX)) arbpatch 0 = mapSeal (\p -> pp p :>: NilFL) `fmap` onepatchgen arbpatch n = frequency [(3,mapSeal (\p -> pp p :>: NilFL) `fmap` onepatchgen), (2,flatcompgen n), (0,rawMergeGen n), (0,mergegen n), (1,mapSeal (\p -> pp p :>: NilFL) `fmap` onepatchgen) ] rawMergeGen :: Int -> Gen (Sealed (FL Patch wX)) rawMergeGen n = do Sealed p1 <- arbpatch len Sealed p2 <- arbpatch len if checkAPatch (invert p1:>:p2:>:NilFL) && checkAPatch (invert p2:>:p1:>:NilFL) then case merge (p2 :\/: p1) of _ :/\: p2' -> return (Sealed (unsafeCoercePStart p2')) else rawMergeGen n where len = if n < 15 then n`div`3 else 3 mergegen :: Int -> Gen (Sealed (FL Patch wX)) mergegen n = do Sealed p1 <- norecursgen len Sealed p2 <- norecursgen len if checkAPatch (invert p1:>:p2:>:NilFL) && checkAPatch (invert p2:>:p1:>:NilFL) then case merge (p2:\/:p1) of _ :/\: p2' -> if checkAPatch (p1+>+p2') then return $ Sealed $ p1+>+p2' else impossible else mergegen n where len = if n < 15 then n`div`3 else 3 instance Arbitrary B.ByteString where arbitrary = liftM BC.pack arbitrary flatlistgen :: Int -> Gen (Sealed (FL Patch wX)) flatlistgen 0 = return $ Sealed NilFL flatlistgen n = do Sealed x <- onepatchgen Sealed xs <- flatlistgen (n-1) return (Sealed (pp x :>: xs)) flatcompgen :: Int -> Gen (Sealed (FL Patch wX)) flatcompgen n = do Sealed ps <- flatlistgen n let myp = regularizePatches $ ps if checkAPatch myp then return $ Sealed myp else flatcompgen n -- resize to size 25, that means we'll get line numbers no greater -- than 1025 using QuickCheck 2.1 linenumgen :: Gen Int linenumgen = frequency [(1,return 1), (1,return 2), (1,return 3), (3,liftM (\n->1+abs n) (resize 25 arbitrary)) ] tokengen :: Gen String tokengen = oneof [return "hello", return "world", return "this", return "is", return "a", return "silly", return "token", return "test"] toklinegen :: Gen String toklinegen = liftM unwords $ replicateM 3 tokengen filelinegen :: Gen B.ByteString filelinegen = liftM BC.pack $ frequency [(1,map fromSafeChar `fmap` arbitrary),(5,toklinegen), (1,return ""), (1,return "{"), (1,return "}") ] filepathgen :: Gen String filepathgen = liftM fixpath badfpgen fixpath :: String -> String fixpath "" = "test" fixpath p = fpth p fpth :: String -> String fpth ('/':'/':cs) = fpth ('/':cs) fpth (c:cs) = c : fpth cs fpth [] = [] newtype SafeChar = SS Char instance Arbitrary SafeChar where arbitrary = oneof $ map (return . SS) (['a'..'z']++['A'..'Z']++['1'..'9']++"0") fromSafeChar :: SafeChar -> Char fromSafeChar (SS s) = s badfpgen :: Gen String badfpgen = frequency [(1,return "test"), (1,return "hello"), (1,return "world"), (1,map fromSafeChar `fmap` arbitrary), (1,liftM2 (\a b-> a++"/"++b) filepathgen filepathgen) ] regularizePatches :: FL Patch wX wY -> FL Patch wX wY regularizePatches patches = rpint (unsafeCoerceP NilFL) patches where -- this reverses the list, which seems odd and causes -- the witness unsafety rpint :: FL Patch wX wY -> FL Patch wA wB -> FL Patch wX wY rpint ok_ps NilFL = ok_ps rpint ok_ps (p:>:ps) = if checkAPatch (unsafeCoerceP p:>:ok_ps) then rpint (unsafeCoerceP p:>:ok_ps) ps else rpint ok_ps ps darcs-2.14.5/harness/Darcs/Test/Patch/Arbitrary/RepoPatchV2.hs0000644000000000000000000000605507346545000022143 0ustar0000000000000000{-# LANGUAGE UndecidableInstances #-} module Darcs.Test.Patch.Arbitrary.RepoPatchV2 where import Darcs.Test.Patch.Arbitrary.Generic import Darcs.Test.Patch.Arbitrary.PrimV1 () import Darcs.Test.Patch.RepoModel import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Merge ( Merge(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Prim ( PrimPatch, anIdentity ) import Darcs.Patch.V2 ( RepoPatchV2 ) import Darcs.Patch.V2.RepoPatch ( isDuplicate ) import Test.QuickCheck import Darcs.Test.Patch.WithState import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Witnesses.Eq import Darcs.Patch.Prim ( FromPrim(..) ) nontrivialRepoPatchV2s :: PrimPatch prim => (RepoPatchV2 prim :> RepoPatchV2 prim) wX wY -> Bool nontrivialRepoPatchV2s = nontrivialCommute nontrivialCommute :: (Commute p, Eq2 p) => (p :> p) wX wY -> Bool nontrivialCommute (x :> y) = case commute (x :> y) of Just (y' :> x') -> not (y' `unsafeCompare` y) || not (x' `unsafeCompare` x) Nothing -> False nontrivialMergerepoPatchV2s :: PrimPatch prim => (RepoPatchV2 prim :\/: RepoPatchV2 prim) wX wY -> Bool nontrivialMergerepoPatchV2s = nontrivialMerge nontrivialMerge :: (Eq2 p, Merge p) => (p :\/: p) wX wY -> Bool nontrivialMerge (x :\/: y) = case merge (x :\/: y) of y' :/\: x' -> not (y' `unsafeCompare` y) || not (x' `unsafeCompare` x) instance MightHaveDuplicate (RepoPatchV2 prim) where hasDuplicate = isDuplicate instance (RepoModel (ModelOf prim), ArbitraryPrim prim) => Arbitrary (Sealed2 (FL (RepoPatchV2 prim))) where arbitrary = do Sealed (WithStartState _ tree) <- arbitrary :: Gen (Sealed (WithStartState (ModelOf prim) (Tree prim))) return $ unseal seal2 (flattenOne tree) instance (RepoModel (ModelOf prim), ArbitraryPrim prim) => Arbitrary (Sealed2 (RepoPatchV2 prim)) where arbitrary = do Sealed (WithStartState _ tree) <- arbitrary :: Gen (Sealed (WithStartState (ModelOf prim) (Tree prim))) case mapFL seal2 `unseal` flattenOne tree of [] -> return $ seal2 $ fromPrim anIdentity ps -> elements ps notDuplicatestriple :: (RepoPatchV2 prim :> RepoPatchV2 prim :> RepoPatchV2 prim) wX wY -> Bool notDuplicatestriple (a :> b :> c) = not (isDuplicate a || isDuplicate b || isDuplicate c) nontrivialTriple :: PrimPatch prim => (RepoPatchV2 prim :> RepoPatchV2 prim :> RepoPatchV2 prim) wX wY -> Bool nontrivialTriple (a :> b :> c) = case commute (a :> b) of Nothing -> False Just (b' :> a') -> case commute (a' :> c) of Nothing -> False Just (c'' :> a'') -> case commute (b :> c) of Nothing -> False Just (c' :> b'') -> (not (a `unsafeCompare` a') || not (b `unsafeCompare` b')) && (not (c' `unsafeCompare` c) || not (b'' `unsafeCompare` b)) && (not (c'' `unsafeCompare` c) || not (a'' `unsafeCompare` a')) darcs-2.14.5/harness/Darcs/Test/Patch/0000755000000000000000000000000007346545000015545 5ustar0000000000000000darcs-2.14.5/harness/Darcs/Test/Patch/Check.hs0000644000000000000000000002753407346545000017131 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE CPP, GeneralizedNewtypeDeriving #-} module Darcs.Test.Patch.Check ( PatchCheck, doCheck, fileExists, dirExists, removeFile, removeDir, createFile, createDir, insertLine, deleteLine, isValid, fileEmpty, checkMove, modifyFile, FileContents(..), inconsistent, handleInconsistent ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString as B (ByteString) import Data.List ( isPrefixOf, inits ) import Control.Monad.State ( State, evalState ) import Control.Monad.Trans.Maybe ( MaybeT(..) ) import Control.Monad.State.Class ( get, put, modify, MonadState ) import qualified Data.IntMap as M ( IntMap, mapKeys, delete, insert, empty, lookup, null ) import System.FilePath ( joinPath, splitDirectories ) -- | File contents are represented by a map from line numbers to line contents. -- If for a certain line number, the line contents are Nothing, that means -- that we are sure that that line exists, but we don't know its contents. -- We must also store the greatest line number that is known to exist in a -- file, to be able to exclude the possibility of it being empty without -- knowing its contents. data FileContents = FC { fcLines :: M.IntMap B.ByteString , fcMaxline :: Int } deriving (Eq, Show) data Prop = FileEx String | DirEx String | NotEx String | FileLines String FileContents deriving (Eq) instance Show Prop where show (FileEx f) = "FileEx "++f show (DirEx d) = "DirEx "++d show (NotEx f) = "NotEx"++f show (FileLines f l) = "FileLines "++f++": "++show l -- | A simulated repository state. The repository is assumed to be -- consistent, and it has two lists of properties: one list with properties -- that hold for this repo, and one with properties that do not hold for this -- repo. These two lists may not have any common elements: if they had, the -- repository would be inconsistent. data ValidState = P [Prop] [Prop] deriving Show -- | PatchCheck is a state monad with a simulated repository state newtype PatchCheck a = PatchCheck { runPatchCheck :: MaybeT (State ValidState) a } deriving (Functor, Applicative, Monad, MonadState ValidState) -- The existing instance definitions in Control.Monad.Except make it -- impossible to provide an 'instance MonadError () (MaybeT m)'. throwPC :: PatchCheck a throwPC = PatchCheck $ MaybeT $ return Nothing catchPC :: PatchCheck a -> PatchCheck a -> PatchCheck a PatchCheck m `catchPC` h = PatchCheck $ MaybeT $ do a <- runMaybeT m case a of Nothing -> runMaybeT (runPatchCheck h) Just r -> return (Just r) inconsistent :: PatchCheck () inconsistent = throwPC -- | The @FileContents@ structure for an empty file emptyFilecontents :: FileContents emptyFilecontents = FC M.empty 0 -- | Returns a given value if the repository state is inconsistent, and performs -- a given action otherwise. handleInconsistent :: a -- ^ The value to return if the state is inconsistent -> PatchCheck a -- ^ The action to perform otherwise -> PatchCheck a handleInconsistent v a = a `catchPC` return v doCheck :: PatchCheck a -> Bool doCheck p = evalState (maybe False (const True) <$> runMaybeT (runPatchCheck p)) (P [] []) isValid :: PatchCheck () isValid = return () has :: Prop -> [Prop] -> Bool has _ [] = False has k (k':ks) = k == k' || has k ks modifyFile :: String -> (Maybe FileContents -> Maybe FileContents) -> PatchCheck () modifyFile f change = do fileExists f c <- fileContents f case change c of Nothing -> assertNot $ FileEx f -- shorthand for "FAIL" Just c' -> setContents f c' insertLine :: String -> Int -> B.ByteString -> PatchCheck () insertLine f n l = do c <- fileContents f case c of Nothing -> assertNot $ FileEx f -- in this case, the repo is inconsistent Just c' -> do let lines' = M.mapKeys (\k -> if k >= n then k+1 else k) (fcLines c') lines'' = M.insert n l lines' maxline' = max n (fcMaxline c') setContents f (FC lines'' maxline') -- deletes a line from a hunk patch (third argument) in the given file (first -- argument) at the given line number (second argument) deleteLine :: String -> Int -> B.ByteString -> PatchCheck () deleteLine f n l = do c <- fileContents f case c of Nothing -> assertNot $ FileEx f Just c' -> let flines = fcLines c' flines' = M.mapKeys (\k -> if k > n then k-1 else k) (M.delete n flines) maxlinenum' | n <= fcMaxline c' = fcMaxline c' - 1 | otherwise = n - 1 c'' = FC flines' maxlinenum' do_delete = setContents f c'' in case M.lookup n flines of Nothing -> do_delete Just l' -> if l == l' then do_delete else assertNot $ FileEx f setContents :: String -> FileContents -> PatchCheck () setContents f c = do P ks nots <- get let ks' = FileLines f c : filter (not . is_file_lines_for f) ks put (P ks' nots) where is_file_lines_for file prop = case prop of FileLines f' _ -> file == f' _ -> False -- | Get (as much as we know about) the contents of a file in the current state. -- Returns Nothing if the state is inconsistent. fileContents :: String -> PatchCheck (Maybe FileContents) fileContents f = do P ks _ <- get return (fic ks) where fic (FileLines f' c:_) | f == f' = Just c fic (_:ks) = fic ks fic [] = Just emptyFilecontents -- | Checks if a file is empty fileEmpty :: String -> PatchCheck () fileEmpty f = do c <- fileContents f let empty = case c of Just c' -> fcMaxline c' == 0 && M.null (fcLines c') Nothing -> True if empty then setContents f emptyFilecontents -- Crude way to make it inconsistent and return false: else assertNot $ FileEx f movedirfilename :: String -> String -> String -> String movedirfilename d d' f | (d ++ "/") `isPrefixOf` f = d' ++ drop (length d) f | f == d = d' | otherwise = f -- | Replaces a filename by another in all paths. Returns True if the repository -- is consistent, False if it is not. doSwap :: String -> String -> PatchCheck () doSwap f f' = modify map_sw where sw (FileEx a) | f `is_soe` a = FileEx $ movedirfilename f f' a | f' `is_soe` a = FileEx $ movedirfilename f' f a sw (DirEx a) | f `is_soe` a = DirEx $ movedirfilename f f' a | f' `is_soe` a = DirEx $ movedirfilename f' f a sw (FileLines a c) | f `is_soe` a = FileLines (movedirfilename f f' a) c | f' `is_soe` a = FileLines (movedirfilename f' f a) c sw (NotEx a) | f `is_soe` a = NotEx $ movedirfilename f f' a | f' `is_soe` a = NotEx $ movedirfilename f' f a sw p = p is_soe d1 d2 = -- is_superdir_or_equal d1 == d2 || (d1 ++ "/") `isPrefixOf` d2 map_sw (P ks nots) = P (map sw ks) (map sw nots) -- | Assert a property about the repository. If the property is already present -- in the repo state, nothing changes, and the function returns True. If it is -- not present yet, it is added to the repo state, and the function is True. If -- the property is already in the list of properties that do not hold for the -- repo, the state becomes inconsistent, and the function returns false. assert :: Prop -> PatchCheck () assert p = do P ks nots <- get if has p nots then inconsistent else if has p ks then isValid else put (P (p:ks) nots) -- | Like @assert@, but negatively: state that some property must not hold for -- the current repo. assertNot :: Prop -> PatchCheck () assertNot p = do P ks nots <- get if has p ks then inconsistent else if has p nots then isValid else put (P ks (p:nots)) -- | Remove a property from the list of properties that do not hold for this -- repo (if it's there), and add it to the list of properties that hold. -- Returns False if the repo is inconsistent, True otherwise. changeToTrue :: Prop -> PatchCheck () changeToTrue p = modify filter_nots where filter_nots (P ks nots) = P (p:ks) (filter (p /=) nots) -- | Remove a property from the list of properties that hold for this repo (if -- it's in there), and add it to the list of properties that do not hold. -- Returns False if the repo is inconsistent, True otherwise. changeToFalse :: Prop -> PatchCheck () changeToFalse p = do modify filter_ks where filter_ks (P ks nots) = P (filter (p /=) ks) (p:nots) assertFileExists :: String -> PatchCheck () assertFileExists f = do assertNot $ NotEx f assertNot $ DirEx f assert $ FileEx f assertDirExists :: String -> PatchCheck () assertDirExists d = do assertNot $ NotEx d assertNot $ FileEx d assert $ DirEx d assertExists :: String -> PatchCheck () assertExists f = assertNot $ NotEx f assertNoSuch :: String -> PatchCheck () assertNoSuch f = do assertNot $ FileEx f assertNot $ DirEx f assert $ NotEx f createFile :: String -> PatchCheck () createFile fn = do superdirsExist fn assertNoSuch fn changeToTrue (FileEx fn) changeToFalse (NotEx fn) createDir :: String -> PatchCheck () createDir fn = do substuffDontExist fn superdirsExist fn assertNoSuch fn changeToTrue (DirEx fn) changeToFalse (NotEx fn) removeFile :: String -> PatchCheck () removeFile fn = do superdirsExist fn assertFileExists fn fileEmpty fn changeToFalse (FileEx fn) changeToTrue (NotEx fn) removeDir :: String -> PatchCheck () removeDir fn = do substuffDontExist fn superdirsExist fn assertDirExists fn changeToFalse (DirEx fn) changeToTrue (NotEx fn) checkMove :: String -> String -> PatchCheck () checkMove f f' = do superdirsExist f superdirsExist f' assertExists f assertNoSuch f' doSwap f f' substuffDontExist :: String -> PatchCheck () substuffDontExist d = do P ks _ <- get if all noss ks then isValid else inconsistent where noss (FileEx f) = not (is_within_dir f) noss (DirEx f) = not (is_within_dir f) noss _ = True is_within_dir f = (d ++ "/") `isPrefixOf` f -- the init and tail calls dump the final init (which is just the path itself -- again), the first init (which is empty), and the initial "." from -- splitDirectories superdirsExist :: String -> PatchCheck () superdirsExist fn = mapM_ assertDirExists superdirs where superdirs = map (("./"++) . joinPath) (init (tail (inits (tail (splitDirectories fn))))) fileExists :: String -> PatchCheck () fileExists fn = do superdirsExist fn assertFileExists fn dirExists :: String -> PatchCheck () dirExists fn = do superdirsExist fn assertDirExists fn darcs-2.14.5/harness/Darcs/Test/Patch/Examples/0000755000000000000000000000000007346545000017323 5ustar0000000000000000darcs-2.14.5/harness/Darcs/Test/Patch/Examples/Set1.hs0000644000000000000000000004353007346545000020500 0ustar0000000000000000-- Copyright (C) 2002-2005,2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Test.Patch.Examples.Set1 ( knownCommutes, knownCantCommutes, knownMerges , knownMergeEquivs, knownCanons, mergePairs2 , validPatches, commutePairs, mergePairs , primitiveTestPatches, testPatches, testPatchesNamed , primitiveCommutePairs ) where import Prelude () import Darcs.Prelude import Data.Maybe ( fromJust ) import System.IO.Unsafe ( unsafePerformIO ) import qualified Data.ByteString.Char8 as BC ( pack ) import qualified Data.ByteString as B ( empty ) import Darcs.Patch ( commute, invert, merge , Named, namepatch , readPatch, fromPrim , adddir, addfile, hunk, binary, rmdir, rmfile, tokreplace ) import Darcs.Patch.Prim ( PrimOf, FromPrim ) import qualified Darcs.Patch.V1 as V1 ( RepoPatchV1 ) import qualified Darcs.Patch.V1.Prim as V1 ( Prim(..) ) import Darcs.Test.Patch.Properties.Check( checkAPatch ) import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Sealed ( unsafeUnseal ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP, unsafeCoercePEnd ) type Patch = V1.RepoPatchV1 V1.Prim -- The unit tester function is really just a glorified map for functions that -- return lists, in which the lists get concatenated (where map would end up -- with a list of lists). quickmerge :: (FL Patch :\/: FL Patch) wX wY -> FL Patch wY wZ quickmerge (p1:\/:p2) = case merge (p1:\/:p2) of _ :/\: p1' -> unsafeCoercePEnd p1' -- ---------------------------------------------------------------------- -- * Show/Read tests -- ---------------------------------------------------------------------- -- | This test involves calling 'show' to print a string describing a patch, -- and then using readPatch to read it back in, and making sure the patch we -- read in is the same as the original. Useful for making sure that I don't -- have any stupid IO bugs. -- ---------------------------------------------------------------------- -- * Canonization tests -- ---------------------------------------------------------------------- knownCanons :: [(FL Patch wX wY,FL Patch wX wY)] knownCanons = [(quickhunk 1 "abcde" "ab" :>: NilFL, quickhunk 3 "cde" "" :>: NilFL), (quickhunk 1 "abcde" "bd" :>: NilFL, quickhunk 1 "a" "" :>: quickhunk 2 "c" "" :>: quickhunk 3 "e" "" :>: NilFL), (quickhunk 4 "a" "b" :>: quickhunk 1 "c" "d" :>: NilFL, quickhunk 1 "c" "d" :>: quickhunk 4 "a" "b" :>: NilFL), (quickhunk 1 "a" "" :>: quickhunk 1 "" "b" :>: NilFL, quickhunk 1 "a" "b" :>: NilFL), (quickhunk 1 "ab" "c" :>: quickhunk 1 "cd" "e" :>: NilFL, quickhunk 1 "abd" "e" :>: NilFL), (quickhunk 1 "abcde" "cde" :>: NilFL, quickhunk 1 "ab" "" :>: NilFL), (quickhunk 1 "abcde" "acde" :>: NilFL, quickhunk 2 "b" "" :>: NilFL)] quickhunk :: (FromPrim p, PrimOf p ~ V1.Prim) => Int -> String -> String -> p wX wY quickhunk l o n = fromPrim $ hunk "test" l (map (\c -> BC.pack [c]) o) (map (\c -> BC.pack [c]) n) -- ---------------------------------------------------------------------- -- * Merge/unmgerge tests -- ---------------------------------------------------------------------- -- | It should always be true that if two patches can be unmerged, then merging -- the resulting patches should give them back again. mergePairs :: [(FL Patch :\/: FL Patch) wX wY] mergePairs = take 400 [(p1:\/:p2)| i <- [0..(length testPatches)-1], p1<-[testPatches!!i], p2<-drop i testPatches, checkAPatch (invert p2 :>: p1 :>: NilFL)] -- ---------------------------------------------------------------------- -- * Commute/recommute tests -- ---------------------------------------------------------------------- -- | Here we test to see if commuting patch A and patch B and then commuting -- the result gives us patch A and patch B again. The set of patches (A,B) -- is chosen from the set of all pairs of test patches by selecting those which -- commute with one another. commutePairs :: [(FL Patch :> FL Patch) wX wY] commutePairs = take 200 [(p1:>p2)| p1<-testPatches, p2<-filter (\p->checkAPatch (p1:>:p:>:NilFL)) testPatches, commute (p1:>p2) /= Nothing] primitiveCommutePairs :: [(FL Patch :> FL Patch) wX wY] primitiveCommutePairs = [(p2:>p1)| p1<-primitiveTestPatches, p2<-primitiveTestPatches, commute (p2:>p1) /= Nothing, checkAPatch (p2:>:p1:>:NilFL)] -- ---------------------------------------------------------------------- -- * Commute tests -- ---------------------------------------------------------------------- -- | Here we provide a set of known interesting commutes. knownCommutes :: [((FL Patch :> FL Patch) wX wY,(FL Patch :> FL Patch) wX wY)] knownCommutes = [ (testhunk 2 [] ["B"]:> testhunk 1 [] ["A"], testhunk 1 [] ["A"]:> testhunk 3 [] ["B"]), (testhunk 2 ["hello world all that is old is good old_"] ["I don't like old things"]:> fromPrim (tokreplace "test" "A-Za-z_" "old" "new"), fromPrim (tokreplace "test" "A-Za-z_" "old" "new"):> testhunk 2 ["hello world all that is new is good old_"] ["I don't like new things"]), (testhunk 2 ["C"] ["D"]:> testhunk 1 ["A"] ["B"], testhunk 1 ["A"] ["B"]:> testhunk 2 ["C"] ["D"]), ((quickmerge (fromPrim (addfile "hello"):\/:fromPrim (addfile "hello"))):> fromPrim (rmfile "NwNSO"), fromPrim (rmfile "NwNSO"):> (quickmerge (fromPrim (addfile "hello"):\/:fromPrim (addfile "hello")))), (testhunk 1 [] ["a"]:> quickmerge (testhunk 3 ["o"] ["n"]:\/: testhunk 3 ["o"] ["v"]), quickmerge (testhunk 2 ["o"] ["n"]:\/: testhunk 2 ["o"] ["v"]):> testhunk 1 [] ["a"]), (testhunk 3 ["B"] []:> testhunk 1 ["A"] [], testhunk 1 ["A"] []:> testhunk 2 ["B"] []), (testhunk 2 ["B"] ["C"]:> testhunk 1 ["A"] ["B"], testhunk 1 ["A"] ["B"]:> testhunk 2 ["B"] ["C"]), (testhunk 3 ["B"] ["C"]:> testhunk 1 ["A"] ["B"], testhunk 1 ["A"] ["B"]:> testhunk 3 ["B"] ["C"]), (testhunk 2 ["B"] ["C","D"]:> testhunk 1 ["A"] ["B","C"], testhunk 1 ["A"] ["B","C"]:> testhunk 3 ["B"] ["C","D"])] where testhunk l o n = fromPrim $ hunk "test" l (map BC.pack o) (map BC.pack n) knownCantCommutes :: [(FL Patch :> FL Patch) wX wY] knownCantCommutes = [ (testhunk 1 [] ["A"]:> testhunk 2 ["o"] ["n"]), (testhunk 1 ["o"] ["n"]:> testhunk 1 [] ["A"]), (testhunk 1 [] ["a"]:> quickmerge (testhunk 2 ["o"] ["n"]:\/: testhunk 2 ["o"] ["v"])), (fromPrim (addfile "test"):> fromPrim (hunk "test" 1 ([BC.pack "a"]) ([BC.pack "b"])))] where testhunk l o n = fromPrim $ hunk "test" l (map BC.pack o) (map BC.pack n) -- ---------------------------------------------------------------------- -- * Merge tests -- ---------------------------------------------------------------------- -- | Here we provide a set of known interesting merges. knownMerges :: [((FL Patch:\/:FL Patch) wX wY,FL Patch wY wZ)] knownMerges = [ (testhunk 2 [BC.pack "c"] [BC.pack "d",BC.pack "e"]:\/: testhunk 1 [BC.pack "x"] [BC.pack "a",BC.pack "b"], testhunk 3 [BC.pack "c"] [BC.pack "d",BC.pack "e"]), (testhunk 1 [BC.pack "x"] [BC.pack "a",BC.pack "b"]:\/: testhunk 2 [BC.pack "c"] [BC.pack "d",BC.pack "e"], testhunk 1 [BC.pack "x"] [BC.pack "a",BC.pack "b"]), (testhunk 3 [BC.pack "A"] []:\/: testhunk 1 [BC.pack "B"] [], testhunk 2 [BC.pack "A"] []), (fromPrim (rmdir "./test/world"):\/: fromPrim (hunk "./world" 3 [BC.pack "A"] []), fromPrim (rmdir "./test/world")), ((quickhunk 1 "a" "bc" :>: quickhunk 6 "d" "ef" :>: NilFL):\/: (quickhunk 3 "a" "bc" :>: quickhunk 8 "d" "ef" :>: NilFL), (quickhunk 1 "a" "bc" :>: quickhunk 7 "d" "ef" :>: NilFL)), (testhunk 1 [BC.pack "A"] [BC.pack "B"]:\/: testhunk 2 [BC.pack "B"] [BC.pack "C"], testhunk 1 [BC.pack "A"] [BC.pack "B"]), (testhunk 2 [BC.pack "A"] [BC.pack "B",BC.pack "C"]:\/: testhunk 1 [BC.pack "B"] [BC.pack "C",BC.pack "D"], testhunk 3 [BC.pack "A"] [BC.pack "B",BC.pack "C"])] where testhunk l o n = fromPrim $ hunk "test" l o n knownMergeEquivs :: [((FL Patch :\/: FL Patch) wX wY, FL Patch wY wZ)] knownMergeEquivs = [ -- The following tests are going to be failed by the -- Conflictor code as a cleanup. --(addfile "test":\/: -- adddir "test", -- joinPatches (adddir "test" :>: -- addfile "test-conflict" :>: NilFL)), --(move "silly" "test":\/: -- adddir "test", -- joinPatches (adddir "test" :>: -- move "silly" "test-conflict" :>: NilFL)), --(addfile "test":\/: -- move "old" "test", -- joinPatches (addfile "test" :>: -- move "old" "test-conflict" :>: NilFL)), --(move "a" "test":\/: -- move "old" "test", -- joinPatches (move "a" "test" :>: -- move "old" "test-conflict" :>: NilFL)), (fromPrim (hunk "test" 1 [] [BC.pack "A"]) :\/: fromPrim (hunk "test" 1 [] [BC.pack "B"]), fromPrim (hunk "test" 1 [] [BC.pack "A", BC.pack "B"])), (fromPrim (hunk "test" 1 [] [BC.pack "a"]):\/: fromPrim (hunk "test" 1 [BC.pack "b"] []), unsafeCoerceP NilFL), --hunk "test" 1 [] [BC.pack "v v v v v v v", -- BC.pack "*************", -- BC.pack "a", -- BC.pack "b", -- BC.pack "^ ^ ^ ^ ^ ^ ^"]), (quickhunk 4 "a" "" :\/: quickhunk 3 "a" "", quickhunk 3 "aa" ""), ((quickhunk 1 "a" "bc" :>: quickhunk 6 "d" "ef" :>: NilFL) :\/: (quickhunk 3 "a" "bc" :>: quickhunk 8 "d" "ef" :>: NilFL), quickhunk 3 "a" "bc" :>: quickhunk 8 "d" "ef" :>: quickhunk 1 "a" "bc" :>: quickhunk 7 "d" "ef" :>: NilFL), (quickmerge (quickhunk 2 "" "bd":\/:quickhunk 2 "" "a") :\/: quickmerge (quickhunk 2 "" "c":\/:quickhunk 2 "" "a"), quickhunk 2 "" "abdc") ] -- | It also is useful to verify that it doesn't matter which order we specify -- the patches when we merge. mergePairs2 :: [(FL Patch wX wY, FL Patch wX wZ)] mergePairs2 = [(p1, p2) | p1<-primitiveTestPatches, p2<-primitiveTestPatches, checkAPatch (invert p1:>:p2:>:NilFL) ] -- ---------------------------------------------------------------------- -- Patch test data -- This is where we define the set of patches which we run our tests on. This -- should be kept up to date with as many interesting permutations of patch -- types as possible. -- ---------------------------------------------------------------------- testPatches :: [FL Patch wX wY] testPatchesNamed :: [Named Patch wX wY] testPatchesAddfile :: [FL Patch wX wY] testPatchesRmfile :: [FL Patch wX wY] testPatchesHunk :: [FL Patch wX wY] primitiveTestPatches :: [FL Patch wX wY] testPatchesBinary :: [FL Patch wX wY] testPatchesCompositeNocom :: [FL Patch wX wY] testPatchesComposite :: [FL Patch wX wY] testPatchesTwoCompositeHunks :: [FL Patch wX wY] testPatchesCompositeHunks :: [FL Patch wX wY] testPatchesCompositeFourHunks :: [FL Patch wX wY] testPatchesMerged :: [FL Patch wX wY] validPatches :: [FL Patch wX wY] testPatchesNamed = [unsafePerformIO $ namepatch "date is" "patch name" "David Roundy" [] (fromPrim $ addfile "test"), unsafePerformIO $ namepatch "Sat Oct 19 08:31:13 EDT 2002" "This is another patch" "David Roundy" ["This log file has","two lines in it"] (fromPrim $ rmfile "test")] testPatchesAddfile = map fromPrim [addfile "test",adddir "test",addfile "test/test"] testPatchesRmfile = map invert testPatchesAddfile testPatchesHunk = [fromPrim (hunk file line old new) | file <- ["test"], line <- [1,2], old <- map (map BC.pack) partials, new <- map (map BC.pack) partials, old /= new ] where partials = [["A"],["B"],[],["B","B2"]] primitiveTestPatches = testPatchesAddfile ++ testPatchesRmfile ++ testPatchesHunk ++ [unsafeUnseal.fromJust.readPatch $ BC.pack "move ./test/test ./hello", unsafeUnseal.fromJust.readPatch $ BC.pack "move ./test ./hello"] ++ testPatchesBinary testPatchesBinary = [fromPrim $ binary "./hello" (BC.pack $ "agadshhdhdsa75745457574asdgg" ++ "a326424677373735753246463gadshhdhdsaasdgg" ++ "a326424677373735753246463gadshhdhdsaasdgg" ++ "a326424677373735753246463gadshhdhdsaasdgg") (BC.pack $ "adafjttkykrehhtrththrthrthre" ++ "a326424677373735753246463gadshhdhdsaasdgg" ++ "a326424677373735753246463gadshhdhdsaasdgg" ++ "a326424677373735753246463gadshhdhdsaagg"), fromPrim $ binary "./hello" B.empty (BC.pack "adafjttkykrere")] testPatchesCompositeNocom = take 50 [p1+>+p2| p1<-primitiveTestPatches, p2<-filter (\p->checkAPatch (p1:>:p:>:NilFL)) primitiveTestPatches, commute (p1:>p2) == Nothing] testPatchesComposite = take 100 [p1+>+p2| p1<-primitiveTestPatches, p2<-filter (\p->checkAPatch (p1:>:p:>:NilFL)) primitiveTestPatches, commute (p1:>p2) /= Nothing, commute (p1:>p2) /= Just (unsafeCoerceP p2:>unsafeCoerceP p1)] testPatchesTwoCompositeHunks = take 100 [p1+>+p2| p1<-testPatchesHunk, p2<-filter (\p->checkAPatch (p1:>:p:>:NilFL)) testPatchesHunk] testPatchesCompositeHunks = take 100 [p1+>+p2+>+p3| p1<-testPatchesHunk, p2<-filter (\p->checkAPatch (p1:>:p:>:NilFL)) testPatchesHunk, p3<-filter (\p->checkAPatch (p1:>:p2:>:p:>:NilFL)) testPatchesHunk] testPatchesCompositeFourHunks = take 100 [p1+>+p2+>+p3+>+p4| p1<-testPatchesHunk, p2<-filter (\p->checkAPatch (p1:>:p:>:NilFL)) testPatchesHunk, p3<-filter (\p->checkAPatch (p1:>:p2:>:p:>:NilFL)) testPatchesHunk, p4<-filter (\p->checkAPatch (p1:>:p2:>:p3:>:p:>:NilFL)) testPatchesHunk] testPatchesMerged = take 200 [p2+>+quickmerge (p1:\/:p2) | p1<-take 10 (drop 15 testPatchesCompositeHunks)++primitiveTestPatches ++take 10 (drop 15 testPatchesTwoCompositeHunks) ++ take 2 (drop 4 testPatchesCompositeFourHunks), p2<-take 10 testPatchesCompositeHunks++primitiveTestPatches ++take 10 testPatchesTwoCompositeHunks ++take 2 testPatchesCompositeFourHunks, checkAPatch (invert p1 :>: p2 :>: NilFL), commute (p2:>p1) /= Just (p1:>p2) ] testPatches = primitiveTestPatches ++ testPatchesComposite ++ testPatchesCompositeNocom ++ testPatchesMerged -- ---------------------------------------------------------------------- -- * Check patch test -- ---------------------------------------------------------------------- validPatches = [(quickhunk 4 "a" "b" :>: quickhunk 1 "c" "d" :>: NilFL), (quickhunk 1 "a" "bc" :>: quickhunk 1 "b" "d" :>: NilFL), (quickhunk 1 "a" "b" :>: quickhunk 1 "b" "d" :>: NilFL)]++testPatches darcs-2.14.5/harness/Darcs/Test/Patch/Examples/Set2Unwitnessed.hs0000644000000000000000000005666207346545000022744 0ustar0000000000000000-- Copyright (C) 2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Test.Patch.Examples.Set2Unwitnessed ( primPermutables, primPatches , commutables, commutablesFL , repov2Commutables , repov2Mergeables, repov2Triples , repov2NonduplicateTriples, repov2Patches, repov2PatchLoopExamples ) where import Data.Maybe ( catMaybes ) import qualified Data.ByteString.Char8 as BC ( pack ) import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Prim ( PrimPatch, fromPrim ) import Darcs.Patch.V2 ( RepoPatchV2 ) -- import Darcs.Test.Patch.Test () -- for instance Eq Patch -- import Darcs.Test.Patch.Examples.Set2Unwitnessed import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import qualified Darcs.Test.Patch.Arbitrary.RepoPatchV2 as W ( notDuplicatestriple ) --import Darcs.Util.Printer ( greenText ) --import Darcs.Util.Printer.Color ( traceDoc ) --import Darcs.Util.Printer.Color ( errorDoc ) import Darcs.Util.Printer.Color () -- for instance Show Doc import Darcs.Test.Patch.WSub import qualified Darcs.Patch.Witnesses.Ordered as W ( (:>), (:\/:) ) import qualified Data.ByteString as B ( ByteString ) import Darcs.Test.Patch.V1Model ( V1Model, Content , makeRepo, makeFile) import Darcs.Test.Patch.WithState ( WithStartState(..) ) import Darcs.Util.Path ( makeName ) import Darcs.Patch.Prim ( PrimPatchBase(..), FromPrim, PrimConstruct(..) ) import Darcs.Patch.Merge ( Merge ) import Darcs.Test.Patch.Arbitrary.Generic ( Tree(..) , TreeWithFlattenPos(..) , commutePairFromTree, commuteTripleFromTree , mergePairFromCommutePair, commutePairFromTWFP , canonizeTree ) -- import Debug.Trace type Patch = RepoPatchV2 Prim2 makeSimpleRepo :: String -> Content -> V1Model wX makeSimpleRepo filename content = makeRepo [(makeName filename, makeFile content)] w_tripleExamples :: (FromPrim p, Merge p, Invert p, PrimPatchBase p, PrimConstruct (PrimOf p)) => [Sealed2 (p W.:> p W.:> p)] w_tripleExamples = [commuteTripleFromTree seal2 $ WithStartState (makeSimpleRepo "file" []) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "g"]) (SeqTree (hunk "file" 2 [] [BC.pack "j"]) (SeqTree (hunk "file" 1 [] [BC.pack "s"]) NilTree))) (SeqTree (hunk "file" 1 [] [BC.pack "e"]) NilTree)) ,commuteTripleFromTree seal2 $ WithStartState (makeSimpleRepo "file" [BC.pack "j"]) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "s"]) (ParTree (SeqTree (hunk "file" 2 [BC.pack "j"] []) NilTree) (SeqTree (hunk "file" 2 [BC.pack "j"] []) NilTree))) (SeqTree (hunk "file" 1 [BC.pack "j"] []) NilTree)) ] w_mergeExamples :: (FromPrim p, Merge p, Invert p, PrimPatchBase p, PrimConstruct (PrimOf p)) => [Sealed2 (p W.:\/: p)] w_mergeExamples = map (unseal2 (mergePairFromCommutePair seal2)) w_commuteExamples w_commuteExamples :: (FromPrim p, Merge p, PrimPatchBase p, PrimConstruct (PrimOf p)) => [Sealed2 (p W.:> p)] w_commuteExamples = [ commutePairFromTWFP seal2 $ WithStartState (makeSimpleRepo "file" []) (TWFP 3 (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "h"]) NilTree) (SeqTree (hunk "file" 1 [] [BC.pack "b"]) (SeqTree (hunk "file" 1 [] [BC.pack "f"]) (SeqTree (hunk "file" 1 [] [BC.pack "v"]) (SeqTree (hunk "file" 2 [BC.pack "f"] []) NilTree)))))), commutePairFromTWFP seal2 $ WithStartState (makeSimpleRepo "file" [BC.pack "f",BC.pack "s",BC.pack "d"]) (TWFP 3 (ParTree (SeqTree (hunk "file" 3 [BC.pack "d"] []) NilTree) (ParTree (SeqTree (hunk "file" 1 [BC.pack "f"] []) NilTree) (SeqTree (hunk "file" 1 [BC.pack "f"] []) (SeqTree (hunk "file" 1 [BC.pack "s",BC.pack "d"] []) (SeqTree (hunk "file" 1 [] [BC.pack "v"]) NilTree)))))), {- commutePairFromTWFP seal2 $ WithStartState (makeSimpleRepo "file" [BC.pack "f",BC.pack "u", BC.pack "s",BC.pack "d"]) (TWFP 5 (ParTree (SeqTree (hunk "file" 5 [] [BC.pack "x"]) (SeqTree (hunk "file" 4 [BC.pack "d"] []) NilTree)) (ParTree (SeqTree (hunk "file" 1 [BC.pack "f",BC.pack "u"] []) NilTree) (SeqTree (hunk "file" 1 [BC.pack "f"] []) (SeqTree (hunk "file" 1 [BC.pack "u",BC.pack "s",BC.pack "d"] []) (SeqTree (hunk "file" 1 [] [BC.pack "a"]) (SeqTree (hunk "file" 1 [BC.pack "a"] []) NilTree))))))),-} commutePairFromTree seal2 $ WithStartState (makeSimpleRepo "file" [BC.pack "n",BC.pack "t",BC.pack "h"]) (ParTree (SeqTree (hunk "file" 1 [BC.pack "n",BC.pack "t",BC.pack "h"] []) NilTree) (SeqTree (hunk "file" 3 [BC.pack "h"] []) (SeqTree (hunk "file" 1 [BC.pack "n"] []) (SeqTree (hunk "file" 1 [BC.pack "t"] []) NilTree)))), commutePairFromTree seal2 $ WithStartState (makeSimpleRepo "file" []) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "n"]) NilTree) (SeqTree (hunk "file" 1 [] [BC.pack "i"]) (SeqTree (hunk "file" 1 [] [BC.pack "i"]) NilTree))), commutePairFromTree seal2 $ WithStartState (makeSimpleRepo "file" []) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "c"]) (ParTree (SeqTree (hunk "file" 1 [BC.pack "c"] [BC.pack "r"]) NilTree) (SeqTree (hunk "file" 1 [] [BC.pack "h"]) (SeqTree (hunk "file" 1 [] [BC.pack "d"]) NilTree)))) (SeqTree (hunk "file" 1 [] [BC.pack "f"]) NilTree)), commutePairFromTWFP seal2 $ WithStartState (makeSimpleRepo "file" []) (TWFP 1 (ParTree (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "t"]) NilTree) (SeqTree (hunk "file" 1 [] [BC.pack "t"]) NilTree)) (SeqTree (hunk "file" 1 [] [BC.pack "f"]) NilTree))), commutePairFromTWFP seal2 $ WithStartState (makeSimpleRepo "file" [BC.pack "f",BC.pack " r", BC.pack "c",BC.pack "v"]) (TWFP 4 (ParTree (SeqTree (hunk "file" 3 [BC.pack "c",BC.pack "v"] []) (ParTree (SeqTree (hunk "file" 2 [BC.pack "r"] []) (SeqTree (hunk "fi le" 1 [BC.pack "f"] []) NilTree)) (SeqTree (hunk "file" 1 [BC.pack "f",BC.pack "r"] []) (SeqTree (hunk "file" 1 [] [BC.pack "y"]) NilTree)))) (SeqTree (hunk "file" 4 [BC.pack "v"] []) NilTree))), commutePairFromTree seal2 $ WithStartState (makeSimpleRepo "file" []) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "z"]) NilTree) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "f"]) NilTree) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "r"]) NilTree) (SeqTree (hunk "file" 1 [] [BC.pack "d"]) NilTree)))) , commutePairFromTree seal2 $ WithStartState (makeSimpleRepo "file" [BC.pack "t",BC.pack "r",BC.pack "h"]) (ParTree (ParTree (SeqTree (hunk "file" 1 [BC.pack "t",BC.pack "r",BC.pack "h"] []) NilTree) (SeqTree (hunk "file" 1 [] [BC.pack "o"]) NilTree)) (SeqTree (hunk "file" 1 [BC.pack "t"] []) (SeqTree (hunk "file" 2 [BC.pack "h"] []) NilTree))) , commutePairFromTWFP seal2 $ WithStartState (makeSimpleRepo "file" []) $ TWFP 2 (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "h"]) NilTree) (SeqTree (hunk "file" 1 [] [BC.pack "y"]) (SeqTree (hunk "file" 2 [] [BC.pack "m"]) (SeqTree (hunk "file" 1 [] [BC.pack "v"]) NilTree)))) , commutePairFromTree seal2 $ WithStartState (makeSimpleRepo "file" []) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "p"]) (SeqTree (hunk "file" 1 [BC.pack "p"] []) (SeqTree (hunk "file" 1 [] [BC.pack "c"]) NilTree))) (SeqTree (hunk "file" 1 [] [BC.pack "z"]) NilTree)) , commutePairFromTree seal2 $ WithStartState (makeSimpleRepo "file" []) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "j" ]) (SeqTree (hunk "file" 1 [BC.pack "j"] []) NilTree)) (SeqTree (hunk "file" 1 [] [BC.pack "v"]) NilTree)) , commutePairFromTree seal2 $ WithStartState (makeSimpleRepo "file" []) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "v"]) NilTree) (SeqTree (hunk "file" 1 [] [BC.pack "j" ]) (SeqTree (hunk "file" 1 [BC.pack "j"] []) NilTree))) , commutePairFromTree seal2 $ WithStartState (makeSimpleRepo "file" [BC.pack "x",BC.pack "c"]) (ParTree (SeqTree (hunk "file" 1 [] [BC.pack "h"]) (ParTree (SeqTree (hunk "file" 3 [BC.pack "c"] []) NilTree) (SeqTree (hunk "file" 2 [BC.pack "x"] []) (SeqTree (hunk "file" 1 [] [BC.pack "j"]) NilTree)))) (SeqTree (hunk "file" 1 [] [BC.pack "l"]) NilTree)) , commutePairFromTree seal2 $ WithStartState (makeSimpleRepo "file" []) (ParTree (SeqTree (hunk "file" 1 [] (packStringLetters "s")) NilTree) (SeqTree (hunk "file" 1 [] (packStringLetters "k")) (SeqTree (hunk "file" 1 (packStringLetters "k") []) (SeqTree (hunk "file" 1 [] (packStringLetters "m")) (SeqTree (hunk "file" 1 (packStringLetters "m") []) NilTree))))) ] packStringLetters :: String -> [B.ByteString] packStringLetters = map (BC.pack . (:[])) w_repov2PatchLoopExamples :: [Sealed (WithStartState V1Model (Tree Prim2))] w_repov2PatchLoopExamples = [Sealed (WithStartState (makeSimpleRepo fx []) $ canonizeTree (ParTree (SeqTree (hunk fx 1 [] (packStringLetters "pkotufogbvdabnmbzajvolwviqebieonxvcvuvigkfgybmqhzuaaurjspd")) (ParTree (SeqTree (hunk fx 47 (packStringLetters "qhzu") (packStringLetters "zafybdcokyjskcgnvhkbzpysaafnjjhcstgrczplxsfwagmh")) (ParTree (ParTree NilTree (ParTree (ParTree (ParTree (SeqTree (hunk fx 15 (packStringLetters "mbzajvolwviqebieonxvcvuvigkfgyb") (packStringLetters "vujnxnhvybvpouyciaabszfmgssezlwwjgnethvrpnfrkubphzvdgymjjoacppqps")) (ParTree NilTree (ParTree (SeqTree (hunk fx 40 (packStringLetters "ssezlwwjgnethvrpnfrkubphzvdgymjjoacppqpsmzafybdcokyjskcgnvhkbz") (packStringLetters "wnesidpccwoiqiichxaaejdsyrhrusqljlcoro")) (ParTree (ParTree (SeqTree (hunk fx 12 (packStringLetters "abnvujnxnhvybvpouyciaabszfmgwnesidpccwoiqii") (packStringLetters "czfdhqkipdstfjycqaxwnbxrihrufdeyneqiiiafwzlmg")) NilTree) NilTree) NilTree)) (SeqTree (hunk fx 25 [] (packStringLetters "dihgmsotezucqdgxczvcivijootyvhlwymbiueufnvpwpeukmskqllalfe")) NilTree)))) (SeqTree (hunk fx 56 (packStringLetters "yjskcgnvhkbzpysaafnjjhcstgrczplxsfwagmhaaurjsp") (packStringLetters "xldhrutyhcyaqeezwujiguawfyawjjqlirxshjddvq")) NilTree)) (SeqTree (hunk fx 20 [] (packStringLetters "ooygwiyogqrqnytixqtmvdxx")) (SeqTree (hunk fx 26 (packStringLetters "yogqrqnytixqtmvdxxvolwviqebieonxvcvuvigkfgybmzafybdcokyjskcgnvhkbz") (packStringLetters "akhsmlbkdxnvfoikmiatfbpzdrsyykkpoxvvddeaspzxe")) (SeqTree (hunk fx 39 [] (packStringLetters "ji")) (ParTree NilTree (ParTree NilTree (ParTree (ParTree NilTree (SeqTree (hunk fx 26 (packStringLetters "akhsmlbkdxnvfjioikmiatfbpzdrsyykkpoxvvddeaspzxepysaafnjjhcstgrczplxs") (packStringLetters "onjbhddskcj")) (SeqTree (hunk fx 39 [] (packStringLetters "fyscunxxxjjtyqpfxeznhtwvlphmp")) NilTree))) (ParTree NilTree (SeqTree (hunk fx 44 [] (packStringLetters "xcchzwmzoezxkmkhcmesplnjpqriypshgiqklgdnbmmkldnydiy")) (ParTree NilTree (SeqTree (hunk fx 64 (packStringLetters "plnjpqriypshgiqklgdnbmmkldnydiymiatfbpzdrsyykkpoxvvddeaspzxepysaafn") (packStringLetters "anjlzfdqbjqbcplvqvkhwjtkigp")) NilTree))))))))))) (ParTree NilTree NilTree))) NilTree)) NilTree)) (ParTree NilTree (SeqTree (hunk fx 1 [] (packStringLetters "ti")) (SeqTree (hunk fx 1 (packStringLetters "t") (packStringLetters "ybcop")) (SeqTree (hunk fx 2 [] (packStringLetters "dvlhgwqlpaeweerqrhnjtfolczbqbzoccnvdsyqiefqitrqneralf")) (SeqTree (hunk fx 15 [] (packStringLetters "yairbjphwtnaerccdlfewujvjvmjakbc")) (SeqTree (hunk fx 51 [] (packStringLetters "xayvfuwaiiogginufnhsrmktpmlbvxiakjwllddkiyofyfw")) (ParTree NilTree NilTree)))))))))] where fx :: String fx = "F" mergeExamples :: [Sealed2 (Patch :\/: Patch)] mergeExamples = map (mapSeal2 fromW) w_mergeExamples repov2PatchLoopExamples :: [Sealed (WithStartState V1Model (Tree Prim2))] repov2PatchLoopExamples = w_repov2PatchLoopExamples commuteExamples :: [Sealed2 (Patch :> Patch)] commuteExamples = map (mapSeal2 fromW) w_commuteExamples tripleExamples :: [Sealed2 (Patch :> Patch :> Patch)] tripleExamples = map (mapSeal2 fromW) w_tripleExamples notDuplicatestriple :: (Patch :> Patch :> Patch) wX wY -> Bool notDuplicatestriple = W.notDuplicatestriple . toW quickhunk :: PrimPatch prim => Int -> String -> String -> prim wX wY quickhunk l o n = hunk "test" l (map (\c -> BC.pack [c]) o) (map (\c -> BC.pack [c]) n) primPermutables :: [(Prim2 :> Prim2 :> Prim2) wX wY] primPermutables = [quickhunk 0 "e" "bo" :> quickhunk 3 "" "x" :> quickhunk 2 "f" "qljo"] mergeables :: [(Prim2 :\/: Prim2) wX wY] mergeables = [quickhunk 1 "a" "b" :\/: quickhunk 1 "a" "c", quickhunk 1 "a" "b" :\/: quickhunk 3 "z" "c", quickhunk 0 "" "a" :\/: quickhunk 1 "" "b", quickhunk 0 "a" "" :\/: quickhunk 1 "" "b", quickhunk 0 "a" "" :\/: quickhunk 1 "b" "", quickhunk 0 "" "a" :\/: quickhunk 1 "b" "" ] mergeablesFL :: [(FL Prim2 :\/: FL Prim2) wX wY] mergeablesFL = map (\ (x:\/:y) -> (x :>: NilFL) :\/: (y :>: NilFL)) mergeables ++ [] -- [(quickhunk 1 "a" "b" :>: quickhunk 3 "z" "c" :>: NilFL) -- :\/: (quickhunk 1 "a" "z" :>: NilFL), -- (quickhunk 1 "a" "b" :>: quickhunk 1 "b" "c" :>: NilFL) -- :\/: (quickhunk 1 "a" "z" :>: NilFL)] mergeable2commutable :: Invert p => (p :\/: p) wX wY -> (p :> p) wX wY mergeable2commutable (x :\/: y) = unsafeCoerceP (invert x) :> y commutablesFL :: [(FL Prim2 :> FL Prim2) wX wY] commutablesFL = map mergeable2commutable mergeablesFL commutables :: [(Prim2 :> Prim2) wX wY] commutables = map mergeable2commutable mergeables primPatches :: [Prim2 wX wY] primPatches = concatMap mergeable2patches mergeables where mergeable2patches (x:\/:y) = [x,y] repov2Patches :: [Patch wX wY] repov2Patches = concatMap commutable2patches repov2Commutables where commutable2patches (x:>y) = [x,y] repov2Triples :: [(Patch :> Patch :> Patch) wX wY] repov2Triples = [ob' :> oa2 :> a2'', oa' :> oa2 :> a2''] ++ map unsafeUnseal2 tripleExamples ++ map unsafeUnseal2 (concatMap getTriples repov2FLs) where oa = fromPrim $ quickhunk 1 "o" "aa" oa2 = oa a2 = fromPrim $ quickhunk 2 "a34" "2xx" ob = fromPrim $ quickhunk 1 "o" "bb" ob' :/\: oa' = merge (oa :\/: ob) a2' :/\: _ = merge (ob' :\/: a2) a2'' :/\: _ = merge (oa2 :\/: a2') repov2NonduplicateTriples :: [(Patch :> Patch :> Patch) wX wY] repov2NonduplicateTriples = filter (notDuplicatestriple) repov2Triples repov2FLs :: [FL (Patch) wX wY] repov2FLs = [oa :>: invert oa :>: oa :>: invert oa :>: ps +>+ oa :>: invert oa :>: NilFL] where oa = fromPrim $ quickhunk 1 "o" "a" ps :/\: _ = merge (oa :>: invert oa :>: NilFL :\/: oa :>: invert oa :>: NilFL) repov2Commutables :: [(Patch :> Patch) wX wY] repov2Commutables = map unsafeUnseal2 commuteExamples++ map mergeable2commutable repov2Mergeables++ [invert oa :> ob'] ++ map unsafeUnseal2 (concatMap getPairs repov2FLs) where oa = fromPrim $ quickhunk 1 "o" "a" ob = fromPrim $ quickhunk 1 "o" "b" _ :/\: ob' = mergeFL (ob :\/: oa :>: invert oa :>: NilFL) repov2Mergeables :: [(Patch :\/: Patch) wX wY] repov2Mergeables = map (\ (x :\/: y) -> fromPrim x :\/: fromPrim y) mergeables ++ repov2IglooMergeables ++ repov2QuickcheckMergeables ++ map unsafeUnseal2 mergeExamples ++ catMaybes (map pair2m (concatMap getPairs repov2FLs)) ++ [(oa :\/: od), (oa :\/: a2'), (ob' :\/: od''), (oe :\/: od), (of' :\/: oe'), (ob' :\/: oe'), (oa :\/: oe'), (ob' :\/: oc'), (b2' :\/: oc'''), (ob' :\/: a2), (b2' :\/: og'''), (oc''' :\/: og'''), (oc'' :\/: og''), (ob'' :\/: og''), (ob'' :\/: oc''), (oc' :\/: od'')] where oa = fromPrim $ quickhunk 1 "o" "aa" a2 = fromPrim $ quickhunk 2 "a34" "2xx" og = fromPrim $ quickhunk 3 "4" "g" ob = fromPrim $ quickhunk 1 "o" "bb" b2 = fromPrim $ quickhunk 2 "b" "2" oc = fromPrim $ quickhunk 1 "o" "cc" od = fromPrim $ quickhunk 7 "x" "d" oe = fromPrim $ quickhunk 7 "x" "e" pf = fromPrim $ quickhunk 7 "x" "f" od'' = fromPrim $ quickhunk 8 "x" "d" ob' :>: b2' :>: NilFL :/\: _ = mergeFL (oa :\/: ob :>: b2 :>: NilFL) a2' :/\: _ = merge (ob' :\/: a2) ob'' :/\: _ = merge (a2 :\/: ob') og' :/\: _ = merge (oa :\/: og) og'' :/\: _ = merge (a2 :\/: og') og''' :/\: _ = merge (ob' :\/: og') oc' :/\: _ = merge (oa :\/: oc) oc'' :/\: _ = merge (a2 :\/: oc) oc''' :/\: _ = merge (ob' :\/: oc') oe' :/\: _ = merge (od :\/: oe) of' :/\: _ = merge (od :\/: pf) pair2m :: Sealed2 (Patch :> Patch) -> Maybe ((Patch :\/: Patch) wX wY) pair2m (Sealed2 (xx :> y)) = do y' :> _ <- commute (xx :> y) return $ unsafeCoerceP (xx :\/: y') repov2IglooMergeables :: [(Patch :\/: Patch) wX wY] repov2IglooMergeables = [(a :\/: b), (b :\/: c), (a :\/: c), (x :\/: a), (y :\/: b), (z :\/: c), (x' :\/: y'), (z' :\/: y'), (x' :\/: z'), (a :\/: a)] where a = fromPrim $ quickhunk 1 "1" "A" b = fromPrim $ quickhunk 2 "2" "B" c = fromPrim $ quickhunk 3 "3" "C" x = fromPrim $ quickhunk 1 "1BC" "xbc" y = fromPrim $ quickhunk 1 "A2C" "ayc" z = fromPrim $ quickhunk 1 "AB3" "abz" x' :/\: _ = merge (a :\/: x) y' :/\: _ = merge (b :\/: y) z' :/\: _ = merge (c :\/: z) repov2QuickcheckMergeables :: [(Patch :\/: Patch) wX wY] repov2QuickcheckMergeables = [-- invert k1 :\/: n1 --, invert k2 :\/: n2 hb :\/: k , b' :\/: b' , n' :\/: n' , b :\/: d , k' :\/: k' , k3 :\/: k3 ] ++ catMaybes (map pair2m pairs) where hb = fromPrim $ quickhunk 0 "" "hb" k = fromPrim $ quickhunk 0 "" "k" n = fromPrim $ quickhunk 0 "" "n" b = fromPrim $ quickhunk 1 "b" "" d = fromPrim $ quickhunk 2 "" "d" d':/\:_ = merge (b :\/: d) --k1 :>: n1 :>: NilFL :/\: _ = mergeFL (hb :\/: k :>: n :>: NilFL) --k2 :>: n2 :>: NilFL :/\: _ = -- merge (hb :>: b :>: NilFL :\/: k :>: n :>: NilFL) k' :>: n' :>: NilFL :/\: _ :>: b' :>: _ = merge (hb :>: b :>: d' :>: NilFL :\/: k :>: n :>: NilFL) pairs = getPairs (hb :>: b :>: d' :>: k' :>: n' :>: NilFL) pair2m :: Sealed2 (Patch :> Patch) -> Maybe ((Patch :\/: Patch) wX wY) pair2m (Sealed2 (xx :> y)) = do y' :> _ <- commute (xx :> y) return $ unsafeCoerceP (xx :\/: y') i = fromPrim $ quickhunk 0 "" "i" x = fromPrim $ quickhunk 0 "" "x" xi = fromPrim $ quickhunk 0 "xi" "" d3 :/\: _ = merge (xi :\/: d) _ :/\: k3 = mergeFL (k :\/: i :>: x :>: xi :>: d3 :>: NilFL) darcs-2.14.5/harness/Darcs/Test/Patch/FileUUIDModel.hs0000644000000000000000000001561707346545000020442 0ustar0000000000000000{-# LANGUAGE OverloadedStrings, MultiParamTypeClasses, StandaloneDeriving #-} -- | Repository model module Darcs.Test.Patch.FileUUIDModel ( FileUUIDModel , Object(..) , repoApply , emptyFile , emptyDir , nullRepo , root, rootId , repoObjects, repoIds , aFilename, aDirname , aLine, aContent , aFile, aDir , aRepo , anUUID ) where import Prelude () import Darcs.Prelude import Darcs.Test.Util.QuickCheck ( alpha, uniques, bSized ) import Darcs.Test.Patch.RepoModel import Darcs.Patch.Apply( applyToState ) import Darcs.Patch.Prim.FileUUID.Core( UUID(..), Object(..) ) import Darcs.Patch.Prim.FileUUID.Apply( ObjectMap(..) ) import Darcs.Patch.Witnesses.Sealed ( Sealed, seal ) import Darcs.Patch.Witnesses.Show import Darcs.Util.Path ( Name, unsafeMakeName ) import Darcs.Util.Hash( Hash(..) ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import qualified Data.Map as M import Data.Maybe ( fromJust ) import Test.QuickCheck ( Arbitrary(..) , Gen, choose, vectorOf, frequency, oneof ) -- import Text.Show.Pretty ( ppShow ) ---------------------------------------------------------------------- -- * Model definition newtype FileUUIDModel wX = FileUUIDModel { _repoMap :: ObjectMap Fail } ---------------------------------------- -- Instances instance Show (Object Fail) where show (Directory l) = show l show (Blob c _) = show c deriving instance Eq (Object Fail) instance Show (FileUUIDModel wX) where show repo = "FileUUIDModel " ++ show (repoObjects repo) instance Show1 FileUUIDModel where showDict1 = ShowDictClass ---------------------------------------------------------------------- -- * Constructors objectMap :: (Monad m) => M.Map UUID (Object m) -> ObjectMap m objectMap m = ObjectMap { getObject = get, putObject = put, listObjects = list } where list = return $ M.keys m put k o = return $ objectMap (M.insert k o m) get k = return $ M.lookup k m {- emptyRepo :: FileUUIDModel wX emptyRepo = FileUUIDModel (objectMap $ M.singleton rootId emptyDir) -} emptyFile :: (Monad m) => Object m emptyFile = Blob (return B.empty) NoHash emptyDir :: Object m emptyDir = Directory M.empty ---------------------------------------------------------------------- -- * Queries nullRepo :: FileUUIDModel wX -> Bool nullRepo repo = repoIds repo == [rootId] rootId :: UUID rootId = UUID "ROOT" -- | The root directory of a repository. root :: FileUUIDModel wX -> (UUID, Object Fail) root (FileUUIDModel repo) = (rootId, fromJust $ unFail $ getObject repo rootId) repoObjects :: FileUUIDModel wX -> [(UUID, Object Fail)] repoObjects (FileUUIDModel repo) = [(uuid, obj uuid) | uuid <- unFail $ listObjects repo] where obj uuid = fromJust $ unFail $ getObject repo uuid repoIds :: FileUUIDModel wX -> [UUID] repoIds = map fst . repoObjects -- | @isEmpty file@ <=> file content is empty -- @isEmpty dir@ <=> dir has no child isEmpty :: Object Fail -> Bool isEmpty (Directory d) = M.null d isEmpty (Blob f _) = B.null $ unFail f nonEmptyRepoObjects :: FileUUIDModel wX -> [(UUID, Object Fail)] nonEmptyRepoObjects = filter (not . isEmpty . snd) . repoObjects ---------------------------------------------------------------------- -- * Comparing repositories ---------------------------------------------------------------------- -- * QuickCheck generators -- Testing code assumes that aFilename and aDirname generators -- will always be able to generate a unique name given a list of -- existing names. This should be OK as long as the number of possible -- file/dirnames is much bigger than the number of files/dirs per repository. -- 'Arbitrary' 'FileUUIDModel' instance is based on the 'aSmallRepo' generator. -- | Files are distinguish by ending their names with ".txt". aFilename :: Gen Name aFilename = do len <- choose (1,3) name <- vectorOf len alpha return $ unsafeMakeName . BC.pack $ name ++ ".txt" aDirname :: Gen Name aDirname = do len <- choose (1,3) name <- vectorOf len alpha return $ unsafeMakeName . BC.pack $ name aWord :: Gen B.ByteString aWord = do c <- alpha return $ BC.pack[c] aLine :: Gen B.ByteString aLine = do wordsNo <- choose (1,2) ws <- vectorOf wordsNo aWord return $ BC.unwords ws aContent :: Gen B.ByteString aContent = bSized 0 0.5 80 $ \k -> do n <- choose (0,k) BC.intercalate "\n" <$> vectorOf n aLine aFile :: (Monad m) => Gen (Object m) aFile = aContent >>= \c -> return $ Blob (return c) NoHash aDir :: (Monad m) => [UUID] -> [UUID] -> Gen [(UUID, Object m)] aDir [] _ = return [] aDir (dirid:dirids) fileids = do dirsplit <- choose (1, length dirids) filesplit <- choose (1, length fileids) let ids = take filesplit fileids files <- vectorOf filesplit aFile names <- vectorOf filesplit aFilename dirnames <- vectorOf dirsplit aDirname dirs <- subdirs (take dirsplit dirids) (drop dirsplit dirids) (drop filesplit fileids) return $ (dirid, Directory $ M.fromList $ names `zip` ids ++ dirnames `zip` dirids) : (fileids `zip` files) ++ dirs where subdirs [] _ _ = return [] subdirs tomake dirs files = do dirsplit <- choose (1, length dirs) filesplit <- choose (1, length files) dir <- aDir (head tomake : take dirsplit dirs) (take filesplit files) remaining <- subdirs (tail tomake) (drop dirsplit dirs) (drop filesplit files) return $ dir ++ remaining anUUID :: Gen UUID anUUID = UUID . BC.pack <$> vectorOf 4 (oneof $ map return "0123456789") -- | @aRepo filesNo dirsNo@ produces repositories with *at most* -- @filesNo@ files and @dirsNo@ directories. -- The structure of the repository is aleatory. aRepo :: Int -- ^ Maximum number of files -> Int -- ^ Maximum number of directories -> Gen (FileUUIDModel wX) aRepo maxFiles maxDirs = do ids <- uniques (maxFiles+maxDirs) anUUID let minFiles = if maxDirs == 0 && maxFiles > 0 then 1 else 0 filesNo <- choose (minFiles,maxFiles) let minDirs = if filesNo == 0 && maxDirs > 0 then 1 else 0 dirsNo <- choose (minDirs,maxDirs) let (dirids, ids') = splitAt dirsNo ids fileids = take filesNo ids' objectmap <- aDir (rootId : dirids) fileids return $ FileUUIDModel $ objectMap $ M.fromList objectmap -- | Generate small repositories. -- Small repositories help generating (potentially) conflicting patches. instance RepoModel FileUUIDModel where type RepoState FileUUIDModel = ObjectMap aSmallRepo = do filesNo <- frequency [(3, return 1), (1, return 2)] dirsNo <- frequency [(3, return 1), (1, return 0)] aRepo filesNo dirsNo repoApply (FileUUIDModel state) patch = FileUUIDModel <$> applyToState patch state showModel = show -- ppShow eqModel r1 r2 = nonEmptyRepoObjects r1 == nonEmptyRepoObjects r2 instance Arbitrary (Sealed FileUUIDModel) where arbitrary = seal <$> aSmallRepo darcs-2.14.5/harness/Darcs/Test/Patch/Info.hs0000644000000000000000000001756507346545000017012 0ustar0000000000000000-- Copyright (C) 2009 Reinier Lamers -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | This module contains tests for the code in Darcs.Patch.Info. Most of them -- are about the UTF-8-encoding of patch metadata. module Darcs.Test.Patch.Info ( testSuite ) where import Prelude hiding ( pi ) import qualified Data.ByteString as B ( ByteString, pack ) import qualified Data.ByteString.Char8 as BC ( unpack ) import Data.List ( sort , isPrefixOf ) import Data.Maybe ( isNothing ) import Data.Text as T ( find, any ) import Data.Text.Encoding ( decodeUtf8With ) import Data.Text.Encoding.Error ( lenientDecode ) import Test.QuickCheck ( Arbitrary(arbitrary), oneof, listOf, choose, shrink , Gen, suchThat, scale ) import Test.Framework.Providers.QuickCheck2 ( testProperty ) import Test.Framework (Test, testGroup) -- import Text.Show.Pretty ( ppShow ) import Darcs.Patch.Info ( PatchInfo(..), rawPatchInfo, showPatchInfo, readPatchInfo , piLog, piAuthor, piName, validDate, validLog, validAuthor , validDatePS, validLogPS, validAuthorPS ) import Darcs.Patch.ReadMonads ( parseStrictly ) import Darcs.Patch.Show ( ShowPatchFor(..) ) import Darcs.Util.ByteString ( decodeLocale, packStringToUTF8, unpackPSFromUTF8, linesPS ) import Darcs.Util.Printer ( renderPS ) testSuite :: Test testSuite = testGroup "Darcs.Patch.Info" [ metadataDecodingTest , metadataEncodingTest , packUnpackTest , parseUnparseTest ] -- | A newtype wrapping String so we can make our own random generator for it. newtype UnicodeString = UnicodeString { asString :: String } deriving (Show, Eq, Ord) -- | A newtype wrapping PatchInfo that has a random generator that generates -- both UTF-8-encoded and non-encoded PatchInfo's. newtype UTF8OrNotPatchInfo = UTF8OrNotPatchInfo PatchInfo deriving (Eq, Ord) -- | A newtype wrapping PatchInfo, which has a random generator that generates -- only UTF-8-encoded PatchInfo's. newtype UTF8PatchInfo = UTF8PatchInfo PatchInfo deriving (Eq, Ord) -- Note that this instance only creates valid unicode strings. It does not -- generate lone surrogates, for instance, as these would fail the -- packUnpackTest below. instance Arbitrary UnicodeString where -- 0x10ffff is the highest Unicode code point ; 0xd800 - 0xdfff are -- surrogates. '\xfffd' is excluded because it is used as a marker -- for UTF-8 test failure. arbitrary = UnicodeString `fmap` listOf (oneof [choose ('\0', '\xd799') ,choose ('\xe000', '\xfffc') ,choose ('\xfffe', '\x10ffff')]) instance Show UTF8PatchInfo where show = withUTF8PatchInfo rawPatchInfoShow instance Show UTF8OrNotPatchInfo where show = withUTF8OrNotPatchInfo rawPatchInfoShow -- | Shows a PatchInfo, outputting every byte and clearly marking what is what rawPatchInfoShow :: PatchInfo -> String rawPatchInfoShow = {- ppShow -} show instance Arbitrary UTF8PatchInfo where arbitrary = UTF8PatchInfo `fmap` arbitraryUTF8PatchInfo shrink upi = flip withUTF8PatchInfo upi $ \pi -> do sn <- shrink (piName pi) sa <- shrink (piAuthor pi) sl <- shrink (filter (not . isPrefixOf "Ignore-this:") (piLog pi)) i <- shrink (isInverted pi) return (UTF8PatchInfo (rawPatchInfo sn (BC.unpack (_piDate pi)) sa sl i)) instance Arbitrary UTF8OrNotPatchInfo where arbitrary = UTF8OrNotPatchInfo `fmap` oneof ([arbitraryUTF8PatchInfo, arbitraryUnencodedPatchInfo]) -- | Generate arbitrary patch metadata. -- Note : We must NOT use 'patchinfo' from Darcs.Patch.Info -- with unsafePerformIO here because this breaks the parse/unparse test -- (the added junk will be different on each call). arbitraryUTF8PatchInfo :: Gen PatchInfo arbitraryUTF8PatchInfo = do d <- arbitrary `suchThat` validDate n <- (asString `fmap` arbitrary) `suchThat` validLog a <- (asString `fmap` arbitrary) `suchThat` validAuthor l <- lines `fmap` scale (* 2) arbitrary i <- return False return $ rawPatchInfo d n a l i -- | Generate arbitrary patch metadata that has totally arbitrary byte strings -- as its name, date, author and log. arbitraryUnencodedPatchInfo :: Gen PatchInfo arbitraryUnencodedPatchInfo = do d <- arbitraryByteString `suchThat` validDatePS n <- arbitraryByteString `suchThat` validLogPS a <- arbitraryByteString `suchThat` validAuthorPS l <- linesPS `fmap` scale (* 2) arbitraryByteString i <- return False return (PatchInfo d n a l i) arbitraryByteString :: Gen B.ByteString arbitraryByteString = B.pack <$> listOf arbitrary -- | Test that anything produced by the 'patchinfo' function is valid UTF-8 metadataEncodingTest :: Test metadataEncodingTest = testProperty "Testing patch metadata encoding" propMetadataEncoding propMetadataEncoding :: UTF8PatchInfo -> Bool propMetadataEncoding (UTF8PatchInfo patchInfo) = encodingOK (_piAuthor patchInfo) && encodingOK (_piName patchInfo) && all encodingOK (_piLog patchInfo) where encodingOK = isNothing . T.find (=='\xfffd') . decodeUtf8With lenientDecode -- | Test that metadata in patches are decoded as UTF-8 or locale depending on -- whether they're valid UTF-8. metadataDecodingTest :: Test metadataDecodingTest = testProperty "Testing patch metadata decoding" propMetadataDecoding propMetadataDecoding :: UTF8OrNotPatchInfo -> Bool propMetadataDecoding (UTF8OrNotPatchInfo patchInfo) = utf8OrLocale (_piAuthor patchInfo) == piAuthor patchInfo && utf8OrLocale (_piName patchInfo) == piName patchInfo && map utf8OrLocale (_piLog patchInfo) `superset` piLog patchInfo where utf8OrLocale bs = if isValidUTF8 bs then unpackPSFromUTF8 bs else decodeLocale bs isValidUTF8 :: B.ByteString -> Bool isValidUTF8 = not . T.any (=='\xfffd') . decodeUtf8With lenientDecode packUnpackTest :: Test packUnpackTest = testProperty "Testing UTF-8 packing and unpacking" $ \uString -> asString uString == (unpackPSFromUTF8 . packStringToUTF8) (asString uString) superset :: (Eq a, Ord a) => [a] -> [a] -> Bool superset a b = sorted_superset (sort a) (sort b) where sorted_superset (x:xs) (y:ys) | x == y = sorted_superset xs ys | x < y = sorted_superset xs (y:ys) | otherwise = False sorted_superset [] (_:_) = False sorted_superset _ [] = True withUTF8PatchInfo :: (PatchInfo -> a) -> UTF8PatchInfo -> a withUTF8PatchInfo f mpi = case mpi of UTF8PatchInfo pinf -> f pinf withUTF8OrNotPatchInfo :: (PatchInfo -> a) -> UTF8OrNotPatchInfo -> a withUTF8OrNotPatchInfo f mpi = case mpi of UTF8OrNotPatchInfo pinf -> f pinf parseUnparseTest :: Test parseUnparseTest = testProperty "parse . show == id" propParseUnparse parsePatchInfo :: B.ByteString -> Maybe PatchInfo parsePatchInfo = fmap fst . parseStrictly readPatchInfo unparsePatchInfo :: PatchInfo -> B.ByteString unparsePatchInfo = renderPS . showPatchInfo ForStorage instance Arbitrary PatchInfo where arbitrary = arbitraryUnencodedPatchInfo propParseUnparse :: PatchInfo -> Bool propParseUnparse pi = Just pi == parsePatchInfo (unparsePatchInfo pi) darcs-2.14.5/harness/Darcs/Test/Patch/Properties/0000755000000000000000000000000007346545000017701 5ustar0000000000000000darcs-2.14.5/harness/Darcs/Test/Patch/Properties/Check.hs0000644000000000000000000001035507346545000021256 0ustar0000000000000000{-# LANGUAGE StandaloneDeriving, GeneralizedNewtypeDeriving #-} module Darcs.Test.Patch.Properties.Check ( Check(..), checkAPatch ) where import Prelude () import Darcs.Prelude import Control.Monad ( liftM ) import Darcs.Test.Patch.Check ( PatchCheck, checkMove, removeDir, createDir, isValid, insertLine, fileEmpty, fileExists, deleteLine, modifyFile, createFile, removeFile, doCheck, inconsistent, FileContents(..) ) import Darcs.Patch.RegChars ( regChars ) import Darcs.Util.ByteString ( linesPS ) import qualified Data.ByteString as B ( ByteString, null, concat ) import qualified Data.ByteString.Char8 as BC ( break, pack ) import Darcs.Util.Path ( fn2fp ) import qualified Data.IntMap as M ( mapMaybe ) import Darcs.Patch ( invert, effect, PrimPatch ) import Darcs.Patch.Invert ( Invert ) import Darcs.Patch.V1 ( ) import Darcs.Patch.V1.Core ( RepoPatchV1(..) ) import Darcs.Patch.V2.RepoPatch ( RepoPatchV2, isConsistent ) import qualified Darcs.Patch.V1.Prim as V1 ( Prim(..) ) import qualified Darcs.Patch.V2.Prim as V2 ( Prim(..) ) import Darcs.Patch.V1.Core ( isMerger ) import qualified Darcs.Patch.Prim.FileUUID as FileUUID ( Prim ) import Darcs.Patch.Prim.V1.Core ( Prim(..), DirPatchType(..), FilePatchType(..) ) import Darcs.Patch.Witnesses.Ordered type Prim1 = V1.Prim type Prim2 = V2.Prim class Check p where checkPatch :: p wX wY -> PatchCheck () instance Check p => Check (FL p) where checkPatch NilFL = isValid checkPatch (p :>: ps) = checkPatch p >> checkPatch ps instance Check p => Check (p:>p) where checkPatch (p1 :> p2) = checkPatch p1 >> checkPatch p2 checkAPatch :: (Invert p, Check p) => p wX wY -> Bool checkAPatch p = doCheck $ do checkPatch p checkPatch $ invert p instance PrimPatch prim => Check (RepoPatchV2 prim) where checkPatch p = maybe isValid (const inconsistent) $ isConsistent p instance Check (RepoPatchV1 Prim1) where checkPatch p | isMerger p = checkPatch $ effect p checkPatch (Merger _ _ _ _) = impossible checkPatch (Regrem _ _ _ _) = impossible checkPatch (PP p) = checkPatch p deriving instance Check Prim1 deriving instance Check Prim2 instance Check FileUUID.Prim where checkPatch _ = isValid -- XXX instance Check Prim where checkPatch (FP f RmFile) = removeFile $ fn2fp f checkPatch (FP f AddFile) = createFile $ fn2fp f checkPatch (FP f (Hunk line old new)) = do fileExists $ fn2fp f mapM_ (deleteLine (fn2fp f) line) old mapM_ (insertLine (fn2fp f) line) (reverse new) isValid checkPatch (FP f (TokReplace t old new)) = modifyFile (fn2fp f) (tryTokPossibly t old new) -- note that the above isn't really a sure check, as it leaves PSomethings -- and PNothings which may have contained new... checkPatch (FP f (Binary o n)) = do fileExists $ fn2fp f mapM_ (deleteLine (fn2fp f) 1) (linesPS o) fileEmpty $ fn2fp f mapM_ (insertLine (fn2fp f) 1) (reverse $ linesPS n) isValid checkPatch (DP d AddDir) = createDir $ fn2fp d checkPatch (DP d RmDir) = removeDir $ fn2fp d checkPatch (Move f f') = checkMove (fn2fp f) (fn2fp f') checkPatch (ChangePref _ _ _) = isValid tryTokPossibly :: String -> String -> String -> (Maybe FileContents) -> (Maybe FileContents) tryTokPossibly t o n = liftM $ \contents -> let lines' = M.mapMaybe (liftM B.concat . tryTokInternal t (BC.pack o) (BC.pack n)) (fcLines contents) in contents { fcLines = lines' } tryTokInternal :: String -> B.ByteString -> B.ByteString -> B.ByteString -> Maybe [B.ByteString] tryTokInternal _ _ _ s | B.null s = Just [] tryTokInternal t o n s = case BC.break (regChars t) s of (before,s') -> case BC.break (not . regChars t) s' of (tok,after) -> case tryTokInternal t o n after of Nothing -> Nothing Just rest -> if tok == o then Just $ before : n : rest else if tok == n then Nothing else Just $ before : tok : rest darcs-2.14.5/harness/Darcs/Test/Patch/Properties/Generic.hs0000644000000000000000000005660207346545000021622 0ustar0000000000000000-- Copyright (C) 2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Test.Patch.Properties.Generic ( invertSymmetry, inverseComposition, invertRollback, recommute, commuteInverses, effectPreserving, permutivity, partialPermutivity, patchAndInverseCommute, mergeEitherWay, show_read, mergeCommute, mergeConsistent, mergeArgumentsConsistent, coalesceEffectPreserving, coalesceCommute, propIsMergeable ) where import Darcs.Test.Util.TestResult ( TestResult, succeeded, failed, rejected, (<&&>), fromMaybe ) import Darcs.Test.Patch.RepoModel ( RepoModel, RepoState, repoApply, eqModel, showModel , maybeFail ) import Darcs.Test.Patch.WithState ( WithState(..), WithStartState(..) ) import Darcs.Test.Patch.Arbitrary.Generic ( Tree, flattenOne, MightBeEmptyHunk(..), MightHaveDuplicate(..) ) import Control.Monad ( msum ) import Darcs.Patch.Witnesses.Show ( Show2(..), show2 ) import Darcs.Patch.Read ( ReadPatch ) import Darcs.Patch.Show ( ShowPatchBasic, displayPatch, showPatch, ShowPatchFor(ForStorage) ) import Darcs.Patch.Prim.Class ( PrimPatch, PrimOf, FromPrim ) import Darcs.Patch () import Darcs.Patch.Apply ( Apply, ApplyState ) import Darcs.Patch.Commute ( commute, commuteFL ) import Darcs.Patch.Merge ( Merge(merge) ) import Darcs.Patch.Read ( readPatch ) import Darcs.Patch.Invert ( Invert, invert, invertFL ) import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (:>)(..), (:\/:)(..), (:/\:)(..), lengthFL, eqFL, reverseRL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), seal2, Sealed2 ) import Darcs.Util.Printer ( Doc, renderPS, redText, greenText, ($$), text ) --import Darcs.ColorPrinter ( traceDoc ) propIsMergeable :: forall model p wX . (FromPrim p, Merge p, RepoModel model) => Sealed (WithStartState model (Tree (PrimOf p))) -> Maybe (Tree p wX) propIsMergeable (Sealed (WithStartState _ t)) = case flattenOne t of Sealed ps -> let _ = seal2 ps :: Sealed2 (FL p) in case lengthFL ps of _ -> Nothing -- | invert symmetry inv(inv(p)) = p invertSymmetry :: (Invert p, Eq2 p) => p wA wB -> TestResult invertSymmetry p = case invert (invert p) =\/= p of IsEq -> succeeded NotEq -> failed $ redText "p /= inv(inv(p))" inverseComposition :: (Invert p, Eq2 p) => (p :> p) wX wY -> TestResult inverseComposition (a :> b) = case eqFL (reverseRL (invertFL (a:>:b:>:NilFL))) (invert b:>:invert a:>:NilFL) of IsEq -> succeeded NotEq -> failed $ redText "inv(a :>: b :>: NilFL) /= inv(b) :>: inv(a) :>: NilFL" -- | invert rollback if b = A(a) then a = A'(b) invertRollback :: (Invert p, Apply p, ApplyState p ~ RepoState model, ShowPatchBasic p, RepoModel model) => WithState model p wA wB -> TestResult invertRollback (WithState a x b) = case maybeFail $ repoApply b (invert x) of Nothing -> failed $ redText "x' not applicable to b." Just a1 -> if a1 `eqModel` a then succeeded else failed $ redText "a1: " $$ text (showModel a1) $$ redText " ---- is not equals to a:" $$ text (showModel a) $$ redText "where a was" $$ text (showModel b) $$ redText "with (invert x) on top:" $$ displayPatch (invert x) -- | recommute AB ↔ B′A′ if and only if B′A′ ↔ AB recommute :: (ShowPatchBasic p, Eq2 p, MightHaveDuplicate p) => (forall wX wY . ((p :> p) wX wY -> Maybe ((p :> p) wX wY))) -> (p :> p) wA wB -> TestResult recommute c (x :> y) = case c (x :> y) of Nothing -> rejected Just (y' :> x') -- this test unfortunately fails on some V2 patches that contain duplicates -- after the commute. While in theory the underlying bug should be fixed, -- we don't know how to and even if we did, it would probably involve a repository -- migration to a new patch type. | hasDuplicate y' || hasDuplicate x' -> rejected | otherwise -> case c (y' :> x') of Nothing -> failed (redText "failed, where x" $$ displayPatch x $$ redText ":> y" $$ displayPatch y $$ redText "y'" $$ displayPatch y' $$ redText ":> x'" $$ displayPatch x') Just (x'' :> y'') -> case y'' =/\= y of NotEq -> failed (redText "y'' =/\\= y failed, where x" $$ displayPatch x $$ redText ":> y" $$ displayPatch y $$ redText "y'" $$ displayPatch y' $$ redText ":> x'" $$ displayPatch x' $$ redText "x''" $$ displayPatch x'' $$ redText ":> y''" $$ displayPatch y'') IsEq -> case x'' =/\= x of NotEq -> failed ( redText "x'' /= x, where x" $$ displayPatch x $$ redText ":> y" $$ displayPatch y $$ redText "y'" $$ displayPatch y' $$ redText ":> x'" $$ displayPatch x' $$ redText "x''" $$ displayPatch x'' $$ redText ":> y''" $$ displayPatch y'') IsEq -> succeeded -- | commuteInverses AB ↔ B′A′ if and only if B⁻¹A⁻¹ ↔ A′⁻¹B′⁻¹ commuteInverses :: (Invert p, ShowPatchBasic p, Eq2 p) => (forall wX wY . (p :> p) wX wY -> Maybe ((p :> p) wX wY)) -> (p :> p) wA wB -> TestResult commuteInverses c (x :> y) = case c (x :> y) of Nothing -> rejected Just (y' :> x') -> case c (invert y :> invert x) of Nothing -> failed $ redText "second commute failed" $$ redText "x" $$ displayPatch x $$ redText "y" $$ displayPatch y $$ redText "y'" $$ displayPatch y' $$ redText "x'" $$ displayPatch x' Just (ix' :> iy') -> case invert ix' =/\= x' of NotEq -> failed $ redText "invert ix' /= x'" $$ redText "x" $$ displayPatch x $$ redText "y" $$ displayPatch y $$ redText "y'" $$ displayPatch y' $$ redText "x'" $$ displayPatch x' $$ redText "ix'" $$ displayPatch ix' $$ redText "iy'" $$ displayPatch iy' $$ redText "invert ix'" $$ displayPatch (invert ix') $$ redText "invert iy'" $$ displayPatch (invert iy') IsEq -> case y' =\/= invert iy' of NotEq -> failed $ redText "y' /= invert iy'" $$ displayPatch iy' $$ displayPatch y' IsEq -> succeeded -- | effect preserving AB <--> B'A' then effect(AB) = effect(B'A') effectPreserving :: ( Apply p , MightBeEmptyHunk p , RepoModel model , ApplyState p ~ RepoState model , ShowPatchBasic p ) => (forall wX wY. (p :> p) wX wY -> Maybe ((p :> p) wX wY)) -> WithState model (p :> p) wA wB -> TestResult effectPreserving _ (WithState _ (x :> _) _) | isEmptyHunk x = rejected effectPreserving c (WithState r (x :> y) r') = case c (x :> y) of Nothing -> rejected Just (y' :> x') -> case maybeFail $ repoApply r y' of Nothing -> failed $ redText "##x" $$ displayPatch x $$ redText "##y" $$ displayPatch y $$ redText "##y'" $$ displayPatch y' $$ redText "##x'" $$ displayPatch x' $$ redText "##y' is not applicable to r" $$ displayModel r Just r_y' -> case maybeFail $ repoApply r_y' x' of Nothing -> failed $ redText "##x" $$ displayPatch x $$ redText "##y" $$ displayPatch y $$ redText "##y'" $$ displayPatch y' $$ redText "##x'" $$ displayPatch x' $$ redText "##x' is not applicable to r_y'" $$ displayModel r_y' Just r_y'x' -> if r_y'x' `eqModel` r' then succeeded else failed $ redText "##x" $$ displayPatch x $$ redText "##y" $$ displayPatch y $$ redText "##y'" $$ displayPatch y' $$ redText "##x'" $$ displayPatch x' $$ redText "##r_y'x'" $$ displayModel r_y'x' $$ redText "##is not equal to r'" $$ displayModel r' where displayModel = text . showModel -- | patchAndInverseCommute If AB ↔ B′A′ then A⁻¹B′ ↔ BA′⁻¹ patchAndInverseCommute :: (Invert p, ShowPatchBasic p, Eq2 p) => (forall wX wY. (p :> p) wX wY -> Maybe ((p :> p) wX wY)) -> (p :> p) wA wB -> TestResult patchAndInverseCommute c (x :> y) = case c (x :> y) of Nothing -> rejected Just (y' :> x') -> case c (invert x :> y') of Nothing -> failed $ redText "-------- original (x :> y)" $$ displayPatch x $$ redText ":>" $$ displayPatch y $$ redText "-------- result (y' :> x')" $$ displayPatch y' $$ redText ":>" $$ displayPatch x' $$ redText "-------- failed commute (invert x :> y')" $$ displayPatch (invert x) $$ redText ":>" $$ displayPatch y' Just (y'' :> ix') -> case y'' =\/= y of NotEq -> failed $ redText "y'' /= y" $$ redText "x" $$ displayPatch x $$ redText "y" $$ displayPatch y $$ redText "y'" $$ displayPatch y' $$ redText "x'" $$ displayPatch x' $$ redText "y''" $$ displayPatch y'' $$ redText "ix'" $$ displayPatch ix' IsEq -> case x' =\/= invert ix' of NotEq -> failed $ redText "x' /= invert ix'" $$ redText "x" $$ displayPatch x $$ redText "y" $$ displayPatch y $$ redText "y'" $$ displayPatch y' $$ redText "x'" $$ displayPatch x' $$ redText "invert x" $$ displayPatch (invert x) $$ redText "y'" $$ displayPatch y' $$ redText "invert ix'" $$ displayPatch (invert ix') IsEq -> succeeded permutivity :: (ShowPatchBasic p, Eq2 p) => (forall wX wY . (p :> p) wX wY -> Maybe ((p :> p) wX wY)) -> (p :> p :> p) wA wB -> TestResult permutivity c (x:>y:>z) = case c (x :> y) of Nothing -> rejected Just (y1 :> x1) -> case c (y :> z) of Nothing -> rejected Just (z2 :> y2) -> case c (x :> z2) of Nothing -> rejected Just (z3 :> x3) -> case c (x1 :> z) of Nothing -> failed $ redText "permutivity1" Just (z4 :> x4) -> --traceDoc (greenText "third commuted" $$ -- greenText "about to commute" $$ -- greenText "y1" $$ displayPatch y1 $$ -- greenText "z4" $$ displayPatch z4) $ case c (y1 :> z4) of Nothing -> failed $ redText "permutivity2" Just (z3_ :> y4) | IsEq <- z3_ =\/= z3 -> --traceDoc (greenText "passed z3") $ error "foobar test" $ case c (y4 :> x4) of Nothing -> failed $ redText "permutivity5: input was" $$ redText "x" $$ displayPatch x $$ redText "y" $$ displayPatch y $$ redText "z" $$ displayPatch z $$ redText "z3" $$ displayPatch z3 $$ redText "failed commute of" $$ redText "y4" $$ displayPatch y4 $$ redText "x4" $$ displayPatch x4 $$ redText "whereas commute of x and y give" $$ redText "y1" $$ displayPatch y1 $$ redText "x1" $$ displayPatch x1 Just (x3_ :> y2_) | NotEq <- x3_ =\/= x3 -> failed $ redText "permutivity6" | NotEq <- y2_ =/\= y2 -> failed $ redText "permutivity7" | otherwise -> succeeded | otherwise -> failed $ redText "permutivity failed" $$ redText "z3" $$ displayPatch z3 $$ redText "z3_" $$ displayPatch z3_ partialPermutivity :: (Invert p, ShowPatchBasic p) => (forall wX wY. (p :> p) wX wY -> Maybe ((p :> p) wX wY)) -> (p :> p :> p) wA wB -> TestResult partialPermutivity c (xx :> yy :> zz) = pp (xx :> yy :> zz) <&&> pp (invert zz :> invert yy :> invert xx) where pp (x :> y :> z) = case c (y :> z) of Nothing -> rejected Just (z1 :> y1) -> case c (x :> z1) of Nothing -> rejected Just (_ :> x1) -> case c (x :> y) of Just _ -> rejected -- this is covered by full permutivity test above Nothing -> case c (x1 :> y1) of Nothing -> succeeded Just _ -> failed $ greenText "partialPermutivity error" $$ greenText "x" $$ displayPatch x $$ greenText "y" $$ displayPatch y $$ greenText "z" $$ displayPatch z mergeArgumentsConsistent :: (ShowPatchBasic p) => (forall wX wY . p wX wY -> Maybe Doc) -> (p :\/: p) wA wB -> TestResult mergeArgumentsConsistent isConsistent (x :\/: y) = fromMaybe $ msum [(\z -> redText "mergeArgumentsConsistent x" $$ displayPatch x $$ z) `fmap` isConsistent x, (\z -> redText "mergeArgumentsConsistent y" $$ displayPatch y $$ z) `fmap` isConsistent y] mergeConsistent :: (ShowPatchBasic p, Merge p) => (forall wX wY . p wX wY -> Maybe Doc) -> (p :\/: p) wA wB -> TestResult mergeConsistent isConsistent (x :\/: y) = case merge (x :\/: y) of y' :/\: x' -> fromMaybe $ msum [(\z -> redText "mergeConsistent x" $$ displayPatch x $$ z) `fmap` isConsistent x, (\z -> redText "mergeConsistent y" $$ displayPatch y $$ z) `fmap` isConsistent y, (\z -> redText "mergeConsistent x'" $$ displayPatch x' $$ z $$ redText "where x' comes from x" $$ displayPatch x $$ redText "and y" $$ displayPatch y) `fmap` isConsistent x', (\z -> redText "mergeConsistent y'" $$ displayPatch y' $$ z) `fmap` isConsistent y'] mergeEitherWay :: (Eq2 p, Merge p) => (p :\/: p) wX wY -> TestResult mergeEitherWay (x :\/: y) = case merge (x :\/: y) of y' :/\: x' -> case merge (y :\/: x) of x'' :/\: y'' | IsEq <- x'' =\/= x', IsEq <- y'' =\/= y' -> succeeded | otherwise -> failed $ redText "mergeEitherWay bug" mergeCommute :: (Eq2 p, ShowPatchBasic p, Merge p, MightHaveDuplicate p) => (p :\/: p) wX wY -> TestResult mergeCommute (x :\/: y) = case merge (x :\/: y) of y' :/\: x' -- this test unfortunately fails on some V2 patches that contain duplicates -- after the merge. While in theory the underlying bug should be fixed, -- we don't know how to and even if we did, it would probably involve a repository -- migration to a new patch type. | hasDuplicate x' || hasDuplicate y' -> rejected | otherwise -> case commute (x :> y') of Nothing -> failed $ redText "mergeCommute 1" $$ redText "x" $$ displayPatch x $$ redText "y" $$ displayPatch y $$ redText "x'" $$ displayPatch x' $$ redText "y'" $$ displayPatch y' Just (y_ :> x'_) | IsEq <- y_ =\/= y, IsEq <- x'_ =\/= x' -> case commute (y :> x') of Nothing -> failed $ redText "mergeCommute 2 failed" $$ redText "x" $$ displayPatch x $$ redText "y" $$ displayPatch y $$ redText "x'" $$ displayPatch x' $$ redText "y'" $$ displayPatch y' Just (x_ :> y'_) | IsEq <- x_ =\/= x, IsEq <- y'_ =\/= y' -> succeeded | otherwise -> failed $ redText "mergeCommute 3" $$ redText "x" $$ displayPatch x $$ redText "y" $$ displayPatch y $$ redText "x'" $$ displayPatch x' $$ redText "y'" $$ displayPatch y' $$ redText "x_" $$ displayPatch x_ $$ redText "y'_" $$ displayPatch y'_ | otherwise -> failed $ redText "mergeCommute 4" $$ redText "x" $$ displayPatch x $$ redText "y" $$ displayPatch y $$ redText "x'" $$ displayPatch x' $$ redText "y'" $$ displayPatch y' $$ redText "x'_" $$ displayPatch x'_ $$ redText "y_" $$ displayPatch y_ -- | coalesce effect preserving coalesceEffectPreserving :: (PrimPatch prim, RepoModel model, ApplyState prim ~ RepoState model ) => (forall wX wY . (prim :> prim) wX wY -> Maybe (FL prim wX wY)) -> WithState model (prim :> prim) wA wB -> TestResult coalesceEffectPreserving j (WithState r (a :> b) r') = case j (a :> b) of Nothing -> rejected Just x -> case maybeFail $ repoApply r x of Nothing -> failed $ redText "x is not applicable to r." $$ text (showModel r) $$ displayPatch x $$ redText "a:>b" $$ displayPatch a $$ displayPatch b $$ redText "r'=" $$ text (showModel r') Just r_x -> if r_x `eqModel` r' then succeeded else failed $ redText "r_x /= r', r=" $$ text (showModel r) $$ redText "a:>b=" $$ displayPatch a $$ displayPatch b $$ redText "x=" $$ displayPatch x $$ redText "r'=" $$ text (showModel r') $$ redText "r_x=" $$ text (showModel r_x) coalesceCommute :: (PrimPatch prim, MightBeEmptyHunk prim) => (forall wX wY . (prim :> prim) wX wY -> Maybe (FL prim wX wY)) -> (prim :> prim :> prim) wA wB -> TestResult coalesceCommute _ (a :> _ :> _) | isEmptyHunk a = rejected coalesceCommute j (a :> b :> c) = case j (b :> c) of Nothing -> rejected Just x -> case commuteFL (a :> b :>: c :>: NilFL) of Just (b' :>: c' :>: NilFL :> a') -> case commuteFL (a :> x) of Just (x' :> a'') -> case a'' =/\= a' of NotEq -> failed $ greenText "a'' =/\\= a' failed" $$ display1 $$ display2 IsEq -> case j (b' :> c') of Nothing -> failed $ greenText "coalesce (b':>c') failed" $$ display1 $$ display2 Just x'' -> case x' =\/= x'' of NotEq -> failed $ greenText "x' =\\/= x'' failed" $$ display1 $$ display2 $$ display3 IsEq -> succeeded where display3 = redText "## coalesce (b':>c') => x''" $$ displayPatch x'' where display2 = redText "## commute (a:>x) => x'" $$ displayPatch x' $$ redText "## :> a''" $$ displayPatch a'' _ -> failed $ greenText "commute a x failed" $$ display1 where display1 = redText "## a" $$ displayPatch a $$ redText "## b" $$ displayPatch b $$ redText "## c" $$ displayPatch c $$ redText "## coalesce (b:>c) => x" $$ displayPatch x $$ redText "## commute (a:>b:>c) => a'" $$ displayPatch a' $$ redText "## b'" $$ displayPatch b' $$ redText "## c'" $$ displayPatch c' _ -> rejected -- note: we would normally use displayPatch in the failure message -- but that would be very misleading here show_read :: (Show2 p, Eq2 p, ReadPatch p, ShowPatchBasic p) => p wA wB -> TestResult show_read p = let ps = renderPS (showPatch ForStorage p) in case readPatch ps of Nothing -> failed (redText "unable to read " $$ showPatch ForStorage p) Just (Sealed p' ) | IsEq <- p' =\/= p -> succeeded | otherwise -> failed $ redText "trouble reading patch p" $$ showPatch ForStorage p $$ redText "reads as p'" $$ showPatch ForStorage p' $$ redText "aka" $$ greenText (show2 p) $$ redText "and" $$ greenText (show2 p') -- vim: fileencoding=utf-8 : darcs-2.14.5/harness/Darcs/Test/Patch/Properties/GenericUnwitnessed.hs0000644000000000000000000001071107346545000024042 0ustar0000000000000000module Darcs.Test.Patch.Properties.GenericUnwitnessed where import qualified Darcs.Test.Patch.Properties.Generic as W ( permutivity, partialPermutivity , mergeConsistent, mergeArgumentsConsistent, mergeEitherWay , mergeCommute, patchAndInverseCommute, coalesceCommute, commuteInverses , recommute , show_read ) import Darcs.Test.Patch.Arbitrary.Generic ( Tree, MightBeEmptyHunk, MightHaveDuplicate ) import Darcs.Test.Patch.RepoModel( RepoModel, RepoState ) import Darcs.Test.Patch.WithState( WithStartState ) import qualified Darcs.Test.Patch.Properties.RepoPatchV2 as W ( propConsistentTreeFlattenings ) import Darcs.Test.Patch.WSub import Darcs.Test.Util.TestResult import Darcs.Patch.Invert ( Invert ) import Darcs.Patch.Read ( ReadPatch ) import Darcs.Patch.Show ( ShowPatchBasic, displayPatch ) import Darcs.Patch.Witnesses.Show import Darcs.Patch.Witnesses.Eq import Darcs.Patch.Witnesses.Sealed( Sealed ) import Darcs.Patch.Merge ( Merge ) import Darcs.Util.Printer ( Doc, redText, ($$) ) import qualified Darcs.Util.Tree as T ( Tree ) permutivity :: (ShowPatchBasic wp, Eq2 wp, WSub wp p) => (forall wX wY . (p :> p) wX wY -> Maybe ((p :> p) wX wY)) -> (p :> p :> p) wA wB -> TestResult permutivity f = W.permutivity (fmap toW . f . fromW) . toW partialPermutivity :: (Invert wp, ShowPatchBasic wp, Eq2 wp, WSub wp p) => (forall wX wY . (p :> p) wX wY -> Maybe ((p :> p) wX wY)) -> (p :> p :> p) wA wB -> TestResult partialPermutivity f = W.partialPermutivity (fmap toW . f . fromW) . toW mergeEitherWay :: (ShowPatchBasic wp, Eq2 wp, Merge wp, WSub wp p) => (p :\/: p) wX wY -> TestResult mergeEitherWay = W.mergeEitherWay . toW commuteInverses :: (Invert wp, ShowPatchBasic wp, Eq2 wp, WSub wp p) => (forall wX wY . (p :> p) wX wY -> Maybe ((p :> p) wX wY)) -> (p :> p) wA wB -> TestResult commuteInverses f = W.commuteInverses (fmap toW . f . fromW) . toW recommute :: (ShowPatchBasic wp, MightHaveDuplicate wp, Eq2 wp, WSub wp p) => (forall wX wY . ((p :> p) wX wY -> Maybe ((p :> p) wX wY))) -> (p :> p) wA wB -> TestResult recommute f = W.recommute (fmap toW . f . fromW) . toW mergeCommute :: (MightHaveDuplicate wp, ShowPatchBasic wp, Eq2 wp, Merge wp, WSub wp p) => (p :\/: p) wX wY -> TestResult mergeCommute = W.mergeCommute . toW mergeConsistent :: (Merge wp, ShowPatchBasic wp, WSub wp p) => (forall wX wY . p wX wY -> Maybe Doc) -> (p :\/: p) wA wB -> TestResult mergeConsistent f = W.mergeConsistent (f . fromW) . toW mergeArgumentsConsistent :: (ShowPatchBasic wp, WSub wp p) => (forall wX wY . p wX wY -> Maybe Doc) -> (p :\/: p) wA wB -> TestResult mergeArgumentsConsistent f = W.mergeArgumentsConsistent (f . fromW) . toW show_read :: (ShowPatchBasic p, ReadPatch p, Eq2 p, Show2 p) => p wX wY -> TestResult show_read = W.show_read patchAndInverseCommute :: (Invert wp, ShowPatchBasic wp, Eq2 wp, WSub wp p) => (forall wX wY . (p :> p) wX wY -> Maybe ((p :> p) wX wY)) -> (p :> p) wA wB -> TestResult patchAndInverseCommute f = W.patchAndInverseCommute (fmap toW . f . fromW) . toW coalesceCommute :: MightBeEmptyHunk Prim2 => (forall wX wY . (Prim2 :> Prim2) wX wY -> Maybe (FL Prim2 wX wY)) -> (Prim2 :> Prim2 :> Prim2) wA wB -> TestResult coalesceCommute f = W.coalesceCommute (fmap toW . f . fromW) . toW consistentTreeFlattenings :: (RepoState model ~ T.Tree, RepoModel model) => Sealed (WithStartState model (Tree Prim2)) -> TestResult consistentTreeFlattenings = (\x -> if W.propConsistentTreeFlattenings x then succeeded else failed $ redText "oops") commuteFails :: (Eq2 p, ShowPatchBasic p) => ((p :> p) wX wY -> Maybe ((p :> p) wX wY)) -> (p :> p) wX wY -> TestResult commuteFails c (x :> y) = case c (x :> y) of Nothing -> succeeded Just (y' :> x') -> failed $ redText "x" $$ displayPatch x $$ redText ":> y" $$ displayPatch y $$ redText "y'" $$ displayPatch y' $$ redText ":> x'" $$ displayPatch x' darcs-2.14.5/harness/Darcs/Test/Patch/Properties/RepoPatchV2.hs0000644000000000000000000000346207346545000022337 0ustar0000000000000000module Darcs.Test.Patch.Properties.RepoPatchV2 ( propConsistentTreeFlattenings ) where import Prelude () import Darcs.Prelude import Data.Maybe ( fromJust ) import Darcs.Test.Patch.Arbitrary.Generic ( Tree, flattenTree, G2(..), mapTree ) import Darcs.Test.Patch.WithState import Darcs.Test.Patch.RepoModel ( RepoModel, repoApply, showModel, eqModel, RepoState , Fail, maybeFail ) import qualified Darcs.Util.Tree as T ( Tree ) import Darcs.Patch.Prim ( fromPrim ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..) ) import qualified Darcs.Patch.V2.Prim as V2 ( Prim ) import Darcs.Patch.V2 ( RepoPatchV2 ) type Prim2 = V2.Prim fromPrim2 :: Prim2 wX wY -> RepoPatchV2 Prim2 wX wY fromPrim2 = fromPrim assertEqualFst :: (RepoModel a, Show b, Show c) => (Fail (a x), b) -> (Fail (a x), c) -> Bool assertEqualFst (x,bx) (y,by) | Just x' <- maybeFail x, Just y' <- maybeFail y, x' `eqModel` y' = True | Nothing <- maybeFail x, Nothing <- maybeFail y = True | otherwise = error ("Not really equal:\n" ++ showx ++ "\nand\n" ++ showy ++ "\ncoming from\n" ++ show bx ++ "\nand\n" ++ show by) where showx | Just x' <- maybeFail x = showModel x' | otherwise = "Nothing" showy | Just y' <- maybeFail y = showModel y' | otherwise = "Nothing" propConsistentTreeFlattenings :: (RepoState model ~ T.Tree, RepoModel model) => Sealed (WithStartState model (Tree Prim2)) -> Bool propConsistentTreeFlattenings (Sealed (WithStartState start t)) = fromJust $ do Sealed (G2 flat) <- return $ flattenTree $ mapTree fromPrim2 t rms <- return $ map (start `repoApply`) flat return $ and $ zipWith assertEqualFst (zip rms flat) (tail $ zip rms flat) darcs-2.14.5/harness/Darcs/Test/Patch/Properties/V1Set1.hs0000644000000000000000000001542107346545000021263 0ustar0000000000000000module Darcs.Test.Patch.Properties.V1Set1 ( checkMerge, checkMergeEquiv, checkMergeSwap, checkCanon , checkCommute, checkCantCommute , tShowRead , tMergeEitherWayValid, tTestCheck ) where import Darcs.Patch ( commute, invert, merge, effect , readPatch, showPatch , fromPrim, canonize, sortCoalesceFL ) import Darcs.Patch.Invert ( Invert ) import Darcs.Patch.Merge ( Merge ) import Darcs.Patch.Read ( ReadPatch ) import Darcs.Patch.Show ( ShowPatchBasic, ShowPatchFor(..) ) import qualified Darcs.Patch.V1 as V1 ( RepoPatchV1 ) import qualified Darcs.Patch.V1.Prim as V1 ( Prim(..) ) import Darcs.Test.Patch.Properties.Check ( checkAPatch, Check ) import Darcs.Util.Printer ( renderPS ) import Darcs.Patch.Witnesses.Eq import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Show import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed) ) import Darcs.Patch.Witnesses.Unsafe( unsafeCoercePEnd ) import Darcs.Test.Util.TestResult import qualified Darcs.Util.Diff as D (DiffAlgorithm(..)) import Darcs.Util.Printer ( text ) type Patch = V1.RepoPatchV1 V1.Prim quickmerge :: (Merge p) => (p :\/: p ) wX wY -> p wY wZ quickmerge (p1:\/:p2) = case merge (p1:\/:p2) of _ :/\: p1' -> unsafeCoercePEnd p1' instance Eq2 p => Eq ((p :/\: p) wX wY) where (x :/\: y) == (x' :/\: y') = isIsEq (x =\/= x') && isIsEq (y =\/= y') -- ---------------------------------------------------------------------------- -- A number of "comparison" properties: these carry out some operation on -- inputs (first value in the pair) and compare the results with a known -- expected value (the second value in the pair). -- checkMerge :: ((FL Patch:\/: FL Patch) wX wY, FL Patch wY wZ) -> TestResult checkMerge (p1:\/:p2,p1') = case merge (p1:\/:p2) of _ :/\: p1a -> if isIsEq (p1a `eqFL` p1') then succeeded else failed $ text $ "Merge gave wrong value!\n"++show p1++show p2 ++"I expected\n"++show p1' ++"but found instead\n"++show p1a checkMergeEquiv :: ((FL Patch:\/:FL Patch) wX wY,FL Patch wY wZ) -> TestResult checkMergeEquiv (p1:\/: p2, pe) = case quickmerge (p1:\/:p2) of p1' -> if checkAPatch (invert p1 :>: p2 :>: p1' :>: invert pe :>: NilFL) then succeeded else failed $ text $ "Oh no, merger isn't equivalent...\n"++show p1++"\n"++show p2 ++"in other words\n" ++ show (p1 :\/: p2) ++"merges as\n" ++ show (merge $ p1 :\/: p2) ++"merges to\n" ++ show (quickmerge $ p1 :\/: p2) ++"which is equivalent to\n" ++ show (effect p1') ++ "should all work out to\n" ++ show pe checkMergeSwap :: (FL Patch wX wY, FL Patch wX wZ) -> TestResult checkMergeSwap (p1, p2) = case merge (p2:\/:p1) of _ :/\: p2' -> case merge (p1:\/:p2) of _ :/\: p1' -> case commute (p1 :> p2') of Just (_ :> p1'b) -> if not $ p1'b `eqFLUnsafe` p1' then failed $ text $ "Merge swapping problem with...\np1 "++ show p1++"merged with\np2 "++ show p2++"p1' is\np1' "++ show p1'++"p1'b is\np1'b "++ show p1'b else succeeded Nothing -> failed $ text $ "Merge commuting problem with...\np1 "++ show p1++"merged with\np2 "++ show p2++"gives\np2' "++ show p2'++"which doesn't commute with p1.\n" checkCanon :: forall wX wY . (FL Patch wX wY, FL Patch wX wY) -> TestResult checkCanon (p1,p2) = if isIsEq $ eqFL p1_ p2 then if isIsEq $ eqFL p1_p p2 then succeeded else failed $ text $ "Canonization with Patience Diff failed:\n"++show p1++"canonized is\n" ++show (p1_p :: FL Patch wX wY) ++"which is not\n"++show p2 else failed $ text $ "Canonization with Myers Diff failed:\n"++show p1++"canonized is\n" ++show (p1_ :: FL Patch wX wY) ++"which is not\n"++show p2 where p1_ = mapFL_FL fromPrim $ concatFL $ mapFL_FL (canonize D.MyersDiff) $ sortCoalesceFL $ effect p1 p1_p = mapFL_FL fromPrim $ concatFL $ mapFL_FL (canonize D.PatienceDiff) $ sortCoalesceFL $ effect p1 checkCommute :: ((FL Patch :> FL Patch) wX wY, (FL Patch :> FL Patch) wX wY) -> TestResult checkCommute (p2 :> p1,p1' :> p2') = case commute (p2 :> p1) of Just (p1a :> p2a) -> if (p1a :> p2a) == (p1' :> p2') then succeeded else failed $ text $ "Commute gave wrong value!\n"++show p1++"\n"++show p2 ++"should be\n"++show p2'++"\n"++show p1' ++"but is\n"++show p2a++"\n"++show p1a Nothing -> failed $ text $ "Commute failed!\n"++show p1++"\n"++show p2 <&&> case commute (p1' :> p2') of Just (p2a :> p1a) -> if (p2a :> p1a) == (p2 :> p1) then succeeded else failed $ text $ "Commute gave wrong value!\n"++show p2a++"\n"++show p1a ++"should have been\n"++show p2'++"\n"++show p1' Nothing -> failed $ text $ "Commute failed!\n"++show p2'++"\n"++show p1' checkCantCommute :: (FL Patch :> FL Patch) wX wY -> TestResult checkCantCommute (p2 :> p1) = case commute (p2 :> p1) of Nothing -> succeeded _ -> failed $ text $ show p1 ++ "\n\n" ++ show p2 ++ "\nArgh, these guys shouldn't commute!\n" -- ---------------------------------------------------------------------------- -- A few "test" properties, doing things with input patches and giving a OK/not -- OK type of answer. tShowRead :: (Show2 p, ReadPatch p, ShowPatchBasic p) => (forall wX wY wW wZ . p wX wY -> p wW wZ -> Bool) -> forall wX wY . p wX wY -> TestResult tShowRead eq p = case readPatch $ renderPS $ showPatch ForStorage p of Just (Sealed p') -> if p' `eq` p then succeeded else failed $ text $ "Failed to read shown: "++(show2 p)++"\n" Nothing -> failed $ text $ "Failed to read at all: "++(show2 p)++"\n" tMergeEitherWayValid :: forall wX wY p . (Check p, Show2 p, Merge p, Invert p) => (p :\/: p) wX wY -> TestResult tMergeEitherWayValid (p1 :\/: p2) = case p2 :>: quickmerge (p1:\/: p2) :>: NilFL of combo2 -> case p1 :>: quickmerge (p2:\/: p1) :>: NilFL of combo1 -> if not $ checkAPatch combo1 then failed $ text $ "oh my combo1 invalid:\n"++show2 p1++"and...\n"++show2 p2++show combo1 else if checkAPatch (invert combo1 :>: combo2 :>: NilFL) then succeeded else failed $ text $ "merge both ways invalid:\n"++show2 p1++"and...\n"++show2 p2++ show combo1++ show combo2 tTestCheck :: forall wX wY . FL Patch wX wY -> TestResult tTestCheck p = if checkAPatch p then succeeded else failed $ text $ "Failed the check: "++show p++"\n" darcs-2.14.5/harness/Darcs/Test/Patch/Properties/V1Set2.hs0000644000000000000000000003620307346545000021265 0ustar0000000000000000-- Copyright (C) 2002-2003,2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Test.Patch.Properties.V1Set2 ( propCommuteInverse, propPatchAndInverseIsIdentity , propSimpleSmartMergeGoodEnough, propCommuteEquivalency , propMergeValid, propInverseValid, propOtherInverseValid , propCommuteEitherOrder , propCommuteEitherWay, propCommuteTwice , propMergeIsCommutableAndCorrect, propMergeIsSwapable , checkSubcommutes , subcommutesInverse, subcommutesNontrivialInverse, subcommutesFailure , propReadShow -- TODO: these are exported temporarily to mark them as used -- Figure out whether to enable or remove the tests. , propUnravelThreeMerge, propUnravelSeqMerge , propUnravelOrderIndependent, propResolveConflictsValid ) where import Prelude () import Darcs.Prelude import Test.QuickCheck import Test.Framework.Providers.QuickCheck2 ( testProperty ) import Test.Framework ( Test ) import Data.Maybe ( isJust ) import Darcs.Test.Patch.Properties.Check ( Check, checkAPatch ) import Darcs.Patch ( invert, commute, merge, readPatch, resolveConflicts, fromPrim, showPatch, ShowPatchFor(..) ) import Darcs.Patch.Commute ( Commute ) import Darcs.Patch.Invert ( Invert ) import qualified Darcs.Patch.V1 as V1 ( RepoPatchV1 ) import qualified Darcs.Patch.V1.Prim as V1 ( Prim(..) ) import Darcs.Patch.V1.Commute ( unravel, merger ) import Darcs.Patch.Prim.V1 ( Prim ) import Darcs.Patch.Prim.V1.Commute ( Perhaps(..) , toPerhaps , speedyCommute , cleverCommute , commuteFiledir , commuteFilepatches ) import Darcs.Util.Printer ( renderPS ) import Darcs.Patch.Witnesses.Eq import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), unsafeUnseal, unseal, mapSeal, Sealed2(..) ) import Darcs.Patch.Witnesses.Unsafe type Prim1 = V1.Prim type Patch = V1.RepoPatchV1 Prim1 -- | Groups a set of tests by giving them the same prefix in their description. -- When this is called as @checkSubcommutes subcoms expl@, the prefix for a -- test becomes @"Checking " ++ expl ++ " for subcommute "@. checkSubcommutes :: Testable a => [(String, a)] -> String -> [Test] checkSubcommutes subcoms expl = map check_subcommute subcoms where check_subcommute (name, test) = let testName = expl ++ " for subcommute " ++ name in testProperty testName test propInverseValid :: Sealed2 (FL Patch) -> Bool propInverseValid (Sealed2 p1) = checkAPatch (invert p1:>:p1:>:NilFL) propOtherInverseValid :: Sealed2 (FL Patch) -> Bool propOtherInverseValid (Sealed2 p1) = checkAPatch (p1:>:invert p1:>:NilFL) propCommuteTwice :: Sealed2 (FL Patch :> FL Patch) -> Property propCommuteTwice (Sealed2 (p1:>p2)) = (doesCommute p1 p2) ==> (Just (p1:>p2) == (commute (p1:>p2) >>= commute)) doesCommute :: (Eq2 p, Invert p, Commute p, Check p) => p wX wY -> p wY wZ -> Bool doesCommute p1 p2 = commute (p1:>p2) /= Nothing && checkAPatch (p1:>:p2:>:NilFL) propCommuteEquivalency :: Sealed2 (FL Patch :> FL Patch) -> Property propCommuteEquivalency (Sealed2 (p1:>p2)) = (doesCommute p1 p2) ==> case commute (p1:>p2) of Just (p2':>p1') -> checkAPatch (p1:>:p2:>:invert p1':>:invert p2':>:NilFL) _ -> impossible propCommuteEitherWay :: Sealed2 (FL Patch :> FL Patch) -> Property propCommuteEitherWay (Sealed2 (p1:>p2)) = doesCommute p1 p2 ==> doesCommute (invert p2) (invert p1) propCommuteEitherOrder :: Sealed2 (FL Patch :> FL Patch :> FL Patch) -> Property propCommuteEitherOrder (Sealed2 (p1:>p2:>p3)) = checkAPatch (p1:>:p2:>:p3:>:NilFL) && doesCommute p1 (p2+>+p3) && doesCommute p2 p3 ==> case commute (p1:>p2) of Nothing -> False Just (p2':>p1') -> case commute (p1':>p3) of Nothing -> False Just (p3':>_) -> case commute (p2':>p3') of Nothing -> False Just (p3'' :> _) -> case commute (p2:>p3) of Nothing -> False Just (p3'a:>_) -> case commute (p1:>p3'a) of Just (p3''a:>_) -> isIsEq (p3''a =\/= p3'') Nothing -> False propPatchAndInverseIsIdentity :: Sealed2 (FL Patch :> FL Patch) -> Property propPatchAndInverseIsIdentity (Sealed2 (p1:>p2)) = checkAPatch (p1:>:p2:>:NilFL) && (commute (p1:>p2) /= Nothing) ==> case commute (p1:>p2) of Just (p2':>_) -> case commute (invert p1:>p2') of Nothing -> True -- This is a subtle distinction. Just (p2'':>_) -> isIsEq (p2'' =\/= p2) Nothing -> impossible propMergeIsCommutableAndCorrect :: Sealed2 (FL Patch :\/: FL Patch) -> Property propMergeIsCommutableAndCorrect (Sealed2 (p1:\/:p2)) = checkAPatch (invert p1:>:p2:>:NilFL) ==> case merge (p2:\/:p1) of p1' :/\: p2' -> case commute (p1:>p2') of Nothing -> False Just (p2'':>p1'') -> isIsEq (p2'' =\/= p2) && isIsEq (p1' =/\= p1'') propMergeIsSwapable :: Sealed2 (FL Patch :\/: FL Patch) -> Property propMergeIsSwapable (Sealed2 (p1:\/:p2)) = checkAPatch (invert p1:>:p2:>:NilFL) ==> case merge (p2:\/:p1) of p1' :/\: p2' -> case merge (p1:\/:p2) of p2''' :/\: p1''' -> isIsEq (p1' =\/= p1''') && isIsEq (p2' =\/= p2''') propMergeValid :: Sealed2 (FL Patch :\/: FL Patch) -> Property propMergeValid (Sealed2 (p1:\/:p2)) = checkAPatch (invert p1:>:p2:>:NilFL) ==> case merge (p2:\/:p1) of _ :/\: p2' -> checkAPatch (invert p1:>:p2:>:invert p2:>:p1:>:p2':>:NilFL) propSimpleSmartMergeGoodEnough :: Sealed2 (FL Patch :\/: FL Patch) -> Property propSimpleSmartMergeGoodEnough (Sealed2 (p1:\/:p2)) = checkAPatch (invert p1:>:p2:>:NilFL) ==> case simpleSmartMerge (p1 :\/: p2) of Nothing -> True Just (Sealed p1'a) -> isJust ((do p1o :> _ <- commute (p2 :> p1'a) IsEq <- return $ p1o =\/= p1 Sealed p2'a <- simpleSmartMerge (p2 :\/: p1) p2b :> p1'b <- commute (p1 :> p2'a) IsEq <- return $ p2 =\/= p2b IsEq <- return $ p1'a =\/= p1'b return ()) :: Maybe ()) simpleSmartMerge :: (Commute p, Invert p) => (p :\/: p) wX wY -> Maybe (Sealed (p wY)) simpleSmartMerge (p1 :\/: p2) = case commute (invert p2 :> p1) of Just (p1':>_) -> Just (Sealed p1') Nothing -> Nothing -- | The conflict resolution code (glump) begins by "unravelling" the merger -- into a set of sequences of patches. Each sequence of patches corresponds -- to one non-conflicted patch that got merged together with the others. The -- result of the unravelling of a series of merges must obviously be -- independent of the order in which those merges are performed. This -- unravelling code (which uses the unwind code mentioned above) uses probably -- the second most complicated algorithm. Fortunately, if we can successfully -- unravel the merger, almost any function of the unravelled merger satisfies -- the two constraints mentioned above that the conflict resolution code must -- satisfy. propUnravelThreeMerge :: Patch wX wY -> Patch wX wZ -> Patch wX wW -> Property propUnravelThreeMerge p1 p2 p3 = checkAPatch (invert p1:>:p2:>:invert p2:>:p3:>:NilFL) ==> (unravel $ unsafeUnseal $ merger "0.0" (unsafeUnseal (merger "0.0" p2 p3)) (unsafeUnseal (merger "0.0" p2 p1))) == (unravel $ unsafeUnseal $ merger "0.0" (unsafeUnseal (merger "0.0" p1 p3)) (unsafeUnseal (merger "0.0" p1 p2))) propUnravelSeqMerge :: Patch wX wY -> Patch wX wZ -> Patch wZ wW -> Property propUnravelSeqMerge p1 p2 p3 = checkAPatch (invert p1:>:p2:>:p3:>:NilFL) ==> (unravel $ unsafeUnseal $ merger "0.0" p3 $ unsafeUnseal $ merger "0.0" p2 p1) == (unravel $ unsafeUnseal $ merger "0.0" (unsafeUnseal $ merger "0.0" p2 p1) p3) propUnravelOrderIndependent :: Patch wX wY -> Patch wX wZ -> Property propUnravelOrderIndependent p1 p2 = checkAPatch (invert p1:>:p2:>:NilFL) ==> (unravel $ unsafeCoercePStart $ unsafeUnseal $ merger "0.0" p2 p1) == (unravel $ unsafeUnseal $ merger "0.0" p1 p2) propResolveConflictsValid :: Patch wX wY -> Patch wX wZ -> Property propResolveConflictsValid p1 p2 = case merge (p1:\/:p2) of _ :/\: p1' -> let p = p2:>:p1':>:NilFL in checkAPatch (invert p1:>:p2:>:NilFL) ==> and $ map (\l -> (\ml -> checkAPatch (p+>+ml)) `unseal` mergeList l) $ resolveConflicts p mergeList :: [Sealed (FL Prim1 wX)] -> Sealed (FL Patch wX) mergeList patches = mapFL_FL fromPrim `mapSeal` doml NilFL patches where doml :: FL Prim1 wX wY -> [Sealed (FL Prim1 wX)] -> Sealed (FL Prim1 wX) doml mp (Sealed p:ps) = case commute (invert p :> mp) of Just (mp' :> _) -> doml (p +>+ mp') ps Nothing -> doml mp ps -- This shouldn't happen for "good" resolutions. doml mp [] = Sealed mp propReadShow :: FL Patch wX wY -> Bool propReadShow p = case readPatch $ renderPS $ showPatch ForStorage p of Just (Sealed p') -> isIsEq (p' =\/= p) Nothing -> False -- |In order for merges to work right with commuted patches, inverting a patch -- past a patch and its inverse had golly well better give you the same patch -- back again. propCommuteInverse :: Sealed2 (FL Patch :> FL Patch) -> Property propCommuteInverse (Sealed2 (p1 :> p2)) = doesCommute p1 p2 ==> case commute (p1 :> p2) of Nothing -> impossible Just (_ :> p1') -> case commute (p1' :> invert p2) of Nothing -> False Just (_ :> p1'') -> isIsEq (p1'' =/\= p1) type CommuteProperty = Sealed2 (Prim1 :> Prim1) -> Property type CommuteFunction = forall wX wY . (Prim1 :> Prim1) wX wY -> Perhaps ((Prim1 :> Prim1) wX wY) newtype WrappedCommuteFunction = WrappedCommuteFunction { runWrappedCommuteFunction :: CommuteFunction } wrapCommuteFunction :: (forall wX wY . (Prim :> Prim) wX wY -> Perhaps ((Prim :> Prim) wX wY)) -> WrappedCommuteFunction wrapCommuteFunction f = WrappedCommuteFunction $ \(p :> q) -> do q' :> p' <- f (V1.unPrim p :> V1.unPrim q) return (V1.Prim q' :> V1.Prim p') subcommutes :: [(String, WrappedCommuteFunction)] subcommutes = [("speedyCommute", wrapCommuteFunction speedyCommute), ("commuteFiledir", wrapCommuteFunction (cleverCommute commuteFiledir)), ("commuteFilepatches", wrapCommuteFunction (cleverCommute commuteFilepatches)), ("commutex", wrapCommuteFunction (toPerhaps . commute)) ] subcommutesInverse :: [(String, CommuteProperty)] subcommutesInverse = zip names (map prop_subcommute cs) where (names, cs) = unzip subcommutes prop_subcommute c (Sealed2 (p1:>p2)) = does c p1 p2 ==> case runWrappedCommuteFunction c (p1 :> p2) of Succeeded (p2' :> p1') -> case runWrappedCommuteFunction c (p1' :> invert p2) of Succeeded (ip2x' :> p1'') -> isIsEq (p1'' =/\= p1) && case runWrappedCommuteFunction c (invert p2 :> invert p1 ) of Succeeded (ip1' :> ip2') -> case runWrappedCommuteFunction c (invert p1 :> p2') of Succeeded (p2o :> ip1o') -> isJust ((do IsEq <- return $ invert ip1' =/\= p1' IsEq <- return $ invert ip2' =/\= p2' IsEq <- return $ ip1o' =/\= ip1' IsEq <- return $ p2o =\/= p2 IsEq <- return $ p1'' =/\= p1 IsEq <- return $ ip2x' =\/= ip2' return ()) :: Maybe ()) _ -> False _ -> False _ -> False _ -> False subcommutesNontrivialInverse :: [(String, CommuteProperty)] subcommutesNontrivialInverse = zip names (map prop_subcommute cs) where -- speedyCommute will never be "nontrivial" (names, cs) = unzip . filter ((/= "speedyCommute") . fst) $ subcommutes prop_subcommute c (Sealed2 (p1 :> p2)) = nontrivial c p1 p2 ==> case runWrappedCommuteFunction c (p1 :> p2) of Succeeded (p2' :> p1') -> case runWrappedCommuteFunction c (p1' :> invert p2) of Succeeded (ip2x' :> p1'') -> isIsEq (p1'' =/\= p1) && case runWrappedCommuteFunction c (invert p2 :> invert p1) of Succeeded (ip1' :> ip2') -> case runWrappedCommuteFunction c (invert p1 :> p2') of Succeeded (p2o :> ip1o') -> isJust ((do IsEq <- return $ invert ip1' =/\= p1' IsEq <- return $ invert ip2' =/\= p2' IsEq <- return $ ip1o' =/\= ip1' IsEq <- return $ p2o =\/= p2 IsEq <- return $ p1'' =/\= p1 IsEq <- return $ ip2x' =\/= ip2' return ()) :: Maybe ()) _ -> False _ -> False _ -> False _ -> False subcommutesFailure :: [(String, CommuteProperty)] subcommutesFailure = zip names (map prop cs) where -- speedyCommute will never fail (it just returns "Unknown") (names, cs) = unzip . filter ((/= "speedyCommute") . fst) $ subcommutes prop c (Sealed2 (p1 :> p2)) = doesFail c p1 p2 ==> case runWrappedCommuteFunction c (invert p2 :> invert p1 ) of Failed -> True _ -> False doesFail :: WrappedCommuteFunction -> Prim1 wX wY -> Prim1 wY wZ -> Bool doesFail c p1 p2 = fails (runWrappedCommuteFunction c (p1 :> p2)) && checkAPatch (p1 :>: p2 :>: NilFL) where fails Failed = True fails _ = False does :: WrappedCommuteFunction -> Prim1 wX wY -> Prim1 wY wZ -> Bool does c p1 p2 = succeeds (runWrappedCommuteFunction c (p1 :> p2)) && checkAPatch (p1 :>: p2 :>: NilFL) where succeeds (Succeeded _) = True succeeds _ = False nontrivial :: WrappedCommuteFunction -> Prim1 wX wY -> Prim1 wY wZ -> Bool nontrivial c p1 p2 = succeeds (runWrappedCommuteFunction c (p1 :> p2)) && checkAPatch (p1 :>: p2 :>: NilFL) where succeeds (Succeeded (p2' :> p1' )) = not (p1' `unsafeCompare` p1 && p2' `unsafeCompare` p2) succeeds _ = False darcs-2.14.5/harness/Darcs/Test/Patch/Rebase.hs0000644000000000000000000000255107346545000017305 0ustar0000000000000000{-# LANGUAGE EmptyDataDecls #-} module Darcs.Test.Patch.Rebase ( testSuite ) where import Control.Monad ( unless ) import Test.Framework ( Test ) import Test.Framework.Providers.HUnit ( testCase ) import Test.HUnit ( assertFailure ) import Darcs.Patch import Darcs.Patch.Conflict import Darcs.Patch.Rebase.Fixup import Darcs.Patch.Rebase.Viewing import Darcs.Patch.Type import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Show import Darcs.Test.Patch.Arbitrary.Generic testSuite :: forall rt p . (RepoPatch p, ArbitraryPrim (PrimOf p), Show2 (PrimOf p)) => PatchType rt p -> [Test] testSuite pt = if hasPrimConstruct (undefined :: PrimOf p WX WX) then [ duplicateConflictedEffect pt ] else [ ] data WX duplicateConflictedEffect :: forall rt p . (RepoPatch p, Show2 (PrimOf p)) => PatchType rt p -> Test duplicateConflictedEffect _ = testCase "duplicate in rebase fixup has a conflicted effect" $ unless (all (/= Okay) cStatuses) $ assertFailure ("unexpected conflicted effect: " ++ show cEffect) where corePrim = addfile "./file" rebase :: RebaseChange p WX WX rebase = RCFwd (PrimFixup (invert corePrim) :>: NilFL) (fromPrim corePrim :>: NilFL) cEffect = conflictedEffect rebase cStatuses = map (\(IsC status _) -> status) cEffect darcs-2.14.5/harness/Darcs/Test/Patch/RepoModel.hs0000644000000000000000000000205507346545000017771 0ustar0000000000000000module Darcs.Test.Patch.RepoModel where import Darcs.Patch.Apply ( Apply, ApplyState ) import Darcs.Patch.Witnesses.Ordered ( FL ) import Test.QuickCheck ( Gen ) data Fail a = Failed String | OK a deriving (Eq, Show) instance Functor Fail where fmap _ (Failed s) = Failed s fmap f (OK v) = OK (f v) instance Applicative Fail where pure = OK Failed s <*> _ = Failed s _ <*> Failed s = Failed s OK f <*> OK v = OK (f v) instance Monad Fail where return = OK Failed s >>= _ = Failed s OK v >>= f = f v unFail :: Fail t -> t unFail (OK x) = x unFail (Failed err) = error $ "unFail failed: " ++ err maybeFail :: Fail a -> Maybe a maybeFail (OK x) = Just x maybeFail _ = Nothing class RepoModel model where type RepoState model :: (* -> *) -> * showModel :: model x -> String eqModel :: model x -> model x -> Bool aSmallRepo :: Gen (model x) repoApply :: (Apply p, ApplyState p ~ RepoState model) => model x -> p x y -> Fail (model y) type family ModelOf (patch :: * -> * -> *) :: * -> * type instance ModelOf (FL prim) = ModelOf prim darcs-2.14.5/harness/Darcs/Test/Patch/Selection.hs0000644000000000000000000000457007346545000020034 0ustar0000000000000000-- Copyright (C) 2016 G. Hoffmann module Darcs.Test.Patch.Selection ( testSuite ) where import Test.Framework (Test, testGroup) import Test.Framework.Providers.HUnit ( testCase ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (:>)(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Patch.V2 ( RepoPatchV2 ) import qualified Darcs.Patch.V2.Prim as V2 import Darcs.Patch.RepoType ( RepoType(..), RebaseType(..) ) import Darcs.UI.SelectChanges ( PatchSelectionOptions(..) , selectionContext , runSelection , WhichChanges(..) ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd(..) ) import Darcs.Patch.Info ( rawPatchInfo ) import Darcs.UI.Options.All ( Verbosity(..), Summary(..) , WithContext(..), SelectDeps(..), MatchFlag(..) ) -- A test module for interactive patch selection. type Patch = RepoPatchV2 V2.Prim testSuite :: Test testSuite = testGroup "Darcs.Patch.Selection" $ [ dontReadContents whch | whch <- [Last, LastReversed, First, FirstReversed] ] dontReadContents :: WhichChanges -> Test dontReadContents whch = testCase ("Matching on patch metadata does not open patch contents: " ++ show whch) $ do let -- here is an FL of patches whose metadata can be read but whose contents -- should NEVER be read, otherwise something really bad would happen. launchNuclearMissilesPatches = unsafeCoerceP $ lnmPatches [ "P " ++ show i | i <- [1..5::Int] ] lnmPatches [] = NilFL lnmPatches (n:names) = buildPatch n :>: lnmPatches names buildPatch :: String -> PatchInfoAnd ('RepoType 'NoRebase) Patch wX wY buildPatch name = PIAP (rawPatchInfo "1999" name "harness" [] False) (error "Patch content read!") pso = PatchSelectionOptions { verbosity = Quiet , matchFlags = [OnePatch "."] -- match on every patch , interactive = False , selectDeps = AutoDeps , summary = NoSummary , withContext = NoContext } context = selectionContext whch "select" pso Nothing Nothing (unselected :> selected) <- runSelection launchNuclearMissilesPatches context -- Forcing selection to happen (at least to the point of knowing whether unselected -- and unselected are NilFL or not) should not evaluate the `undefined` inside of our -- patches, ie, we don't need to read too much. unselected `seq` selected `seq` return () darcs-2.14.5/harness/Darcs/Test/Patch/Utils.hs0000644000000000000000000000203407346545000017200 0ustar0000000000000000module Darcs.Test.Patch.Utils ( testConditional, testStringList ) where import Test.Framework ( Test, TestName ) import Test.Framework.Providers.HUnit ( testCase ) import Test.Framework.Providers.QuickCheck2 ( testProperty ) import Test.HUnit ( assertFailure ) import Test.QuickCheck ( Arbitrary, Testable, (==>) ) -- | Turns a condition and a test function into a conditional quickcheck -- property that can be run by test-framework. testConditional :: (Arbitrary a, Show a, Testable prop) => TestName -- ^ Test name -> (a -> Bool) -- ^ Condition -> (a -> prop) -- ^ Test function -> Test testConditional name cond t = testProperty name t' where t' x = cond x ==> t x -- | Utility function to run old tests that return a list of error messages, -- with the empty list meaning success. testStringList :: String -> [String] -> Test testStringList name test = testCase name $ mapM_ assertFailure test darcs-2.14.5/harness/Darcs/Test/Patch/V1Model.hs0000644000000000000000000002112307346545000017347 0ustar0000000000000000-- | Repository model module Darcs.Test.Patch.V1Model ( V1Model, repoTree , RepoItem, File, Dir, Content , makeRepo, emptyRepo , makeFile, emptyFile , emptyDir , nullRepo , isFile, isDir , fileContent, dirContent , isEmpty , root , filterFiles, filterDirs , find , list , ap2fp , aFilename, aDirname , aLine, aContent , aFile, aDir , aRepo ) where import Prelude () import Darcs.Prelude import Darcs.Test.Util.QuickCheck ( alpha, uniques, bSized ) import Darcs.Test.Patch.RepoModel import Darcs.Patch.Apply( applyToTree ) import Darcs.Patch.Witnesses.Sealed ( Sealed, seal ) import Darcs.Patch.Witnesses.Show import Darcs.Util.Path import Darcs.Util.Tree( Tree, TreeItem ) import Darcs.Util.Tree.Hashed ( darcsUpdateHashes ) import qualified Darcs.Util.Tree as T import Control.Arrow ( second ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as BLC import qualified Data.Map as M import Test.QuickCheck ( Arbitrary(..) , Gen, choose, vectorOf, frequency ) -- import Text.Show.Pretty ( ppShow ) ---------------------------------------------------------------------- -- * Model definition -- | A repository is an abstraction build in top of a 'Tree'. -- NB: Repository preferences are not supported yet. newtype V1Model wX = V1Model { repoTree :: Tree Fail } -- | Repository items may be text files or directories. -- NB: Binary files are not supported yet. newtype RepoItem = RepoItem { treeItem :: TreeItem Fail } type File = RepoItem type Dir = RepoItem type Content = [B.ByteString] ---------------------------------------- -- Instances data FlatItem = Dir FilePath | File FilePath [String] deriving Show flattenTree :: Tree Fail -> [FlatItem] flattenTree = map flattenEntry . T.list where flattenEntry (fn, T.SubTree _) = Dir (BC.unpack (flatten fn)) flattenEntry (fn, T.File blob) = File (BC.unpack (flatten fn)) (map BLC.unpack $ BLC.lines $ unFail $ T.readBlob blob) flattenEntry (_, _) = impossible instance Show (V1Model wX) where show repo = "V1Model " ++ show (flattenTree (repoTree repo)) instance Show1 V1Model where showDict1 = ShowDictClass ---------------------------------------- -- Utils bs2lbs :: B.ByteString -> BL.ByteString bs2lbs bs = BL.fromChunks [bs] lbs2bs :: BL.ByteString -> B.ByteString lbs2bs = B.concat . BL.toChunks content2lbs :: Content -> BL.ByteString content2lbs = BLC.unlines . map bs2lbs lbs2content :: BL.ByteString -> Content lbs2content = map lbs2bs . BLC.lines ---------------------------------------------------------------------- -- ** Path conversion ap2fp :: AnchoredPath -> FilePath ap2fp = anchorPath "" ---------------------------------------------------------------------- -- * Constructors makeRepo :: [(Name, RepoItem)] -> V1Model wX makeRepo = V1Model . T.makeTree . map (second treeItem) emptyRepo :: V1Model wX emptyRepo = V1Model T.emptyTree makeFile :: Content -> File makeFile = RepoItem . T.File . T.makeBlob . content2lbs emptyFile :: File emptyFile = RepoItem $ T.File T.emptyBlob emptyDir :: Dir emptyDir = RepoItem $ T.SubTree T.emptyTree ---------------------------------------------------------------------- -- * Queries nullRepo :: V1Model wX -> Bool nullRepo = M.null . T.items . repoTree isFile :: RepoItem -> Bool isFile (RepoItem (T.File _)) = True isFile _other = False isDir :: RepoItem -> Bool isDir (RepoItem (T.SubTree _)) = True isDir _other = False fileContent :: File -> Content fileContent (RepoItem (T.File blob)) = lbs2content $ unFail $ T.readBlob blob fileContent _other = error "fileContent: Not a file." dirContent :: Dir -> [(Name, RepoItem)] dirContent (RepoItem (T.SubTree subtree)) = map (second RepoItem) $ M.toList $ T.items subtree dirContent _other = error "dirContent: Not a directory." -- | @isEmpty file@ <=> file content is empty -- @isEmpty dir@ <=> dir has no child isEmpty :: RepoItem -> Bool isEmpty item | isFile item = null $ fileContent item | isDir item = null $ dirContent item | otherwise = undefined -- | The root directory of a repository. root :: V1Model wX -> Dir root = RepoItem . T.SubTree . repoTree find :: V1Model wX -> AnchoredPath -> Maybe RepoItem find (V1Model tree) path = RepoItem <$> T.find tree path -- | List repository items. -- NB: It does not include the root directory. list :: V1Model wX -> [(AnchoredPath, RepoItem)] list (V1Model tree) = map (second RepoItem) $ T.list tree ---------------------------------------------------------------------- -- ** Filtering filterFiles :: [(n, RepoItem)] -> [(n, File)] filterFiles = filter (isFile . snd) filterDirs :: [(n, RepoItem)] -> [(n, Dir)] filterDirs = filter (isDir . snd) ---------------------------------------------------------------------- -- * Comparing repositories diffRepos :: V1Model wX -> V1Model wY -> (V1Model wU, V1Model wV) diffRepos repo1 repo2 = let (diff1,diff2) = unFail $ T.diffTrees hashedTree1 hashedTree2 in (V1Model diff1, V1Model diff2) where hashedTree1, hashedTree2 :: Tree Fail hashedTree1 = unFail $ darcsUpdateHashes $ repoTree repo1 hashedTree2 = unFail $ darcsUpdateHashes $ repoTree repo2 ---------------------------------------------------------------------- -- * Patch application ---------------------------------------------------------------------- -- * QuickCheck generators -- Testing code assumes that aFilename and aDirname generators -- will always be able to generate a unique name given a list of -- existing names. This should be OK as long as the number of possible -- file/dirnames is much bigger than the number of files/dirs per repository. -- 'Arbitrary' 'V1Model' instance is based on the 'aSmallRepo' generator. -- | Files are distinguish by ending their names with ".txt". aFilename :: Gen Name aFilename = do len <- choose (1,maxLength) name <- vectorOf len alpha return $ makeName (name ++ ".txt") where maxLength = 3 aDirname :: Gen Name aDirname = do len <- choose (1,maxLength) name <- vectorOf len alpha return $ makeName name where maxLength = 3 aWord :: Gen B.ByteString aWord = do c <- alpha return $ BC.pack[c] aLine :: Gen B.ByteString aLine = do wordsNo <- choose (1,2) ws <- vectorOf wordsNo aWord return $ BC.unwords ws aContent :: Gen Content aContent = bSized 0 0.5 80 $ \k -> do n <- choose (0,k) vectorOf n aLine aFile :: Gen File aFile = makeFile <$> aContent -- | See 'aRepo', the same applies for 'aDir'. aDir :: Int -- ^ Maximum number of files -> Int -- ^ Maximum number of directories -> Gen Dir aDir filesL dirL = root <$> aRepo filesL dirL -- | @aRepo filesNo dirsNo@ produces repositories with *at most* -- @filesNo@ files and @dirsNo@ directories. -- The structure of the repository is aleatory. aRepo :: Int -- ^ Maximum number of files -> Int -- ^ Maximum number of directories -> Gen (V1Model wX) aRepo maxFiles maxDirs = do let minFiles = if maxDirs == 0 && maxFiles > 0 then 1 else 0 filesNo <- choose (minFiles,maxFiles) let minDirs = if filesNo == 0 && maxDirs > 0 then 1 else 0 dirsNo <- choose (minDirs,maxDirs) -- NB: Thanks to laziness we don't need to care about division by zero -- since if dirsNo == 0 then neither filesPerDirL nor subdirsPerDirL will -- be evaluated. let filesPerDirL = (maxFiles-filesNo) `div` dirsNo subdirsPerDirL = (maxDirs-dirsNo) `div` dirsNo files <- vectorOf filesNo aFile filenames <- uniques filesNo aFilename dirs <- vectorOf dirsNo (aDir filesPerDirL subdirsPerDirL) dirnames <- uniques dirsNo aDirname return $ makeRepo (filenames `zip` files ++ dirnames `zip` dirs) -- | Generate small repositories. -- Small repositories help generating (potentially) conflicting patches. instance RepoModel V1Model where type RepoState V1Model = Tree showModel m = show {- ppShow -} m aSmallRepo = do filesNo <- frequency [(3, return 1), (1, return 2)] dirsNo <- frequency [(3, return 1), (1, return 0)] aRepo filesNo dirsNo repoApply (V1Model tree) patch = V1Model <$> applyToTree patch tree eqModel repo1 repo2 = let (diff1,diff2) = diffRepos repo1 repo2 in nullRepo diff1 && nullRepo diff2 instance Arbitrary (Sealed V1Model) where arbitrary = seal <$> aSmallRepo darcs-2.14.5/harness/Darcs/Test/Patch/WSub.hs0000644000000000000000000001157407346545000016771 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-} module Darcs.Test.Patch.WSub where {- The Examples.Set2Unwitnessed module builds a lot of test cases by pattern matching on the results of merge/commute in where clauses. This would be very painful to switch to using witnesses properly, because we'd have to make them use case in series. So instead we give up on witnesses for this module, but instead of preprocessor hacks which make incompatible code with the rest of darcs, we build a fresh set of witnesses constructors (FL etc) which aren't actually GADTs or existentials. So the pattern matching works as before, but we need to translate back and forth a lot. We call the normal darcs constructors the 'W' variants. -} import qualified Darcs.Test.Patch.Arbitrary.Generic as W ( getPairs, getTriples ) import qualified Darcs.Patch as W ( commute ) import qualified Darcs.Patch.Merge as W ( merge, mergeFL ) import qualified Darcs.Patch.Prim as W ( coalesce ) import qualified Darcs.Patch.Witnesses.Ordered as W import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Witnesses.Eq import Darcs.Patch.Witnesses.Show import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP, unsafeCoercePStart, unsafeCoercePEnd ) import Darcs.Patch.Merge ( Merge ) import Darcs.Patch.V2 ( RepoPatchV2 ) import qualified Darcs.Patch.V2.Prim as V2 import Darcs.Patch.Commute ( Commute ) import Darcs.Patch.Invert ( Invert(..) ) type Prim2 = V2.Prim infixr 5 :>: infixr 5 +>+ infixr 1 :> infix 1 :/\: infix 1 :\/: data FL p wX wY where NilFL :: FL p wX wY (:>:) :: p wX wY -> FL p wX wY -> FL p wX wY (+>+) :: FL p wX wY -> FL p wX wY -> FL p wX wY NilFL +>+ ps = ps (p :>: ps) +>+ qs = p :>: (ps +>+ qs) data (p :> q) wX wY where (:>) :: p wX wY -> q wX wY -> (p :> q) wX wY data (p :\/: q) wX wY where (:\/:) :: p wX wY -> q wX wY -> (p :\/: q) wX wY data (p :/\: q) wX wY where (:/\:) :: p wX wY -> q wX wY -> (p :/\: q) wX wY class WSub wp p | p -> wp, wp -> p where fromW :: wp wX wY -> p wX wY toW :: p wX wY -> wp wX wY instance (WSub wp1 p1, WSub wp2 p2) => WSub (wp1 W.:\/: wp2) (p1 :\/: p2) where fromW (x W.:\/: y) = unsafeCoerceP (fromW x) :\/: unsafeCoerceP (fromW y) toW (x :\/: y) = unsafeCoerceP (toW x) W.:\/: unsafeCoerceP (toW y) instance (WSub wp1 p1, WSub wp2 p2) => WSub (wp1 W.:/\: wp2) (p1 :/\: p2) where fromW (x W.:/\: y) = unsafeCoerceP (fromW x) :/\: unsafeCoerceP (fromW y) toW (x :/\: y) = unsafeCoerceP (toW x) W.:/\: unsafeCoerceP (toW y) instance (WSub wp1 p1, WSub wp2 p2) => WSub (wp1 W.:> wp2) (p1 :> p2) where fromW (x W.:> y) = unsafeCoercePEnd (fromW x) :> unsafeCoercePStart (fromW y) toW (x :> y) = unsafeCoercePEnd (toW x) W.:> unsafeCoercePStart (toW y) instance WSub wp p => WSub (W.FL wp) (FL p) where fromW W.NilFL = unsafeCoerceP NilFL fromW (x W.:>: xs) = unsafeCoercePEnd (fromW x) :>: unsafeCoercePStart (fromW xs) toW NilFL = unsafeCoerceP W.NilFL toW (x :>: xs) = unsafeCoercePEnd (toW x) W.:>: unsafeCoercePStart (toW xs) instance WSub prim prim => WSub (RepoPatchV2 prim) (RepoPatchV2 prim) where fromW = id toW = id instance WSub Prim2 Prim2 where fromW = id toW = id instance (WSub wp p, WSub wq q, Show2 wp, Show2 wq) => Show ((p :> q) wX wY) where show = show . toW instance (WSub wp p, WSub wq q, Show2 wp, Show2 wq) => Show2 (p :> q) where showDict2 = ShowDictClass instance (WSub wp p, WSub wq q, Show2 wp, Show2 wq) => Show ((p :\/: q) wX wY) where show = show . toW instance (WSub wp p, WSub wq q, Show2 wp, Show2 wq) => Show2 (p :\/: q) where showDict2 = ShowDictClass instance (WSub wp p, Show2 wp) => Show (FL p wX wY) where show = show . toW instance (WSub wp p, Show2 wp) => Show2 (FL p) where showDict2 = ShowDictClass instance (WSub wp p, Commute wp, Eq2 wp) => Eq2 (FL p) where unsafeCompare x y = unsafeCompare (toW x) (toW y) instance (WSub wp p, Commute wp, Invert wp) => Invert (FL p) where invert = fromW . invert . toW instance (WSub wp p, Commute wp) => Commute (FL p) where commute (xs W.:> ys) = do ys' W.:> xs' <- W.commute (toW xs W.:> toW ys) return (fromW ys' W.:> fromW xs') mergeFL :: (WSub wp p, Merge wp) => (p :\/: FL p) wX wY -> (FL p :/\: p) wX wY mergeFL = fromW . W.mergeFL . toW merge :: (WSub wp p, Merge wp) => (p :\/: p) wX wY -> (p :/\: p) wX wY merge = fromW . W.merge . toW commute :: (WSub wp p, Commute wp) => (p :> p) wX wY -> Maybe ((p :> p) wX wY) commute = fmap fromW . W.commute . toW getPairs :: FL (RepoPatchV2 Prim2) wX wY -> [Sealed2 (RepoPatchV2 Prim2 :> RepoPatchV2 Prim2)] getPairs = map (mapSeal2 fromW) . W.getPairs . toW getTriples :: FL (RepoPatchV2 Prim2) wX wY -> [Sealed2 (RepoPatchV2 Prim2 :> RepoPatchV2 Prim2 :> RepoPatchV2 Prim2)] getTriples = map (mapSeal2 fromW) . W.getTriples . toW coalesce :: (Prim2 :> Prim2) wX wY -> Maybe (FL Prim2 wX wY) coalesce = fmap fromW . W.coalesce . toW darcs-2.14.5/harness/Darcs/Test/Patch/WithState.hs0000644000000000000000000001241607346545000020021 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses, ScopedTypeVariables, UndecidableInstances #-} module Darcs.Test.Patch.WithState where import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Witnesses.Show import Test.QuickCheck ( Gen, sized, choose ) ---------------------------------------------------------------------- -- * WithState data WithState s p wX wY = WithState { wsStartState :: s wX , wsPatch :: p wX wY , wsEndState :: s wY } deriving Eq instance (Show1 s, Show2 p) => Show (WithState s p wX wY) where showsPrec d (WithState s p s') = showParen (d > appPrec) $ showString "WithState " . showsPrec1 (appPrec+1) s . showString " " . showsPrec2 (appPrec+1) p . showString " " . showsPrec1 (appPrec+1) s' instance (Show1 s, Show2 p) => Show2 (WithState s p) where showDict2 = ShowDictClass data WithStartState s p wX = WithStartState { wssStartState :: s wX , wssPatch :: p wX } deriving Eq instance (Show1 s, Show1 p) => Show (WithStartState s p wX) where showsPrec d (WithStartState s p) = showParen (d > appPrec) $ showString "WithStartState " . showsPrec1 (appPrec + 1) s . showString " " . showsPrec1 (appPrec + 1) p instance (Show1 s, Show1 p) => Show1 (WithStartState s p) where showDict1 = ShowDictClass -- | A combination of a patch and its final state. The state, in this module, is -- typically represented by a 'RepoModel' value. The @px@ type is typically a -- patch type applied to its pre-state, e.g. @Prim x@. data WithEndState s px wY = WithEndState { wesPatch :: px wY , wesEndState :: s wY } deriving Eq instance (Show1 s, Show1 p) => Show (WithEndState s p wX) where showsPrec d (WithEndState p s) = showParen (d > appPrec) $ showString "WithEndState " . showsPrec1 (appPrec + 1) p . showString " " . showsPrec1 (appPrec + 1) s instance (Show1 s, Show1 p) => Show1 (WithEndState s p) where showDict1 = ShowDictClass ---------------------------------------------------------------------- -- * ArbitraryState generators -- | A type class to generate arbitrary values, threading a state through the -- arbitrary calls. So this can be used to generate a patch that comes after -- another patch. The post-state of the generated patch is hidden by the -- 'Sealed'. class ArbitraryState s p where arbitraryState :: s wX -> Gen (Sealed (WithEndState s (p wX))) -- does a coarbitrary make sense? instance ArbitraryState s p => ArbitraryState s (WithState s p) where arbitraryState s = do Sealed (WithEndState x s') <- arbitraryState s return $ seal $ WithEndState (WithState s x s') s' instance ArbitraryState s p => ArbitraryState s (p :> p) where arbitraryState s = do Sealed (WithEndState p1 s') <- arbitraryState s Sealed (WithEndState p2 s'') <- arbitraryState s' return $ seal $ WithEndState (p1 :> p2) s'' instance ArbitraryState s p => ArbitraryState s (p :> p :> p) where arbitraryState s0 = do Sealed (WithEndState p1 s1) <- arbitraryState s0 Sealed (WithEndState p2 s2) <- arbitraryState s1 Sealed (WithEndState p3 s3) <- arbitraryState s2 return $ seal $ WithEndState (p1 :> p2 :> p3) s3 arbitraryFL :: ArbitraryState s p => forall wX . Int -> s wX -> Gen (Sealed (WithEndState s (FL p wX))) arbitraryFL 0 s = return $ seal $ WithEndState NilFL s arbitraryFL n s = do Sealed (WithEndState x s') <- arbitraryState s Sealed (WithEndState xs s'') <- arbitraryFL (n-1) s' return $ seal $ WithEndState (x :>: xs) s'' instance ArbitraryState s p => ArbitraryState s (FL p) where arbitraryState s = sized $ \n -> do k <- choose (0, min 2 (n `div` 5)) arbitraryFL k s makeS2Gen :: ArbitraryState s p => Gen (s wX) -> Gen (Sealed2 p) makeS2Gen stGen = do s <- stGen Sealed (WithEndState p _) <- arbitraryState s return $ seal2 p makeSGen :: ArbitraryState s p => Gen (s wX) -> Gen (Sealed (p wX)) makeSGen stGen = do s <- stGen Sealed (WithEndState p _) <- arbitraryState s return $ seal p makeWS2Gen :: ArbitraryState s p => Gen (s wX) -> Gen (Sealed2 (WithState s p)) makeWS2Gen stGen = do s <- stGen Sealed (WithEndState wsP _) <- arbitraryState s return $ seal2 wsP makeWSGen :: ArbitraryState s p => Gen (s wX) -> Gen (Sealed (WithState s p wX)) makeWSGen stGen = do s <- stGen Sealed (WithEndState wsP _) <- arbitraryState s return $ seal wsP instance (Show2 p, Show1 s) => Show1 ((WithState s p) wA) where showDict1 = ShowDictClass darcs-2.14.5/harness/Darcs/Test/Repository/0000755000000000000000000000000007346545000016665 5ustar0000000000000000darcs-2.14.5/harness/Darcs/Test/Repository/Inventory.hs0000644000000000000000000001237707346545000021230 0ustar0000000000000000module Darcs.Test.Repository.Inventory where import Darcs.Repository.Inventory ( Inventory(..) , HeadInventory , ValidHash(..) , InventoryHash , PatchHash , PristineHash , getValidHash , mkValidHash , parseInventory , showInventory , skipPristineHash , peekPristineHash , pokePristineHash , prop_inventoryParseShow , prop_peekPokePristineHash , prop_skipPokePristineHash ) import Darcs.Patch.Info ( rawPatchInfo ) import Darcs.Util.Printer ( renderPS ) import Darcs.Test.Patch.Info () import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import Test.Framework ( Test, testGroup ) import Test.Framework.Providers.HUnit ( testCase ) import Test.Framework.Providers.QuickCheck2 ( testProperty ) import Test.HUnit ( Assertion, (@=?) ) import Test.QuickCheck testSuite :: Test testSuite = testGroup "Darcs.Repository.Inventory" [ testProperty "parse/show roundtrips" prop_inventoryParseShow , testProperty "peek gets back what we poked" prop_peekPokePristineHash , testProperty "skip/poke roundtrips" prop_skipPokePristineHash , testCase "example1" (testInventory rawHeadInv1 headInv1) , testCase "example2" (testInventory rawHeadInv2 headInv2) ] instance Arbitrary B.ByteString where arbitrary = B.pack <$> arbitrary instance Arbitrary Inventory where arbitrary = uncurry Inventory <$> arbitrary instance Arbitrary InventoryHash where arbitrary = arbitraryHash instance Arbitrary PatchHash where arbitrary = arbitraryHash instance Arbitrary PristineHash where arbitrary = arbitraryHash arbitraryHash :: ValidHash h => Gen h arbitraryHash = mkValidHash <$> do n <- elements [64, 75] -- see D.R.Cache.okayHash vectorOf n $ elements $ '-' : (['0'..'9'] ++ ['a'..'f']) testInventory :: B.ByteString -> HeadInventory -> Assertion testInventory raw (vhash,inv) = do let hash = getValidHash vhash hash @=? peekPristineHash raw let rest = skipPristineHash raw Just inv @=? parseInventory rest rest @=? renderPS (showInventory inv) raw @=? renderPS (pokePristineHash hash rest) headInv1 :: HeadInventory headInv1 = ( mkValidHash "57fb9c1abbed1c0b880e2fffebe32a2163762b87e67e9bf4dcd3168e5abcad83" , Inventory { inventoryParent = Nothing , inventoryPatches = [ ( rawPatchInfo "20180311141206" "Add d/f and e." "tester" [ "Ignore-this: b541ff7ea385297c8ad07fe58016efa8" ] False , mkValidHash "0000000154-703d7811c2e3f1e1aa81e4be5fab31a291cc18158ec8a75733b6faa5fb406286" ) , ( rawPatchInfo "20180311141206" "Move d/f to e/f." "tester" [ "Ignore-this: b71452c8a91c573f7e7fa2e8eb34afd1" ] False , mkValidHash "0000000106-4b1bc6db02d2eea04efe888b64ce853a416c14ae1ae43550b0137f11a8a8dfee" ) ] } ) rawHeadInv1 :: B.ByteString rawHeadInv1 = BC.pack "pristine:57fb9c1abbed1c0b880e2fffebe32a2163762b87e67e9bf4dcd3168e5abcad83\n\ \[Add d/f and e.\n\ \tester**20180311141206\n\ \ Ignore-this: b541ff7ea385297c8ad07fe58016efa8\n\ \] \n\ \hash: 0000000154-703d7811c2e3f1e1aa81e4be5fab31a291cc18158ec8a75733b6faa5fb406286\n\ \[Move d/f to e/f.\n\ \tester**20180311141206\n\ \ Ignore-this: b71452c8a91c573f7e7fa2e8eb34afd1\n\ \] \n\ \hash: 0000000106-4b1bc6db02d2eea04efe888b64ce853a416c14ae1ae43550b0137f11a8a8dfee\n\ \" headInv2 :: HeadInventory headInv2 = ( mkValidHash "f2f70f1326252fc53077d7cd71769f405618829ba40a8f00f112ac97213f5f4b" , Inventory { inventoryParent = Just (mkValidHash "0000220070-6ef010a955c38fc4301787092979994bafd366eb50152b66e089deff649d35da") , inventoryPatches = [ ( rawPatchInfo "20160429142058" "TAG 2.12.0" "Guillaume Hoffmann " [ "Ignore-this: 5c8cbe0424942686a2168f9e6fd8e35d" ] False , mkValidHash "0000088075-e1cc4489099cfff1df5875a8146dc012110c156f3dad839f4632d62ee2331e43" ) , ( rawPatchInfo "20160429143015" "bump version to 2.13.0" "Guillaume Hoffmann " [ "Ignore-this: 7468e30e96f3bf833f4e374e9cc7e515" ] False , mkValidHash "0000000198-0f5455b7c229e132a2fc2173dcce2b567f806c1d3eb1c37fd9fe8d8e42ef4fc9" ) ] } ) rawHeadInv2 :: B.ByteString rawHeadInv2 = BC.pack "pristine:f2f70f1326252fc53077d7cd71769f405618829ba40a8f00f112ac97213f5f4b\n\ \Starting with inventory:\n\ \0000220070-6ef010a955c38fc4301787092979994bafd366eb50152b66e089deff649d35da\n\ \[TAG 2.12.0\n\ \Guillaume Hoffmann **20160429142058\n\ \ Ignore-this: 5c8cbe0424942686a2168f9e6fd8e35d\n\ \] \n\ \hash: 0000088075-e1cc4489099cfff1df5875a8146dc012110c156f3dad839f4632d62ee2331e43\n\ \[bump version to 2.13.0\n\ \Guillaume Hoffmann **20160429143015\n\ \ Ignore-this: 7468e30e96f3bf833f4e374e9cc7e515\n\ \] \n\ \hash: 0000000198-0f5455b7c229e132a2fc2173dcce2b567f806c1d3eb1c37fd9fe8d8e42ef4fc9\n\ \" darcs-2.14.5/harness/Darcs/Test/Util/0000755000000000000000000000000007346545000015423 5ustar0000000000000000darcs-2.14.5/harness/Darcs/Test/Util/QuickCheck.hs0000644000000000000000000000244307346545000017774 0ustar0000000000000000 module Darcs.Test.Util.QuickCheck ( upper , lower , alpha , notIn , uniques , maybeOf , bSized ) where import Prelude () import Darcs.Prelude import Test.QuickCheck.Gen -- | An uppercase alphabetic character. upper :: Gen Char upper = choose ('A','Z') -- | A lowercase alphabetic character. lower :: Gen Char lower = choose ('a','z') -- | An alphabetic character. alpha :: Gen Char alpha = oneof [upper, lower] -- | @gen `notIn` xs@ generate a @x@ that is not in @xs@. notIn :: Eq a => Gen a -> [a] -> Gen a gen `notIn` xs = gen `suchThat` (`notElem` xs) -- | @uniques k gen@ generates a list of @k@ unique values. uniques :: Eq a => Int -> Gen a -> Gen [a] uniques k gen = go k [] where go 0 xs = return xs go n xs = do x <- gen `notIn` xs go (n-1) (x:xs) -- | Try to arbitrarily pick some element of the list. maybeOf :: [a] -> Gen (Maybe a) maybeOf [] = return Nothing maybeOf xs = Just <$> elements xs -- | A bounded sized combinator. bSized :: Int -- ^ Lower bound -> Double -- ^ Increment -> Int -- ^ Upper bound -> (Int -> Gen a) -> Gen a bSized low inc upp mkGen = sized $ mkGen . resize' where resize' :: Int -> Int resize' n = let x = fromIntegral n in min upp (floor(inc*x) + low) darcs-2.14.5/harness/Darcs/Test/Util/TestResult.hs0000644000000000000000000000261107346545000020075 0ustar0000000000000000module Darcs.Test.Util.TestResult ( TestResult , succeeded , failed , rejected , (<&&>) , fromMaybe , isOk , isFailed ) where import Darcs.Util.Printer (Doc, renderString) import qualified Test.QuickCheck.Property as Q data TestResult = TestSucceeded | TestFailed Doc | TestRejected succeeded :: TestResult succeeded = TestSucceeded failed :: Doc -> TestResult failed = TestFailed rejected :: TestResult rejected = TestRejected -- | Succeed even if one of the arguments is rejected. (<&&>) :: TestResult -> TestResult -> TestResult t@(TestFailed _) <&&> _s = t _t <&&> s@(TestFailed _) = s TestRejected <&&> s = s t <&&> TestRejected = t TestSucceeded <&&> TestSucceeded = TestSucceeded -- | 'Nothing' is considered success whilst 'Just' is considered failure. fromMaybe :: Maybe Doc -> TestResult fromMaybe Nothing = succeeded fromMaybe (Just errMsg) = failed errMsg isFailed :: TestResult -> Bool isFailed (TestFailed _) = True isFailed _other = False -- | A test is considered Ok if it does not fail. isOk :: TestResult -> Bool isOk = not . isFailed -- | 'Testable' instance is defined by converting 'TestResult' to -- 'QuickCheck.Property.Result' instance Q.Testable TestResult where property TestSucceeded = Q.property Q.succeeded property (TestFailed errorMsg) = Q.property (Q.failed {Q.reason = renderString errorMsg}) property TestRejected = Q.property Q.rejected darcs-2.14.5/harness/0000755000000000000000000000000007346545000012533 5ustar0000000000000000darcs-2.14.5/harness/hstestdata.zip0000755000000000000000000004043507346545000015434 0ustar0000000000000000PK Z:_darcs/UT lJ95IJux PK wY:_darcs/pristine.hashed/UT R@`J95IJux PK Z:=.[[b_darcs/pristine.hashed/0000000088-b629d32eda4e44b4f196579e6b36caafc53107eff12d1dde063bdd8b52d21a38UT \5IJ\5IJux 5A 0{RhԴ)Q([O獫(ѭQO^\6=Lpr ؜r›'[XPKV: Hb_darcs/pristine.hashed/0000000002-87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7UT T5IJT5IJux `f'L _erPKR:Ib_darcs/pristine.hashed/0000000002-0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813fUT L5IJL5IJux `fGL G>PKkY:{9.b_darcs/pristine.hashed/0000000010-e6f805fa5fc041ab4bb7aa119641f77ac3e9f42106bc9f92354080692736c8deUT 9@`J9@`Jux `fo/sz,Y FiwnPľ0%6.;=]&&:^ZTz![[}ⶡ,'蘏brk5*WΫM$4>[|eޒrzLJ/[h~_( X ʠ*KXYsettx3RIVLXfݙ X+]ÜZ.g&߁dRWPK I: _darcs/prefs/UT 95IJ95IJux PKI:qAě_darcs/prefs/binariesUT 95IJ95IJux PMo0 W60@/;ɚ)X}شզ@ont#P4J <1R8lrҰ׆g0`?aDVq Ԁ@-zwDWy셞pФ* 2 ,6R/Z! vemV)WLt- $*pF ~iLFXEHf)('t 8\ Oɗji˒n޲DEi( ]>]X"LF]V8aX}_E:l\fKMؾPTT=N׹M[HWACv5naN97Oa E<|m~ VHUQbOԤǑrmBcm  3V׾:BP q:qKjJ$`Q_];f&+P[P8>KpӃU.ߏ)oޥ4suقd02S{Sqճi}NאSӲtU9J&!4so 7wѹ&!/2đ5I4JH߮l$9هBulAaT-j{D3_y_"/DKֺx_J'B\p>[,v4&6^aʖLǭL cn?5$uZ*"왍$K'D9^f'xUٷc,,8m26iX56J: gۙkJ,>'{RZ`y"r$HT!؛͆mVS֔anv'8>{^_2;J_r琩0X&_w]IPK I:_darcs/prefs/motdUT 95IJ95IJux PK wY:_darcs/patches/UT R@`J95IJux PK wY:bZ_darcs/patches/0000000375-0004f58841fa2a879732c077eb6e7309f1dd8b3dbae3559298cb97afad38c36aUT R@`JR@`Jux } 0 {"gEm7x&^HekeoD1?E14׳Ciyl(u-C^UC&D禞hpk! ۳-M%eҹJPR !5IP$ );la[4sbϴ'~ gnzb+ c$3aR~6q' |*BwPK h:r.Z_darcs/patches/0000000227-e54718f289070d7e09bbb752616934e0417290b8a798388083f8e2038817bc92UT t5IJt5IJux m 0E|ś+֤6UD&I:Åùt7`,8\3.u&nÐrH(*5+] #L˱ -h)Hq$jn\cujY+%ч\־b` ;g؏a]GQPK n: xZ_darcs/patches/0000000147-fa3ee8d70a3fb3d9f6aee557675eeb116df0813520a93346453419f119a2d71dUT 5IJ5IJux e wM1:Wc [H(uvn'"<(Zky]s9i9CסVh8(&'PHu[0Az\R,2N_&N`j Ōsɻ{+JJY*b]d jWhProƠ44p2 X-!*DB%ZcZ>PK a:~^_darcs/inventories/0000000382-2da2908c780ff8ef88ebae3cbe219df46a51b982a6a8c16e27a5d85d5cbc25e9UT e5IJe5IJux JCA YZ2L.݉"$m?čݳjyj%SlOyNW+`3f2/mجjX =L3v# .L%Q{u6JEJ>=Sm-~4Uw^263ȁU 钲Ci-S8-:1'QPK u:0k^_darcs/inventories/0000001008-09bafef4ebd348512b5ba6e115464ffe9041691421420c0ab559a99ce1d813fcUT 5IJ5IJux n1 w?.%EQhnEנ($&6`_App'v0~?>h{?I %iœn?tȀ woX!l[ k.}LSћJD3FqlآPW4aҺQ ROz_*teePtMF!e+ʑ h^i87PULi*4#JUv}߂Dp^|9>&'ZQHuu΂5 0q޻p*C9I&0 bye=EIN*6EV|iKQ3vܫ 4"M4wf)³*'hJKfʨ85Aγ2]1 58լIkIԬi ^X'.w/uSd G # ER'4628ey;PK Z:b9^_darcs/inventories/0000000190-ff575eca8b1699926e287033bf74a351fbe492ef357c1a1c205c63dcf0a36edfUT \5IJ\5IJux % 0=O`4鉈n*"ܝvޜe]=#O[few@H>٬󻵹B*5)B,.fDikEDE.(~Z*!#-IQqZN7?LPK wY:a,(22^_darcs/inventories/0000001211-d705032f80e41ed76d51c764b549a46416bd29e9c379e00695f8b0f8908441ecUT R@`JR@`Jux Mo1 @+\i']!Gnk8v*Tr8g1y8|8._m;;Ӷ?|J 5iœw2tԽ 8۲OfX穣q9x͔QKhթ8 ΓFiu9ϦEa&v㤳QKsTDФ4JwtN-92@jB7 i2s ܿ-:e %p}n=8FK@]{Ɍ2C0 vTCƘKP[Pqȯ+ywZ.H,TU]4j$4%c.^O#w F!r^ W.uL(\(NH;ǟv肉(Mr./$ɚTj"--x`)KB<TX g3YF*8>YZ0;_?v~/FEQ!,Qbu(e!"oZ2aeJUg1F͜J9߁S/̻PK I:gի _darcs/formatUT 95IJ95IJux hashed darcs-2 PKwY:Қ׎HU_darcs/tentative_pristineUT R@`JR@`Jux %I 0 &MXpNsyGZfwAK0@ UE"DwJLnӖPK M:foo_aUT A5IJA5IJux a PK T:foo_dir/UT O5IJD5IJux PK V:foo_dir/foo_subdir/UT T5IJO5IJux PK V:foo_dir/foo_subdir/foo_aUT T5IJT5IJux a PK Q: foo_dir/foo_aUT J5IJJ5IJux a PK R: foo_dir/foo_bUT L5IJL5IJux b PK nY: foo space/UT @@`J?`Jux PK nY:foo space/foo_aUT @@`J@@`Jux a PK kY:f= foo space/foo\backslashUT 9@`J9@`Jux backslash PK QY:ȁfoo space/foo newlineUT  @`J @`Jux newline PK Z:A_darcs/UTlJux PK wY:AA_darcs/pristine.hashed/UTR@`Jux PK Z:=.[[b_darcs/pristine.hashed/0000000088-b629d32eda4e44b4f196579e6b36caafc53107eff12d1dde063bdd8b52d21a38UT\5IJux PKV: Hb_darcs/pristine.hashed/0000000002-87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7UTT5IJux PKR:Ib8_darcs/pristine.hashed/0000000002-0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813fUTL5IJux PKkY:{9.b_darcs/pristine.hashed/0000000010-e6f805fa5fc041ab4bb7aa119641f77ac3e9f42106bc9f92354080692736c8deUT9@`Jux PK wY:&b_darcs/pristine.hashed/0000000284-ba1baff2dab9f3fdb42f8ab4c97d43fd636d14c891207c5e47a978a02aba9739UTR@`Jux PK u:C_b_darcs/pristine.hashed/0000000183-6eebdc0ce46aec3457a7feefefaeb3732907150540c6e376c0564543b8eecddaUT5IJux PK u:=b._darcs/pristine.hashed/0000000274-c40f7f018b5cdb889583641e449e5386271af224695d24ec1e692b9fb1db01e3UT5IJux PKQY:#b_darcs/pristine.hashed/0000000008-7ba826f0c347f6adc4686c8d1f61aeb2e2e98322749cd4f82204c926f4022ceeUT @`Jux PK wY:b>_darcs/pristine.hashed/0000000283-5e1671028edb90cc82bfb81b3ee29ec4f1daa354ec423398f2cc983f2f4ad4fbUTR@`Jux PKwY:ZS _darcs/hashed_inventoryUTR@`Jux PK I: AG _darcs/prefs/UT95IJux PKI:qAě _darcs/prefs/binariesUT95IJux PKI:L2x_darcs/prefs/boringUT95IJux PK I:_darcs/prefs/motdUT95IJux PK wY:A-_darcs/patches/UTR@`Jux PK wY:bZv_darcs/patches/0000000375-0004f58841fa2a879732c077eb6e7309f1dd8b3dbae3559298cb97afad38c36aUTR@`Jux PK h:r.Z_darcs/patches/0000000227-e54718f289070d7e09bbb752616934e0417290b8a798388083f8e2038817bc92UTt5IJux PK n: xZ_darcs/patches/0000000147-fa3ee8d70a3fb3d9f6aee557675eeb116df0813520a93346453419f119a2d71dUT5IJux PK wY: 3_darcs/patches/pending.tentativeUTR@`Jux PK u:WZ_darcs/patches/0000000200-f845b978211aa40061d5c1503e11c150a1f486aee7bc95868f6a1ae56c5271aaUT5IJux PK wY:_darcs/patches/pendingUTR@`Jux PK Z:xZ_darcs/patches/0000000140-4f9db7bc4438e289cba97ffad517e754d1afb6f9e91d75d06abd3fc7f3d60762UT\5IJux PK `:$Z<_darcs/patches/0000000125-330b85f2d1b798ce83ce5a9ff9542e97169cbb92c9990caa40c9415d174bd089UTd5IJux PK wY:AV_darcs/inventories/UTR@`Jux PK n:KT^_darcs/inventories/0000000796-a69cac87af8a076fef18f51d4849f17ca57ad8eedd2fb0f15d02a34a950a9c55UT5IJux PK a:~^_darcs/inventories/0000000382-2da2908c780ff8ef88ebae3cbe219df46a51b982a6a8c16e27a5d85d5cbc25e9UTe5IJux PK h:dII^d_darcs/inventories/0000000593-94396dc37bfeebdcddd2f4a467ce3f00092341caaf3058fd26189017da72ca99UTt5IJux PK u:0k^E!_darcs/inventories/0000001008-09bafef4ebd348512b5ba6e115464ffe9041691421420c0ab559a99ce1d813fcUT5IJux PK Z:b9^#_darcs/inventories/0000000190-ff575eca8b1699926e287033bf74a351fbe492ef357c1a1c205c63dcf0a36edfUT\5IJux PK wY:a,(22^$_darcs/inventories/0000001211-d705032f80e41ed76d51c764b549a46416bd29e9c379e00695f8b0f8908441ecUTR@`Jux PK I:gի '_darcs/formatUT95IJux PKwY:Қ׎HU(_darcs/tentative_pristineUTR@`Jux PK M:(foo_aUTA5IJux PK T:A(foo_dir/UTO5IJux PK V:A9)foo_dir/foo_subdir/UTT5IJux PK V:)foo_dir/foo_subdir/foo_aUTT5IJux PK Q: )foo_dir/foo_aUTJ5IJux PK R: #*foo_dir/foo_bUTL5IJux PK nY: Al*foo space/UT@@`Jux PK nY:*foo space/foo_aUT@@`Jux PK kY:f= *foo space/foo\backslashUT9@`Jux PK QY:ȁV+foo space/foo newlineUT @`Jux PK,,Z+darcs-2.14.5/harness/test.hs0000644000000000000000000003022007346545000014043 0ustar0000000000000000{-# LANGUAGE CPP, MultiParamTypeClasses, DeriveDataTypeable, ViewPatterns, OverloadedStrings, ExtendedDefaultRules #-} {-# OPTIONS_GHC -fno-warn-missing-fields #-} {-# OPTIONS_GHC -fno-warn-type-defaults #-} module Main ( main ) where import qualified Darcs.Test.Misc import qualified Darcs.Test.Patch import qualified Darcs.Test.Email import qualified Darcs.Test.Repository.Inventory import qualified Darcs.Test.HashedStorage import Control.Monad ( filterM ) import Control.Exception ( SomeException ) import Data.Text ( Text, pack, unpack ) import Data.List ( isPrefixOf, isSuffixOf, sort ) import GHC.IO.Encoding ( textEncodingName ) import System.Console.CmdArgs hiding ( args ) import System.Directory ( doesFileExist ) import System.Environment.FindBin ( getProgPath ) import System.FilePath( takeDirectory, takeBaseName, isAbsolute ) import System.IO( hSetBinaryMode, hSetBuffering, BufferMode( NoBuffering ), stdin, stdout, stderr, localeEncoding ) import Test.Framework.Providers.API ( TestResultlike(..), Testlike(..), Test, runImprovingIO, yieldImprovement, Test(..), liftIO ) import Test.Framework ( defaultMainWithArgs ) import Shelly hiding ( liftIO, run, FilePath, path ) import qualified Shelly doUnit :: IO [Test] doUnit = return unitTests -- | TODO make runnable in parallel doHashed :: IO [Test] doHashed = return Darcs.Test.HashedStorage.tests -- | This is the big list of tests that will be run using testrunner. unitTests :: [Test] unitTests = [ Darcs.Test.Email.testSuite , Darcs.Test.Misc.testSuite , Darcs.Test.Repository.Inventory.testSuite ] ++ Darcs.Test.Patch.testSuite -- ---------------------------------------------------------------------- -- shell tests -- ---------------------------------------------------------------------- data Format = Darcs1 | Darcs2 deriving (Show, Eq, Typeable, Data) data DiffAlgorithm = MyersDiff | PatienceDiff deriving (Show, Eq, Typeable, Data) data Running = Running deriving Show data Result = Success | Skipped | Failed String instance Show Result where show Success = "Success" show Skipped = "Skipped" show (Failed f) = unlines (map ("| " ++) $ lines f) instance TestResultlike Running Result where testSucceeded Success = True testSucceeded Skipped = True testSucceeded _ = False data ShellTest = ShellTest { format :: Format , testfile :: FilePath , testdir :: Maybe FilePath -- ^ only if you want to set it explicitly , _darcspath :: FilePath , diffalgorithm :: DiffAlgorithm } deriving Typeable runtest' :: ShellTest -> Text -> Sh Result runtest' (ShellTest fmt _ _ dp da) srcdir = do wd <- toTextIgnore <$> pwd setenv "HOME" wd setenv "TESTDATA" (toTextIgnore (srcdir "tests" "data")) setenv "TESTBIN" (toTextIgnore (srcdir "tests" "bin")) setenv "DARCS_TESTING_PREFS_DIR" $ toTextIgnore $ wd ".darcs" setenv "EMAIL" "tester" setenv "GIT_AUTHOR_NAME" "tester" setenv "GIT_AUTHOR_EMAIL" "tester" setenv "GIT_COMMITTER_NAME" "tester" setenv "GIT_COMMITTER_EMAIL" "tester" setenv "DARCS_DONT_COLOR" "1" setenv "DARCS_DONT_ESCAPE_ANYTHING" "1" p <- get_env_text "PATH" setenv "PATH" (pack (takeDirectory dp ++ pathVarSeparator ++ unpack p)) setenv "DARCS" $ pack dp setenv "GHC_VERSION" $ pack $ show (__GLASGOW_HASKELL__ :: Int) mkdir ".darcs" writefile ".darcs/defaults" defaults _ <- onCommandHandles (initOutputHandles (\h -> hSetBinaryMode h True)) $ Shelly.run "bash" [ "test" ] return Success `catch_sh` \(_::SomeException) -> do code <- lastExitCode case code of 200 -> return Skipped _ -> Failed <$> unpack <$> lastStderr where defaults = pack $ unlines [ "ALL " ++ fmtstr , "send no-edit-description" , "ALL ignore-times" , "ALL " ++ daf ] fmtstr = case fmt of Darcs2 -> "darcs-2" Darcs1 -> "darcs-1" daf = case da of PatienceDiff -> "patience" MyersDiff -> "myers" #ifdef WIN32 pathVarSeparator = ";" #else pathVarSeparator = ":" #endif runtest :: ShellTest -> Sh Result runtest t = withTmp $ \dir -> do cp "tests/lib" dir cp "tests/network/sshlib" dir cp (fromText $ pack $ testfile t) (dir "test") srcdir <- pwd silently $ sub $ cd dir >> runtest' t (toTextIgnore srcdir) where withTmp = case testdir t of Just dir -> \job -> do let d = (dir show (format t) show (diffalgorithm t) takeBaseName (testfile t)) mkdir_p d job d Nothing -> withTmpDir instance Testlike Running Result ShellTest where testTypeName _ = "Shell" runTest _ test = runImprovingIO $ do yieldImprovement Running liftIO (shelly $ runtest test) shellTest :: FilePath -> Format -> Maybe FilePath -> String -> DiffAlgorithm -> Test shellTest dp fmt tdir file da = Test (takeBaseName file ++ " (" ++ show fmt ++ ")" ++ " (" ++ show da ++ ")") $ ShellTest fmt file tdir dp da toString :: Shelly.FilePath -> String toString = unpack . toTextIgnore findShell :: FilePath -> Text -> Maybe FilePath -> Bool -> [DiffAlgorithm] -> [Format] -> Sh [Test] findShell dp sdir tdir isFailing diffAlgorithms repoFormats = do files <- ls (fromText sdir) let test_files = sort $ filter relevant $ filter (hasExt "sh") files return [ shellTest dp fmt tdir file da | file <- map toString test_files , fmt <- repoFormats , da <- diffAlgorithms ] where relevant = (if isFailing then id else not) . ("failing-" `isPrefixOf`) . takeBaseName . toString -- ---------------------------------------------------------------------- -- harness -- ---------------------------------------------------------------------- data Config = Config { hashed :: Bool , failing :: Bool , shell :: Bool , network :: Bool , unit :: Bool , myers :: Bool , patience :: Bool , darcs1 :: Bool , darcs2 :: Bool , full :: Bool , darcs :: String , tests :: [String] , testDir :: Maybe FilePath , plain :: Bool , hideSuccesses :: Bool , threads :: Int , qcCount :: Int } deriving (Data, Typeable, Eq) defaultConfig :: Annotate Ann defaultConfig = record Config{} [ hashed := False += help "Run hashed-storage tests [no]" , failing := False += help "Run the failing (shell) tests [no]" , shell := True += help "Run the passing, non-network shell tests [yes]" -- RELEASE BRANCH ONLY: disable network tests (too fragile) -- , network := True += help "Run the network shell tests [yes]" , network := False += help "Run the network shell tests [no]" , unit := True += help "Run the unit tests [yes]" , myers := False += help "Use myers diff [no]" , patience := True += help "Use patience diff [yes]" += name "p" , darcs1 := False += help "Use darcs-1 repo format [no]" += name "1" , darcs2 := True += help "Use darcs-2 repo format [yes]" += name "2" , full := False += help "Run all tests in all variants" , darcs := "" += help "Darcs binary path" += typ "PATH" , tests := [] += help "Pattern to limit the tests to run" += typ "PATTERN" += name "t" , testDir := Nothing += help "Directory to run tests in" += typ "PATH" += name "d" , plain := False += help "Use plain-text output [no]" , hideSuccesses := False += help "Hide successes [no]" , threads := 1 += help "Number of threads [1]" += name "j" , qcCount := 100 += help "Number of QuickCheck iterations per test [100]" += name "q" ] += summary "Darcs test harness" += program "darcs-test" run :: Config -> IO () run conf = do let args = [ "-j", show $ threads conf ] ++ concat [ ["-t", x ] | x <- tests conf ] ++ [ "--plain" | True <- [plain conf] ] ++ [ "--hide-successes" | True <- [hideSuccesses conf] ] -- this multiplier is calibrated against the observed behaviour of the test harness - -- increase it if we see lots of "arguments exhausted" errors or similar ++ [ "--maximum-unsuitable-generated-tests", show (7 * qcCount conf) ] ++ [ "--maximum-generated-tests", show (qcCount conf) ] case testDir conf of Nothing -> return () Just d -> do e <- shelly (test_e (fromText $ pack d)) when e $ fail ("Directory " ++ d ++ " already exists. Cowardly exiting") darcsBin <- case darcs conf of "" -> do path <- getProgPath let candidates = -- if darcs-test lives in foo/something, look for foo/darcs[.exe] -- for example if we've done cabal install -ftest, there'll be a darcs-test and darcs in the cabal -- installation folder [path ("darcs" ++ exeSuffix)] ++ -- if darcs-test lives in foo/darcs-test/something, look for foo/darcs/darcs[.exe] -- for example after cabal build we can run dist/build/darcs-test/darcs-test and it'll find -- the darcs in dist/build/darcs/darcs [takeDirectory path "darcs" ("darcs" ++ exeSuffix) | takeBaseName path == "darcs-test" ] availableCandidates <- filterM doesFileExist (map toString candidates) case availableCandidates of (darcsBin:_) -> do putStrLn $ "Using darcs executable in " ++ darcsBin return darcsBin [] -> fail ("No darcs specified or found nearby. Perhaps --darcs `pwd`/dist/build/darcs/darcs" ++ exeSuffix ++ "?") v -> return v when (shell conf || network conf || failing conf) $ do unless (isAbsolute $ darcsBin) $ fail ("Argument to --darcs should be an absolute path") unless (exeSuffix `isSuffixOf` darcsBin) $ putStrLn $ "Warning: --darcs flag does not end with " ++ exeSuffix ++ " - some tests may fail (case does matter)" putStrLn $ "Locale encoding is " ++ textEncodingName localeEncoding let repoFormat = (if darcs1 conf then (Darcs1:) else id) . (if darcs2 conf then (Darcs2:) else id) $ [] let diffAlgorithm = (if myers conf then (MyersDiff:) else id) . (if patience conf then (PatienceDiff:) else id) $ [] stests <- shelly $ if shell conf then findShell darcsBin "tests" (testDir conf) (failing conf) diffAlgorithm repoFormat else return [] utests <- if unit conf then doUnit else return [] ntests <- shelly $ if network conf then findShell darcsBin "tests/network" (testDir conf) (failing conf) diffAlgorithm repoFormat else return [] hstests <- if hashed conf then doHashed else return [] defaultMainWithArgs (stests ++ utests ++ ntests ++ hstests) args where exeSuffix :: String #ifdef WIN32 exeSuffix = ".exe" #else exeSuffix = "" #endif main :: IO () main = do hSetBinaryMode stdout True hSetBuffering stdout NoBuffering hSetBinaryMode stderr True hSetBinaryMode stdin True clp <- cmdArgs_ defaultConfig run $ if full clp then clp { hashed = True , shell = True , network = True , unit = True , myers = True , patience = True , darcs1 = True , darcs2 = True } else clp darcs-2.14.5/release/0000755000000000000000000000000007346545000012510 5ustar0000000000000000darcs-2.14.5/release/distributed-context0000755000000000000000000000027707346545000016450 0ustar0000000000000000Just "\nContext:\n\n\n[TAG 2.14.5\nBen Franksen **20200806192304\n Ignore-this: 2c4a08e40916e6c0e2dfde4eb66752af766640f92a4dbb847812e06fc0142c6da8592d68199f6985\n] \n"darcs-2.14.5/release/distributed-version0000755000000000000000000000000607346545000016437 0ustar0000000000000000Just 0darcs-2.14.5/src/Darcs/0000755000000000000000000000000007346545000012713 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch.hs0000644000000000000000000000743207346545000014314 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch ( RepoType , IsRepoType , PrimOf , Named , WrappedNamed , fromPrim , fromPrims , rmfile , addfile , rmdir , adddir , move , hunk , tokreplace , namepatch , anonymous , binary , description , showContextPatch , ShowPatchFor(..) , showPatch , displayPatch , showNicely , infopatch , changepref , thing , things , primIsAddfile , primIsHunk , primIsSetpref , merge , commute , listTouchedFiles , hunkMatches , forceTokReplace , PrimPatch -- * for PatchTest , resolveConflicts , Effect , effect , primIsBinary , primIsAdddir , invert , invertFL , invertRL , commuteFL , commuteFLorComplain , commuteRL , readPatch , readPatchPartial , canonize , sortCoalesceFL , tryToShrink , patchname , patchcontents , applyToFilePaths , apply , applyToTree , maybeApplyToTree , effectOnFilePaths , patch2patchinfo , summary , summaryFL , plainSummary , xmlSummary , plainSummaryPrims , adddeps , getdeps , listConflictedFiles , isInconsistent , module Darcs.Patch.RepoPatch ) where import Darcs.Patch.Apply ( apply,applyToFilePaths, effectOnFilePaths, applyToTree, maybeApplyToTree ) import Darcs.Patch.Commute ( commute, commuteFL, commuteFLorComplain, commuteRL ) import Darcs.Patch.Conflict ( listConflictedFiles, resolveConflicts ) import Darcs.Patch.Effect ( Effect(effect) ) import Darcs.Patch.Invert ( invert, invertRL, invertFL ) import Darcs.Patch.Inspect ( listTouchedFiles, hunkMatches ) import Darcs.Patch.Merge ( merge ) import Darcs.Patch.Named ( Named, adddeps, namepatch, anonymous, getdeps, infopatch, patch2patchinfo, patchname, patchcontents ) import Darcs.Patch.Named.Wrapped ( WrappedNamed ) import Darcs.Patch.Prim ( fromPrims, fromPrim, canonize, sortCoalesceFL, rmdir, rmfile, tokreplace, adddir, addfile, binary, changepref, hunk, move, primIsAdddir, primIsAddfile, primIsHunk, primIsBinary, primIsSetpref, tryToShrink, PrimPatch, PrimPatchBase(..) ) import Darcs.Patch.Read ( readPatch, readPatchPartial ) import Darcs.Patch.Repair ( isInconsistent ) import Darcs.Patch.RepoPatch ( RepoPatch ) import Darcs.Patch.RepoType ( RepoType, IsRepoType ) import Darcs.Patch.Show ( description, showPatch, showNicely, displayPatch , summary, summaryFL, thing, things, ShowPatchFor(..), ShowContextPatch(..) ) import Darcs.Patch.Summary ( xmlSummary, plainSummary, plainSummaryPrims ) import Darcs.Patch.TokenReplace ( forceTokReplace ) darcs-2.14.5/src/Darcs/Patch/0000755000000000000000000000000007346545000013752 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/Annotate.hs0000644000000000000000000002411207346545000016057 0ustar0000000000000000{-# LANGUAGE OverloadedStrings, TypeSynonymInstances, MultiParamTypeClasses #-} -- Copyright (C) 2010 Petr Rockai -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. -- | -- Module : Darcs.Patch.Annotate -- Copyright : 2010 Petr Rockai -- License : MIT -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.Patch.Annotate ( annotateFile , annotateDirectory , format , machineFormat , AnnotateResult , Annotate(..) ) where import Prelude () import Darcs.Prelude import Control.Monad.State ( modify, modify', when, gets, State, execState ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import qualified Data.Map as M import qualified Data.Vector as V import Data.Function ( on ) import Data.List( nub, groupBy ) import Data.Maybe( isJust, mapMaybe ) import qualified Darcs.Patch.Prim.FileUUID as FileUUID import Darcs.Patch.Info ( PatchInfo(..), displayPatchInfo, piAuthor, makePatchname ) import Darcs.Patch.Named ( Named(..) ) import Darcs.Patch.Named.Wrapped ( WrappedNamed(..) ) import Darcs.Patch.PatchInfoAnd( info, PatchInfoAnd, hopefully ) import Darcs.Patch.Prim.V1.Core ( Prim(..), DirPatchType(..), FilePatchType(..) ) import Darcs.Patch.TokenReplace ( annotateReplace ) import Darcs.Patch.Witnesses.Ordered import Darcs.Util.Path ( FileName, movedirfilename, fn2ps, ps2fn ) import Darcs.Util.Printer( renderString ) import Darcs.Util.ByteString ( linesPS, decodeLocale ) data FileOrDirectory = File | Directory deriving (Show, Eq) type AnnotateResult = V.Vector (Maybe PatchInfo, B.ByteString) data Annotated = Annotated { annotated :: !AnnotateResult , current :: ![(Int, B.ByteString)] , path :: (Maybe FileName) , what :: FileOrDirectory , currentInfo :: PatchInfo } deriving Show type AnnotatedM = State Annotated class Annotate p where annotate :: p wX wY -> AnnotatedM () instance Annotate Prim where annotate (FP fn fp) = case fp of RmFile -> do whenPathIs fn $ modify' (\s -> s { path = Nothing }) whenWhatIs Directory $ updateDirectory fn AddFile -> return () Hunk off o n -> whenPathIs fn $ whenWhatIs File $ do let remove = length o let add = length n i <- gets currentInfo c <- gets current a <- gets annotated -- NOTE patches are inverted and in inverse order modify' $ \s -> -- NOTE subtract one from offset because darcs counts from one, -- whereas vectors and lists count from zero. let (to,from) = splitAt (off-1) c in s { current = map eval $ to ++ replicate add (-1, B.empty) ++ drop remove from , annotated = merge i a $ map eval $ take remove $ from } TokReplace t o n -> whenPathIs fn $ whenWhatIs File $ do let test = annotateReplace t (BC.pack o) (BC.pack n) i <- gets currentInfo c <- gets current a <- gets annotated modify' $ \s -> s { current = map (\(ix,b)->if test b then (-1,B.empty) else (ix,b)) c , annotated = merge i a $ map eval $ filter (test . snd) $ c } -- TODO what if the status of a file changed from text to binary? Binary _ _ -> whenPathIs fn $ bug "annotate: can't handle binary changes" annotate (DP _ AddDir) = return () annotate (DP fn RmDir) = whenWhatIs Directory $ do whenPathIs fn $ modify' (\s -> s { path = Nothing }) updateDirectory fn annotate (Move fn fn') = do modify' (\s -> s { path = fmap (movedirfilename fn fn') (path s) }) whenWhatIs Directory $ do let fix (i, x) = (i, fn2ps $ movedirfilename fn fn' (ps2fn x)) modify $ \s -> s { current = map fix $ current s } annotate (ChangePref _ _ _) = return () instance Annotate FileUUID.Prim where annotate _ = bug "annotate not implemented for FileUUID patches" instance Annotate p => Annotate (FL p) where annotate = sequence_ . mapFL annotate instance Annotate p => Annotate (Named p) where annotate (NamedP _ _ p) = annotate p instance Annotate p => Annotate (WrappedNamed rt p) where annotate (NormalP n) = annotate n annotate (RebaseP _ _) = bug "annotate not implemented for Rebase patches" instance Annotate p => Annotate (PatchInfoAnd rt p) where annotate = annotate . hopefully whenWhatIs :: FileOrDirectory -> AnnotatedM () -> AnnotatedM () whenWhatIs w actions = do w' <- gets what when (w == w') actions whenPathIs :: FileName -> AnnotatedM () -> AnnotatedM () whenPathIs fn actions = do p <- gets path when (p == Just fn) actions eval :: (Int, B.ByteString) -> (Int, B.ByteString) eval (i,b) = seq i $ seq b $ (i,b) merge :: a -> V.Vector (Maybe a, BC.ByteString) -> [(Int, t)] -> V.Vector (Maybe a, BC.ByteString) merge i a l = a V.// [ (line, (Just i, B.empty)) | (line, _) <- l, line >= 0 && line < V.length a] updateDirectory :: FileName -> AnnotatedM () updateDirectory p = whenWhatIs Directory $ do let line = fn2ps p files <- gets current case filter ((==line) . snd) files of [match@(ident, _)] -> reannotate ident match line _ -> return () where reannotate ident match line = modify $ \x -> x { annotated = annotated x V.// [ (ident, update line $ currentInfo x) ] , current = filter (/= match) $ current x } update line inf = (Just inf, BC.concat [ " -- created as: ", line ]) complete :: Annotated -> Bool complete x = V.all (isJust . fst) $ annotated x annotate' :: Annotate p => FL (PatchInfoAnd rt p) wX wY -> Annotated -> Annotated annotate' NilFL ann = ann annotate' (p :>: ps) ann | complete ann = ann | otherwise = annotate' ps $ execState (annotate p) (ann { currentInfo = info p }) annotateFile :: Annotate p => FL (PatchInfoAnd rt p) wX wY -> FileName -> B.ByteString -> AnnotateResult annotateFile patches inipath inicontent = annotated $ annotate' patches initial where initial = Annotated { path = Just inipath , currentInfo = bug "There is no currentInfo." , current = zip [0..] (linesPS inicontent) , what = File , annotated = V.replicate (length $ breakLines inicontent) (Nothing, B.empty) } annotateDirectory :: Annotate p => FL (PatchInfoAnd rt p) wX wY -> FileName -> [FileName] -> AnnotateResult annotateDirectory patches inipath inicontent = annotated $ annotate' patches initial where initial = Annotated { path = Just inipath , currentInfo = bug "There is no currentInfo." , current = zip [0..] (map fn2ps inicontent) , what = Directory , annotated = V.replicate (length inicontent) (Nothing, B.empty) } machineFormat :: B.ByteString -> AnnotateResult -> String machineFormat d a = unlines [ case i of Just inf -> show $ makePatchname inf Nothing -> -- make unknowns uniform, for easier parsing take 40 ( repeat '0' ) -- fake hash of the right size ++ " | " ++ BC.unpack line ++ " " ++ BC.unpack add | ((i, add), line) <- zip (V.toList a) (breakLines d) ] format :: B.ByteString -> AnnotateResult -> String format d a = pi_list ++ "\n" ++ numbered where numberedLines = zip [(1 :: Int)..] . lines $ file prependNum (lnum, annLine) = let maxDigits = length . show . length $ numberedLines lnumStr = show lnum paddingNum = maxDigits - length lnumStr in replicate paddingNum ' ' ++ lnumStr ++ ": " ++ annLine numbered = unlines . map prependNum $ numberedLines pi_list = unlines [ show n ++ ": " ++ renderString (displayPatchInfo i) | (n :: Int, i) <- zip [1..] pis ] file = concat [ annotation (fst $ head chunk) ++ " | " ++ line (head chunk) ++ "\n" ++ unlines [ indent 25 (" | " ++ line l) | l <- tail chunk ] | chunk <- file_ann ] pis = nub $ mapMaybe fst $ V.toList a pi_map = M.fromList (zip pis [1 :: Int ..]) file_ann = groupBy ((==) `on` fst) $ zip (V.toList a) (breakLines d) line ((_, add), l) = decodeLocale $ BC.concat [l, " ", add] annotation (Just i, _) | Just n <- M.lookup i pi_map = pad 20 (piMail i) ++ " " ++ pad 4 ('#' : show n) annotation _ = pad 25 "unknown" pad n str = replicate (n - length str) ' ' ++ take n str indent n str = replicate n ' ' ++ str piMail pi | '<' `elem` piAuthor pi = takeWhile (/= '>') . drop 1 . dropWhile (/= '<') $ piAuthor pi | otherwise = piAuthor pi breakLines :: BC.ByteString -> [BC.ByteString] breakLines s = case BC.split '\n' s of [] -> [] split | BC.null (last split) -> init split | otherwise -> split darcs-2.14.5/src/Darcs/Patch/Apply.hs0000644000000000000000000000676307346545000015407 0ustar0000000000000000-- Copyright (C) 2002-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE MultiParamTypeClasses #-} -- | -- Module : Darcs.Patch.Apply -- Copyright : 2002-2005 David Roundy -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.Patch.Apply ( Apply(..) , applyToFilePaths , applyToTree , applyToState , maybeApplyToTree , effectOnFilePaths ) where import Prelude () import Darcs.Prelude import Control.Exception ( catch, IOException ) import Control.Arrow ( (***) ) import Darcs.Util.Tree( Tree ) import Darcs.Patch.ApplyMonad ( ApplyMonad(..), withFileNames, ApplyMonadTrans(..) ) import Darcs.Util.Path( fn2fp, fp2fn ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..) ) class Apply p where type ApplyState p :: (* -> *) -> * apply :: ApplyMonad (ApplyState p) m => p wX wY -> m () instance Apply p => Apply (FL p) where type ApplyState (FL p) = ApplyState p apply NilFL = return () apply (p:>:ps) = apply p >> apply ps instance Apply p => Apply (RL p) where type ApplyState (RL p) = ApplyState p apply NilRL = return () apply (p:<:ps) = apply ps >> apply p effectOnFilePaths :: (Apply p, ApplyState p ~ Tree) => p wX wY -> [FilePath] -> [FilePath] effectOnFilePaths p fps = fps' where (_, fps', _) = applyToFilePaths p Nothing fps applyToFilePaths :: (Apply p, ApplyState p ~ Tree) => p wX wY -> Maybe [(FilePath, FilePath)] -> [FilePath] -> ([FilePath], [FilePath], [(FilePath, FilePath)]) applyToFilePaths pa ofpos fs = toFPs $ withFileNames ofnos fns (apply pa) where fns = map fp2fn fs ofnos = map (fp2fn *** fp2fn) <$> ofpos toFPs (affected, new, renames) = (map fn2fp affected, map fn2fp new, map (fn2fp *** fn2fp) renames) -- | Apply a patch to a 'Tree', yielding a new 'Tree'. applyToTree :: (Apply p, Monad m, ApplyState p ~ Tree) => p wX wY -> Tree m -> m (Tree m) applyToTree = applyToState applyToState :: forall p m wX wY. (Apply p, ApplyMonadTrans (ApplyState p) m) => p wX wY -> (ApplyState p) m -> m ((ApplyState p) m) applyToState patch t = snd <$> runApplyMonad (apply patch) t -- | Attempts to apply a given replace patch to a Tree. If the apply fails (if -- the file the patch applies to already contains the target token), we return -- Nothing, otherwise we return the updated Tree. maybeApplyToTree :: (Apply p, ApplyState p ~ Tree) => p wX wY -> Tree IO -> IO (Maybe (Tree IO)) maybeApplyToTree patch tree = (Just `fmap` applyToTree patch tree) `catch` (\(_ :: IOException) -> return Nothing) darcs-2.14.5/src/Darcs/Patch/ApplyMonad.hs0000644000000000000000000002012407346545000016351 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-missing-methods -fno-warn-orphans #-} {-# LANGUAGE TypeSynonymInstances, MultiParamTypeClasses , ConstraintKinds, UndecidableInstances , UndecidableSuperClasses #-} -- Copyright (C) 2010, 2011 Petr Rockai -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. module Darcs.Patch.ApplyMonad ( ApplyMonad(..), ApplyMonadTrans(..), ApplyMonadState(..) , withFileNames, withFiles, ToTree(..) , ApplyMonadTree(..) ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import qualified Data.Map as M import qualified Darcs.Util.Tree.Monad as TM import Darcs.Util.Tree ( Tree ) import Data.Maybe ( fromMaybe ) import Darcs.Util.Path ( FileName, movedirfilename, fn2fp, isParentOrEqOf, floatPath, AnchoredPath ) import Control.Monad.State.Strict import Control.Monad.Identity( Identity ) import Darcs.Patch.MonadProgress import GHC.Exts ( Constraint ) fn2ap :: FileName -> AnchoredPath fn2ap = floatPath . fn2fp class ToTree s where toTree :: s m -> Tree m instance ToTree Tree where toTree = id class (Functor m, Monad m, ApplyMonad state (ApplyMonadOver state m)) => ApplyMonadTrans (state :: (* -> *) -> *) m where type ApplyMonadOver state m :: * -> * runApplyMonad :: (ApplyMonadOver state m) x -> state m -> m (x, state m) instance (Functor m, Monad m) => ApplyMonadTrans Tree m where type ApplyMonadOver Tree m = TM.TreeMonad m runApplyMonad = TM.virtualTreeMonad class ApplyMonadState (state :: (* -> *) -> *) where type ApplyMonadStateOperations state :: (* -> *) -> Constraint class (Functor m, Monad m) => ApplyMonadTree m where -- a semantic, Tree-based interface for patch application mDoesDirectoryExist :: FileName -> m Bool mDoesFileExist :: FileName -> m Bool mReadFilePS :: FileName -> m B.ByteString mCreateDirectory :: FileName -> m () mRemoveDirectory :: FileName -> m () mCreateFile :: FileName -> m () mCreateFile f = mModifyFilePS f $ \_ -> return B.empty mRemoveFile :: FileName -> m () mRename :: FileName -> FileName -> m () mModifyFilePS :: FileName -> (B.ByteString -> m B.ByteString) -> m () mChangePref :: String -> String -> String -> m () mChangePref _ _ _ = return () instance ApplyMonadState Tree where type ApplyMonadStateOperations Tree = ApplyMonadTree class ( Functor m, Monad m, Functor (ApplyMonadBase m), Monad (ApplyMonadBase m) , ApplyMonadStateOperations state m, ToTree state ) -- ApplyMonadOver (ApplyMonadBase m) ~ m is *not* required in general, -- since ApplyMonadBase is not injective => ApplyMonad (state :: (* -> *) -> *) m where type ApplyMonadBase m :: * -> * nestedApply :: m x -> state (ApplyMonadBase m) -> m (x, state (ApplyMonadBase m)) liftApply :: (state (ApplyMonadBase m) -> (ApplyMonadBase m) x) -> state (ApplyMonadBase m) -> m (x, state (ApplyMonadBase m)) getApplyState :: m (state (ApplyMonadBase m)) instance (Functor m, Monad m) => ApplyMonad Tree (TM.TreeMonad m) where type ApplyMonadBase (TM.TreeMonad m) = m getApplyState = gets TM.tree nestedApply a start = lift $ runApplyMonad a start liftApply a start = do x <- gets TM.tree lift $ runApplyMonad (lift $ a x) start instance (Functor m, Monad m) => ApplyMonadTree (TM.TreeMonad m) where mDoesDirectoryExist d = TM.directoryExists (fn2ap d) mDoesFileExist d = TM.fileExists (fn2ap d) mReadFilePS p = B.concat `fmap` BL.toChunks `fmap` TM.readFile (fn2ap p) mModifyFilePS p j = do have <- TM.fileExists (fn2ap p) x <- if have then B.concat `fmap` BL.toChunks `fmap` TM.readFile (fn2ap p) else return B.empty TM.writeFile (fn2ap p) . BL.fromChunks . (:[]) =<< j x mCreateDirectory p = TM.createDirectory (fn2ap p) mRename from to = TM.rename (fn2ap from) (fn2ap to) mRemoveDirectory = TM.unlink . fn2ap mRemoveFile = TM.unlink . fn2ap -- Latest name, current original name. type OrigFileNameOf = (FileName, FileName) -- Touched files, new file list (after removes etc.) and rename details type FilePathMonadState = ([FileName], [FileName], [OrigFileNameOf]) type FilePathMonad = State FilePathMonadState -- |trackOrigRename takes an old and new name and attempts to apply the mapping -- to the OrigFileNameOf pair. If the old name is the most up-to-date name of -- the file in question, the first element of the OFNO will match, otherwise if -- the up-to-date name was originally old, the second element will match. trackOrigRename :: FileName -> FileName -> OrigFileNameOf -> OrigFileNameOf trackOrigRename old new pair@(latest, from) | old `isParentOrEqOf` latest = (latest, movedirfilename old new latest) | old `isParentOrEqOf` from = (latest, movedirfilename old new from) | otherwise = pair -- |withFileNames takes a maybe list of existing rename-pairs, a list of -- filenames and an action, and returns the resulting triple of affected files, -- updated filename list and new rename details. If the rename-pairs are not -- present, a new list is generated from the filesnames. withFileNames :: Maybe [OrigFileNameOf] -> [FileName] -> FilePathMonad a -> FilePathMonadState withFileNames mbofnos fps x = execState x ([], fps, ofnos) where ofnos = fromMaybe (map (\y -> (y, y)) fps) mbofnos instance ApplyMonad Tree FilePathMonad where type ApplyMonadBase FilePathMonad = Identity instance ApplyMonadTree FilePathMonad where -- We can't check it actually is a directory here mDoesDirectoryExist d = gets $ \(_, fs, _) -> d `elem` fs mCreateDirectory = mCreateFile mCreateFile f = modify $ \(ms, fs, rns) -> (f : ms, fs, rns) mRemoveFile f = modify $ \(ms, fs, rns) -> (f : ms, filter (/= f) fs, rns) mRemoveDirectory = mRemoveFile mRename a b = modify $ \(ms, fs, rns) -> ( a : b : ms , map (movedirfilename a b) fs , map (trackOrigRename a b) rns) mModifyFilePS f _ = mCreateFile f instance MonadProgress FilePathMonad where runProgressActions = silentlyRunProgressActions type RestrictedApply = State (M.Map FileName B.ByteString) instance ApplyMonad Tree RestrictedApply where type ApplyMonadBase RestrictedApply = Identity instance ApplyMonadTree RestrictedApply where mDoesDirectoryExist _ = return True mCreateDirectory _ = return () mRemoveFile f = modify $ M.delete f mRemoveDirectory _ = return () mRename a b = modify $ M.mapKeys (movedirfilename a b) mModifyFilePS f j = do look <- gets $ M.lookup f case look of Nothing -> return () Just bits -> do new <- j bits modify $ M.insert f new instance MonadProgress RestrictedApply where runProgressActions = silentlyRunProgressActions withFiles :: [(FileName, B.ByteString)] -> RestrictedApply a -> [(FileName, B.ByteString)] withFiles p x = M.toList $ execState x $ M.fromList p darcs-2.14.5/src/Darcs/Patch/ApplyPatches.hs0000644000000000000000000000172307346545000016706 0ustar0000000000000000module Darcs.Patch.ApplyPatches ( applyPatches ) where import Darcs.Patch.Info ( displayPatchInfo ) import Darcs.Patch.ApplyMonad ( ApplyMonad(..) ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, hopefully, info ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.MonadProgress ( MonadProgress, ProgressAction(..), runProgressActions) import Darcs.Patch.Witnesses.Ordered ( FL(..), mapFL ) import Darcs.Util.Printer ( text, ($$) ) applyPatches :: (MonadProgress m, ApplyMonad (ApplyState p) m, Apply p) => FL (PatchInfoAnd rt p) wX wY -> m () applyPatches ps = runProgressActions "Applying patch" (mapFL doApply ps) where doApply hp = ProgressAction { paAction = apply (hopefully hp) , paMessage = displayPatchInfo (info hp) , paOnError = text "Unapplicable patch:" $$ displayPatchInfo (info hp) } darcs-2.14.5/src/Darcs/Patch/Bracketed.hs0000644000000000000000000000336407346545000016200 0ustar0000000000000000module Darcs.Patch.Bracketed ( Bracketed(..), mapBracketed, unBracketed , BracketedFL, mapBracketedFLFL, unBracketedFL ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Format ( PatchListFormat ) import Darcs.Patch.Witnesses.Ordered ( FL(..), mapFL_FL, concatFL ) -- |This type exists for legacy support of on-disk format patch formats. -- It is a wrapper type that explicitly tracks the nesting of braces and parens -- in the on-disk representation of such patches. It is used as an intermediate -- form when reading such patches normally, and also for round-tripping such -- patches when checking the hash in bundles. -- It shouldn't be used for anything else. data Bracketed p wX wY where Singleton :: p wX wY -> Bracketed p wX wY -- A single patch, not wrapped in anything Braced :: BracketedFL p wX wY -> Bracketed p wX wY -- A list of patches, wrapped in {} Parens :: BracketedFL p wX wY -> Bracketed p wX wY -- A list of patches, wrapped in () type BracketedFL p wX wY = FL (Bracketed p) wX wY unBracketed :: Bracketed p wX wY -> FL p wX wY unBracketed (Singleton p) = p :>: NilFL unBracketed (Braced ps) = unBracketedFL ps unBracketed (Parens ps) = unBracketedFL ps unBracketedFL :: BracketedFL p wX wY -> FL p wX wY unBracketedFL = concatFL . mapFL_FL unBracketed mapBracketed :: (forall wA wB . p wA wB -> q wA wB) -> Bracketed p wX wY -> Bracketed q wX wY mapBracketed f (Singleton p) = Singleton (f p) mapBracketed f (Braced ps) = Braced (mapBracketedFLFL f ps) mapBracketed f (Parens ps) = Parens (mapBracketedFLFL f ps) mapBracketedFLFL :: (forall wA wB . p wA wB -> q wA wB) -> BracketedFL p wX wY -> BracketedFL q wX wY mapBracketedFLFL f = mapFL_FL (mapBracketed f) instance PatchListFormat (Bracketed p) darcs-2.14.5/src/Darcs/Patch/Bracketed/0000755000000000000000000000000007346545000015636 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/Bracketed/Instances.hs0000644000000000000000000000332007346545000020117 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Bracketed.Instances () where import Darcs.Patch.Bracketed ( Bracketed(..) ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.Prim ( FromPrim(..), PrimPatchBase(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(NilFL), mapFL ) import Darcs.Util.Printer ( vcat, blueText, ($$) ) -- The PrimPatchBase, Effect and FromPrim instances are only -- needed (by Darcs.Patch.Bundle) because the ReadPatch instance for -- WrappedNamed unconditionally has them as requirements even though -- they are only needed for the 'IsRebase case which isn't itself used -- by Darcs.Patch.Bundle. -- TODO see if this can be simplified instance PrimPatchBase p => PrimPatchBase (Bracketed p) where type PrimOf (Bracketed p) = PrimOf p instance Effect p => Effect (Bracketed p) where effect (Singleton p) = effect p effect (Braced ps) = effect ps effect (Parens ps) = effect ps effectRL (Singleton p) = effectRL p effectRL (Braced ps) = effectRL ps effectRL (Parens ps) = effectRL ps instance FromPrim p => FromPrim (Bracketed p) where fromPrim p = Singleton (fromPrim p) instance ShowPatchBasic p => ShowPatchBasic (Bracketed p) where showPatch f (Singleton p) = showPatch f p showPatch _ (Braced NilFL) = blueText "{" $$ blueText "}" showPatch f (Braced ps) = blueText "{" $$ vcat (mapFL (showPatch f) ps) $$ blueText "}" showPatch f (Parens ps) = blueText "(" $$ vcat (mapFL (showPatch f) ps) $$ blueText ")" -- the ReadPatch instance is defined in Darcs.Patch.Read as it is -- used as an intermediate form during reading of lists of patches -- that are specified as ListFormatV1 or ListFormatV2. darcs-2.14.5/src/Darcs/Patch/Bundle.hs0000644000000000000000000003407707346545000015532 0ustar0000000000000000-- Copyright (C) 2002-2004,2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.Bundle ( makeBundleN , scanBundle , contextPatches , scanContextFile , patchFilename , minContext ) where import Prelude () import Darcs.Prelude import Data.Char ( isAlpha, toLower, isDigit, isSpace ) import qualified Data.ByteString as B ( ByteString, length, null, drop, isPrefixOf ) import qualified Data.ByteString.Char8 as BC ( unpack, break, pack ) import Darcs.Util.Tree( Tree ) import Darcs.Util.Tree.Monad( virtualTreeIO ) import Darcs.Patch ( RepoPatch, showPatch, showContextPatch, readPatchPartial ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Bracketed ( Bracketed, unBracketedFL ) import Darcs.Patch.Bracketed.Instances () import Darcs.Patch.Commute( commute ) import Darcs.Patch.Depends ( slightlyOptimizePatchset ) import Darcs.Patch.Format ( PatchListFormat ) import Darcs.Patch.Info ( PatchInfo, readPatchInfo, showPatchInfo, displayPatchInfo, isTag ) import Darcs.Patch.Named.Wrapped ( WrappedNamed ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, piap, fmapFLPIAP, info, patchInfoAndPatch, unavailable, hopefully, generaliseRepoTypePIAP ) import Darcs.Patch.ReadMonads ( parseStrictly ) import Darcs.Patch.RepoType ( RepoType(..), RebaseType(..) ) import Darcs.Patch.Set ( PatchSet(..), Tagged(..), SealedPatchSet, Origin ) import Darcs.Patch.Show ( ShowPatchBasic, ShowPatchFor(ForStorage) ) import Darcs.Patch.Witnesses.Ordered ( RL(..), FL(..), (:>)(..), reverseFL, (+<+), mapFL, mapFL_FL, mapRL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), seal ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Util.ByteString ( mmapFilePS, linesPS, unlinesPS, dropSpace, substrPS, decodeLocale ) import Darcs.Util.Hash ( sha1PS ) import Darcs.Util.Printer ( Doc, renderPS, newline, text, ($$), vcat, vsep, renderString ) -- |hashBundle creates a SHA1 string of a given a FL of named patches. This -- allows us to ensure that the patches in a received patchBundle have not been -- modified in transit. hashBundle :: (PatchListFormat p, ShowPatchBasic p) => FL (WrappedNamed rt p) wX wY -> String hashBundle to_be_sent = show $ sha1PS $ renderPS $ vcat (mapFL (showPatch ForStorage) to_be_sent) <> newline makeBundleN :: (ApplyState p ~ Tree, RepoPatch p) => Maybe (Tree IO) -> PatchSet rt p wStart wX -> FL (WrappedNamed rt p) wX wY -> IO Doc makeBundleN the_s (PatchSet (_ :<: Tagged t _ _) ps) to_be_sent = makeBundle2 the_s ((NilRL :<: t) +<+ ps) to_be_sent to_be_sent makeBundleN the_s (PatchSet NilRL ps) to_be_sent = makeBundle2 the_s ps to_be_sent to_be_sent -- | In makeBundle2, it is presumed that the two patch sequences are -- identical, but that they may be lazily generated. If two different -- patch sequences are passed, a bundle with a mismatched hash will be -- generated, which is not the end of the world, but isn't very useful -- either. makeBundle2 :: (ApplyState p ~ Tree, RepoPatch p) => Maybe (Tree IO) -> RL (PatchInfoAnd rt p) wStart wX -> FL (WrappedNamed rt p) wX wY -> FL (WrappedNamed rt p) wX wY -> IO Doc makeBundle2 the_s common' to_be_sent to_be_sent2 = do patches <- case the_s of Just tree -> fst `fmap` virtualTreeIO (showContextPatch ForStorage to_be_sent) tree Nothing -> return (vsep $ mapFL (showPatch ForStorage) to_be_sent) return $ format patches where format the_new = text "" $$ text "New patches:" $$ text "" $$ the_new $$ text "" $$ text "Context:" $$ text "" $$ vcat (map (showPatchInfo ForStorage) common) $$ text "Patch bundle hash:" $$ text (hashBundle to_be_sent2) $$ text "" common = mapRL info common' parseBundle :: forall rt p. RepoPatch p => B.ByteString -> Either String (Sealed ((PatchSet rt p :> FL (PatchInfoAnd rt p)) Origin)) parseBundle input | B.null input = Left "Bad patch bundle!" parseBundle input = case sillyLex input of ("New patches:", rest) -> case getPatches rest of (Sealed bracketedPatches, rest') -> case sillyLex rest' of ("Context:", rest'') -> case getContext rest'' of (cont, maybe_hash) -> let sealedCtxAndPs = sealCtxAndPs cont bracketedPatches in case substrPS (BC.pack "Patch bundle hash:") maybe_hash of Just n -> let hPs = mapFL_FL hopefully bracketedPatches realHash = hashBundle hPs getHash = fst . sillyLex . snd . sillyLex bundleHash = getHash $ B.drop n maybe_hash in if realHash == bundleHash then sealedCtxAndPs else Left hashFailureMessage Nothing -> sealedCtxAndPs (a, r) -> Left $ "Malformed patch bundle: '" ++ a ++ "' is not 'Context:'\n" ++ BC.unpack r ("Context:", rest) -> case getContext rest of (cont, rest') -> case sillyLex rest' of ("New patches:", rest'') -> case getPatches rest'' of (Sealed bracketedPatches, _) -> Right $ sealContextWithPatches cont bracketedPatches (a, _) -> Left $ "Malformed patch bundle: '" ++ a ++ "' is not 'New patches:'" ("-----BEGIN PGP SIGNED MESSAGE-----",rest) -> parseBundle $ filterGpgDashes rest (_, rest) -> parseBundle rest where hashFailureMessage = "Patch bundle failed hash!\n" ++ "This probably means that the patch has been " ++ "corrupted by a mailer.\n" ++ "The most likely culprit is CRLF newlines." sealCtxAndPs ctx ps = Right $ sealContextWithPatches ctx ps sealContextWithPatches :: [PatchInfo] -> FL (PatchInfoAnd ('RepoType 'NoRebase) (Bracketed p)) wX wY -> Sealed ((PatchSet rt p :> FL (PatchInfoAnd rt p)) Origin) sealContextWithPatches context bracketedPatches = let -- witness to fmapFLPIAP that the bundle won't contain stash/rebase patches -- TODO use EmptyCase with GHC 7.8+ notRebasing _ = error "internal error: unreachable case (Darcs.Patch.Bundle.parseBundle.notRebasing)" patches = mapFL_FL (generaliseRepoTypePIAP . fmapFLPIAP unBracketedFL notRebasing) bracketedPatches in case reverse context of (x : ry) | isTag x -> let ps = unavailablePatches (reverse ry) t = Tagged (piUnavailable x) Nothing NilRL in Sealed $ PatchSet (NilRL :<: t) ps :> patches _ -> let ps = PatchSet NilRL (unavailablePatches context) in Sealed $ ps :> patches -- The above NilRLs aren't quite right, because ther *are* -- earlier patches, but we can't set this to undefined -- because there are situations where we look at the rest. -- :{ scanBundle :: forall rt p . RepoPatch p => B.ByteString -> Either String (SealedPatchSet rt p Origin) scanBundle bundle = do Sealed (PatchSet tagged recent :> ps) <- parseBundle bundle return . Sealed $ PatchSet tagged (recent +<+ reverseFL ps) -- |filterGpgDashes unescapes a clearsigned patch, which will have had any -- lines starting with dashes escaped with a leading "- ". filterGpgDashes :: B.ByteString -> B.ByteString filterGpgDashes ps = unlinesPS $ map drop_dashes $ takeWhile (/= BC.pack "-----END PGP SIGNED MESSAGE-----") $ dropWhile not_context_or_newpatches $ linesPS ps where drop_dashes x | B.length x < 2 = x | BC.pack "- " `B.isPrefixOf` x = B.drop 2 x | otherwise = x not_context_or_newpatches s = (s /= BC.pack "Context:") && (s /= BC.pack "New patches:") -- |unavailablePatches converts a list of PatchInfos into a RL of PatchInfoAnd -- Unavailable patches. This is used to represent the Context of a patchBundle. unavailablePatches :: [PatchInfo] -> RL (PatchInfoAnd rt p) wX wY unavailablePatches = foldr (flip (:<:) . piUnavailable) (unsafeCoerceP NilRL) -- |piUnavailable returns an Unavailable within a PatchInfoAnd given a -- PatchInfo. piUnavailable :: PatchInfo -> PatchInfoAnd rt p wX wY piUnavailable i = patchInfoAndPatch i . unavailable $ "Patch not stored in patch bundle:\n" ++ renderString (displayPatchInfo i) -- |getContext parses a context list, returning a tuple containing the list, -- and remaining ByteString input. getContext :: B.ByteString -> ([PatchInfo],B.ByteString) getContext ps = case parseStrictly readPatchInfo ps of Just (pinfo, r') -> case getContext r' of (pis, r'') -> (pinfo : pis, r'') Nothing -> ([], ps) -- |(-:-) is used to build up a Sealed FL of patches and tuple it, along with -- any unconsumed input. (-:-) :: a wX wY -> (Sealed (FL a wY), b) -> (Sealed (FL a wX), b) p -:- (Sealed ps, r) = (Sealed (p :>: ps), r) -- |getPatches attempts to parse a sequence of patches from a ByteString, -- returning the FL of as many patches-with-info as were successfully parsed, -- along with any unconsumed input. getPatches :: RepoPatch p => B.ByteString -> (Sealed (FL (PatchInfoAnd ('RepoType 'NoRebase) (Bracketed p)) wX), B.ByteString) getPatches ps = case parseStrictly readPatchInfo ps of Nothing -> (Sealed NilFL, ps) Just (pinfo, _) -> case readPatchPartial ps of Nothing -> (Sealed NilFL, ps) Just (Sealed p, r) -> (pinfo `piap` p) -:- getPatches r -- |sillyLex takes a ByteString and breaks it upon the first newline, having -- removed any leading spaces. The before-newline part is unpacked to a String, -- and tupled up with the remaining ByteString. sillyLex :: B.ByteString -> (String, B.ByteString) sillyLex ps = (decodeLocale a, b) where (a, b) = BC.break (== '\n') (dropSpace ps) contextPatches :: PatchSet rt p Origin wX -> (PatchSet rt p :> RL (PatchInfoAnd rt p)) Origin wX contextPatches set = case slightlyOptimizePatchset set of PatchSet (ts :<: Tagged t _ ps') ps -> PatchSet ts ps' :> ((NilRL :<: t) +<+ ps) PatchSet NilRL ps -> PatchSet NilRL NilRL :> ps -- |'scanContextFile' scans the context in the file of the given name. scanContextFile :: FilePath -> IO (PatchSet rt p Origin wX) scanContextFile filename = scanContext `fmap` mmapFilePS filename where -- are the type witnesses sensible? scanContext :: B.ByteString -> PatchSet rt p Origin wX scanContext input | B.null input = error "Bad context!" | otherwise = case sillyLex input of ("Context:",rest) -> case getContext rest of (cont@(_ : _), _) | isTag (last cont) -> let ps = unavailablePatches $ init cont t = Tagged (piUnavailable $ last cont) Nothing NilRL in PatchSet (NilRL :<: t) ps (cont, _) -> PatchSet NilRL (unavailablePatches cont) ("-----BEGIN PGP SIGNED MESSAGE-----",rest) -> scanContext $ filterGpgDashes rest (_, rest) -> scanContext rest -- | Minimize the context of a bundle to be sent, taking into account -- the patches selected to be sent minContext :: (RepoPatch p) => PatchSet rt p wStart wB -> FL (PatchInfoAnd rt p) wB wC -> Sealed ((PatchSet rt p :> FL (PatchInfoAnd rt p)) wStart) minContext (PatchSet behindTag topCommon) to_be_sent = case go topCommon NilFL to_be_sent of Sealed (c :> to_be_sent') -> seal (PatchSet behindTag c :> to_be_sent') where go :: (RepoPatch p) => RL (PatchInfoAnd rt p) wA wB -- context we attempt to minimize -> FL (PatchInfoAnd rt p) wB wC -- patches we cannot remove from context -> FL (PatchInfoAnd rt p) wC wD -- patches to be included in the bundle -> Sealed (( RL (PatchInfoAnd rt p) :> FL (PatchInfoAnd rt p) ) wA ) go NilRL necessary to_be_sent' = seal (reverseFL necessary :> to_be_sent') go (rest :<: candidate) necessary to_be_sent' = let fl1 = (candidate :>: NilFL) in case commute (fl1 :> necessary) of Nothing -> go rest (candidate :>: necessary) to_be_sent' Just (necessary' :> fl1') -> case commute (fl1' :> to_be_sent') of Nothing -> go rest (candidate :>: necessary) to_be_sent' Just (to_be_sent'' :> _) -> -- commutation work, we can drop the patch go rest necessary' to_be_sent'' -- |patchFilename maps a patch description string to a safe (lowercased, spaces -- removed and ascii-only characters) patch filename. patchFilename :: String -> String patchFilename the_summary = name ++ ".dpatch" where name = map safeFileChar the_summary safeFileChar c | isAlpha c = toLower c | isDigit c = c | isSpace c = '-' safeFileChar _ = '_' darcs-2.14.5/src/Darcs/Patch/Choices.hs0000644000000000000000000005152207346545000015670 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | The purpose of this module is to deal with many of the common -- cases that come up when choosing a subset of a group of patches. -- -- The idea is to divide a sequence of candidate patches into an initial -- section named 'InFirst', a final section named 'InLast', and between them a -- third section of not yet decided patches named 'InMiddle'. The reason for the -- neutral terminology 'InFirst', 'InMiddle', and 'InLast', is that which of 'InFirst' -- and 'InLast' counts as @selected@ or @deselected@ depends on -- what we want to achive, that is, on the command and its options. -- See "Darcs.UI.SelectChanges" for examples of how to use the functions from -- this module. -- -- Obviously if there are dependencies between the patches that will put a -- constraint on how you can choose to divide them up. Unless stated otherwise, -- functions that move patches from one section to another pull all dependent -- patches with them. -- -- Internally, we don't necessarily reorder patches immediately, but merely -- tag them with the desired status, and thus postpone the actual commutation. -- This saves a lot of unnecessary work, especially when choices are made -- interactively, where the user can revise earlier decisions. module Darcs.Patch.Choices ( -- * Choosing patches PatchChoices , Slot(..) -- ** Constructing , patchChoices , mkPatchChoices -- ** Querying , patchSlot , getChoices , separateFirstMiddleFromLast , separateFirstFromMiddleLast -- ** Forcing patches into a given 'Slot' , forceMatchingFirst , forceFirsts , forceFirst , forceMatchingLast , forceLasts , forceLast , forceMiddle , makeEverythingSooner , makeEverythingLater -- ** Operations on 'InMiddle' patches , selectAllMiddles , refineChoices -- ** Substitution , substitute -- * Labelling patches , LabelledPatch , Label , label , unLabel , labelPatches , getLabelInt ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Merge ( Merge, merge ) import Darcs.Patch.Invert ( Invert, invert ) import Darcs.Patch.Commute ( Commute, commute, commuteRL ) import Darcs.Patch.Inspect ( PatchInspect, listTouchedFiles, hunkMatches ) import Darcs.Patch.Permutations ( commuteWhatWeCanRL, commuteWhatWeCanFL ) import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..) , (:>)(..), (:\/:)(..), (:/\:)(..), (:||:)(..) , zipWithFL, mapFL_FL, concatFL , (+>+), reverseRL, anyFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed2(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) -- | 'Label' @mp i@ acts as a temporary identifier to help us keep track of patches -- during the selection process. These are useful for finding patches that -- may have moved around during patch selection (being pushed forwards or -- backwards as dependencies arise). -- -- The identifier is implemented as a tuple @Label mp i@. The @i@ is an -- integer, expected to be unique within the patches being -- scrutinised. The @mp@ is motivated by patch splitting; it -- provides a convenient way to generate a new identifier from the patch -- being split. For example, if we split a patch identified as @Label Nothing -- 5@, the resulting sub-patches could be identified as -- @Label (Just (Label Nothing 5))1@, @Label (Just (Label Nothing 5)) 2@, etc. -- -- IOW, 'Label' is a non-empty, reversed list of 'Int's. data Label = Label (Maybe Label) Int deriving Eq -- | A patch with a 'Label' attached to it. data LabelledPatch p wX wY = LP Label (p wX wY) -- | This internal type tags a 'LabelledPatch' with a 'Bool', to distinguish -- 'InMiddle' from 'InLast' patches. data PatchChoice p wX wY = PC { pcPatch :: (LabelledPatch p wX wY) -- ^ the 'LabelledPatch' in question , _pcIsLast :: Bool -- ^ 'False' = 'InMiddle', 'True' = 'InLast' } -- | Internal function to tag a 'LabelledPatch' as 'InMiddle' or 'InLast'. pcSetLast :: Bool -> LabelledPatch p wX wY -> PatchChoice p wX wY pcSetLast = flip PC -- TODO pcsFirsts should be an 'RL', not an 'FL'. -- | A sequence of 'LabelledPatch'es where each patch is either -- 'InFirst', 'InMiddle', or 'InLast'. The representation is -- optimized for the case where we start chosing patches from the left -- of the sequence: patches that are 'InFirst' are commuted to the head -- immediately, but patches that are 'InMiddle' or 'InLast' are mixed -- together; when a patch is marked 'InLast', its dependencies are -- not updated until we retrieve the final result. data PatchChoices p wX wY where PCs :: { pcsFirsts :: FL (LabelledPatch p) wX wM , pcsMiddleLasts :: FL (PatchChoice p) wM wY} -> PatchChoices p wX wY -- | See module documentation for "Darcs.Patch.Choices". data Slot = InFirst | InMiddle | InLast label :: LabelledPatch p wX wY -> Label label (LP tg _) = tg getLabelInt :: Label -> Int getLabelInt (Label _ i) = i unLabel :: LabelledPatch p wX wY -> p wX wY unLabel (LP _ p) = p -- This is dangerous if two patches from different labelled series are compared -- ideally Label (and hence LabelledPatch/PatchChoices) would have a witness type -- to represent the originally labelled sequence. compareLabels :: LabelledPatch p wA wB -> LabelledPatch p wC wD -> EqCheck (wA, wB) (wC, wD) compareLabels (LP l1 _) (LP l2 _) = if l1 == l2 then unsafeCoerceP IsEq else NotEq instance Eq2 p => Eq2 (LabelledPatch p) where unsafeCompare (LP l1 p1) (LP l2 p2) = l1 == l2 && unsafeCompare p1 p2 instance Invert p => Invert (LabelledPatch p) where invert (LP t p) = LP t (invert p) instance Commute p => Commute (LabelledPatch p) where commute (LP l1 p1 :> LP l2 p2) = do p2' :> p1' <- commute (p1 :> p2) return (LP l2 p2' :> LP l1 p1') instance PatchInspect p => PatchInspect (LabelledPatch p) where listTouchedFiles = listTouchedFiles . unLabel hunkMatches f = hunkMatches f . unLabel instance Merge p => Merge (LabelledPatch p) where merge (LP l1 p1 :\/: LP l2 p2) = case merge (p1 :\/: p2) of p2' :/\: p1' -> LP l2 p2' :/\: LP l1 p1' instance Commute p => Commute (PatchChoice p) where commute (PC p1 c1 :> PC p2 c2) = do p2' :> p1' <- commute (p1 :> p2) return (PC p2' c2 :> PC p1' c1) instance PatchInspect p => PatchInspect (PatchChoice p) where listTouchedFiles = listTouchedFiles . pcPatch hunkMatches f = hunkMatches f . pcPatch instance Merge p => Merge (PatchChoice p) where merge (PC lp1 c1 :\/: PC lp2 c2) = case merge (lp1 :\/: lp2) of lp2' :/\: lp1' -> PC lp2' c2 :/\: PC lp1' c1 -- | Create a 'PatchChoices' from a sequence of patches, so that -- all patches are initially 'InMiddle'. patchChoices :: FL p wX wY -> PatchChoices p wX wY patchChoices = mkPatchChoices . labelPatches Nothing -- | Label a sequence of patches, maybe using the given parent label. labelPatches :: Maybe Label -> FL p wX wY -> FL (LabelledPatch p) wX wY labelPatches tg ps = zipWithFL LP (map (Label tg) [1..]) ps -- | Create a 'PatchChoices' from an already labelled sequence of patches, -- so that all patches are initially 'InMiddle'. mkPatchChoices :: FL (LabelledPatch p) wX wY -> PatchChoices p wX wY mkPatchChoices = PCs NilFL . mapFL_FL (pcSetLast False) instance Eq2 p => Eq2 (PatchChoice p) where unsafeCompare (PC lp1 _) (PC lp2 _) = unsafeCompare lp1 lp2 -- | Like 'getChoices' but lumps together 'InMiddle' and 'InLast' patches. -- This is more efficient than using 'getChoices' and then catenating 'InMiddle' -- and 'InLast' sections because we have to commute less. -- (This is what 'PatchChoices' are optimized for.) -- -- prop> separateFirstFromMiddleLast c == case getChoices c of f:>m:>l -> f:>m+>+l separateFirstFromMiddleLast :: PatchChoices p wX wZ -> (FL (LabelledPatch p) :> FL (LabelledPatch p)) wX wZ separateFirstFromMiddleLast (PCs f ml) = f :> mapFL_FL pcPatch ml -- | Like 'getChoices' but lumps together 'InFirst' and 'InMiddle' patches. -- -- prop> separateFirstMiddleFromLast c == case getChoices c of f:>m:>l -> f+>+m:>l separateFirstMiddleFromLast :: Commute p => PatchChoices p wX wZ -> (FL (LabelledPatch p) :> FL (LabelledPatch p)) wX wZ separateFirstMiddleFromLast (PCs f l) = case pushLasts l of (m :> l') -> f +>+ m :> l' -- | Retrieve the resulting sections from a 'PatchChoice'. The result is a -- triple @first:>middle:>last@, such that all patches in @first@ are -- 'InFirst', all patches in @middle@ are 'InMiddle', and all patches in @last@ -- are 'InLast'. getChoices :: Commute p => PatchChoices p wX wY -> (FL (LabelledPatch p) :> FL (LabelledPatch p) :> FL (LabelledPatch p)) wX wY getChoices (PCs f ml) = case pushLasts ml of (m :> l') -> f :> m :> l' -- | Internal function to commute patches in the common 'pcsMiddleLasts' segment -- so that all 'InLast' patches are behind 'InMiddle' ones. Patches 'InMiddle' -- that depend on any 'InLast' are promoted to 'InLast'. pushLasts :: Commute p => FL (PatchChoice p) wX wY -> (FL (LabelledPatch p) :> FL (LabelledPatch p)) wX wY pushLasts NilFL = NilFL :> NilFL pushLasts (PC lp False :>: pcs) = case pushLasts pcs of (m :> l) -> (lp :>: m) :> l pushLasts (PC lp True :>: pcs) = case pushLasts pcs of (m :> l) -> case commuteWhatWeCanFL (lp :> m) of (m' :> lp' :> deps) -> m' :> (lp' :>: deps +>+ l) -- TODO for the way we use this function it is too restrictive IMO: it does not -- allow the user to select anything that doesn't match the pre-filters. -- | Use the given monadic 'PatchChoices' transformer on the 'InMiddle' section -- of a 'PatchChoices', then fold the result back into the original 'PatchChoices'. refineChoices :: (Commute p, Monad m) => (forall wU wV . FL (LabelledPatch p) wU wV -> PatchChoices p wU wV -> m (PatchChoices p wU wV)) -> PatchChoices p wX wY -> m (PatchChoices p wX wY) refineChoices act ps = case getChoices ps of (f :> m :> l) -> do (PCs f' l') <- act m (mkPatchChoices m) return . PCs (f +>+ f') $ l' +>+ mapFL_FL (pcSetLast True) l -- | Given a 'LabelledPatch' determine to which section of the given -- 'PatchChoices' it belongs. This is not trivial to compute, since a patch -- tagged as 'InMiddle' may be forced to actually be 'InLast' by dependencies. We -- return a possibly re-ordered 'PatchChoices' so as not to waste the -- commutation effort. patchSlot :: forall p wA wB wX wY. Commute p => LabelledPatch p wA wB -> PatchChoices p wX wY -> (Slot, PatchChoices p wX wY) patchSlot (LP t _) pc@(PCs f ml) | foundIn f = (InFirst, pc) | otherwise = psLast f NilRL NilRL ml where foundIn = anyFL ((== t) . label) psLast :: forall wM wC wL . FL (LabelledPatch p) wX wM -> RL (LabelledPatch p) wM wC -> RL (LabelledPatch p) wC wL -> FL (PatchChoice p) wL wY -> (Slot, PatchChoices p wX wY) psLast firsts middles bubble (PC lp True :>: ls) | label lp == t = (InLast , PCs { pcsFirsts = firsts , pcsMiddleLasts = settleM middles +>+ settleB bubble +>+ PC lp True :>: ls}) psLast firsts middles bubble (PC lp False :>: ls) | label lp == t = case commuteRL (bubble :> lp) of Just (lp' :> bubble') -> (InMiddle, PCs { pcsFirsts = firsts , pcsMiddleLasts = settleM middles +>+ PC lp' False :>: settleB bubble' +>+ ls}) Nothing -> (InLast, PCs { pcsFirsts = firsts , pcsMiddleLasts = settleM middles +>+ settleB bubble +>+ PC lp True :>: ls}) psLast firsts middles bubble (PC lp True :>: ls) = psLast firsts middles (bubble :<: lp) ls psLast firsts middles bubble (PC lp False :>: ls) = case commuteRL (bubble :> lp) of Just (lp' :> bubble') -> psLast firsts (middles :<: lp') bubble' ls Nothing -> psLast firsts middles (bubble :<: lp) ls psLast _ _ _ NilFL = impossible settleM middles = mapFL_FL (\lp -> PC lp False) $ reverseRL middles settleB bubble = mapFL_FL (\lp -> PC lp True) $ reverseRL bubble -- | Force all patches matching the given predicate to be 'InFirst', -- pulling any dependencies with them. This even forces any patches -- that were already tagged 'InLast'. forceMatchingFirst :: forall p wA wB. Commute p => ( forall wX wY . LabelledPatch p wX wY -> Bool) -> PatchChoices p wA wB -> PatchChoices p wA wB forceMatchingFirst pred (PCs f0 ml) = fmfLasts f0 NilRL ml where fmfLasts :: FL (LabelledPatch p) wA wM -> RL (PatchChoice p) wM wN -> FL (PatchChoice p) wN wB -> PatchChoices p wA wB fmfLasts f l1 (a :>: l2) | pred_pc a = case commuteWhatWeCanRL (l1 :> a) of (deps :> a' :> l1') -> let f' = f +>+ mapFL_FL pcPatch (reverseRL deps) +>+ (pcPatch a' :>: NilFL) in fmfLasts f' l1' l2 fmfLasts f l1 (a :>: l2) = fmfLasts f (l1 :<: a) l2 fmfLasts f l1 NilFL = PCs { pcsFirsts = f , pcsMiddleLasts = reverseRL l1 } pred_pc :: forall wX wY . PatchChoice p wX wY -> Bool pred_pc (PC lp _) = pred lp -- | Force all patches labelled with one of the given labels to be 'InFirst', -- pulling any dependencies with them. This even forces any patches -- that were already tagged 'InLast'. forceFirsts :: Commute p => [Label] -> PatchChoices p wA wB -> PatchChoices p wA wB forceFirsts ps = forceMatchingFirst ((`elem` ps) . label) -- | Force a single patch labelled with the given label to be 'InFirst', -- pulling any dependencies with them. This even forces any patches -- that were already tagged 'InLast'. forceFirst :: Commute p => Label -> PatchChoices p wA wB -> PatchChoices p wA wB forceFirst p = forceMatchingFirst ((== p) . label) --TODO: stop after having seen the patch we want to force first -- | Make all 'InMiddle' patches either 'InFirst' or 'InLast'. This does *not* -- modify any patches that are already determined to be 'InLast' by -- dependencies. selectAllMiddles :: forall p wX wY. Commute p => Bool -> PatchChoices p wX wY -> PatchChoices p wX wY selectAllMiddles True (PCs f l) = PCs f (mapFL_FL g l) where g (PC lp _) = PC lp True selectAllMiddles False (PCs f l) = samf f NilRL NilRL l where samf :: forall wM1 wM2 wM3 . FL (LabelledPatch p) wX wM1 -> RL (LabelledPatch p) wM1 wM2 -> RL (PatchChoice p) wM2 wM3 -> FL (PatchChoice p) wM3 wY -> PatchChoices p wX wY samf f1 f2 l1 (pc@(PC lp False) :>: l2) = case commuteRL (l1 :> pc) of Nothing -> samf f1 f2 (l1 :<: PC lp True) l2 Just ((PC lp' _) :> l1') -> samf f1 (f2 :<: lp') l1' l2 samf f1 f2 l1 (PC lp True :>: l2) = samf f1 f2 (l1 :<: PC lp True) l2 samf f1 f2 l1 NilFL = PCs (f1 +>+ reverseRL f2) (reverseRL l1) -- | Similar to 'forceMatchingFirst' only that patches are forced to be -- 'InLast' regardless of their previous status. forceMatchingLast :: Commute p => (forall wX wY . LabelledPatch p wX wY -> Bool) -> PatchChoices p wA wB -> PatchChoices p wA wB forceMatchingLast pred (PCs f ml) = forceMatchingMiddleOrLast pred True NilRL f ml -- | Internal function working directly on the constituent parts of a -- 'PatchChoices' and taking an accumulating 'RL' to build up a new 'InFirst' -- section. It forces patches to be 'InMiddle' or 'InLast', depending -- on the 'Bool' parameter ('True' means 'InLast', 'False' means 'InMiddle'). -- It does this regardless of the previous status of patches and also pulls -- any dependent patches with it. forceMatchingMiddleOrLast :: forall p wA wB wM1 wM2 . Commute p => (forall wX wY . LabelledPatch p wX wY -> Bool) -> Bool -> RL (LabelledPatch p) wA wM1 -- ^ accumulator for 'InFirst' patches -> FL (LabelledPatch p) wM1 wM2 -- ^ original 'InFirst' section -> FL (PatchChoice p) wM2 wB -- ^ original 'InMiddle' and 'InLast' section -> PatchChoices p wA wB forceMatchingMiddleOrLast pred b f1 (a :>: f2) ml | pred a = case commuteWhatWeCanFL (a :> f2) of (f2' :> a' :> deps) -> let ml' = mapFL_FL (pcSetLast b) (a' :>: deps) +>+ ml in forceMatchingMiddleOrLast pred b f1 f2' ml' forceMatchingMiddleOrLast pred b f1 (a :>: f2) ml = forceMatchingMiddleOrLast pred b (f1 :<: a) f2 ml forceMatchingMiddleOrLast pred b f1 NilFL ml = PCs { pcsFirsts = reverseRL f1 , pcsMiddleLasts = mapFL_FL choose ml } where choose (PC lp c) = (PC lp (if pred lp then b else c) ) -- | Force all patches labelled with one of the given labels to be 'InLast', -- pulling any dependencies with them. This even forces any patches -- that were previously tagged 'InFirst'. forceLasts :: Commute p => [Label] -> PatchChoices p wA wB -> PatchChoices p wA wB forceLasts ps = forceMatchingLast ((`elem` ps) . label) -- | Force a single patch labelled with the given label to be 'InLast', -- pulling any dependencies with them, regardless of their previous status. forceLast :: Commute p => Label -> PatchChoices p wA wB -> PatchChoices p wA wB forceLast p = forceMatchingLast ((== p) . label) -- | Force a patch with the given 'Label' to be 'InMiddle', -- pulling any dependencies with it, regardless of their previous status. forceMiddle :: Commute p => Label -> PatchChoices p wA wB -> PatchChoices p wA wB forceMiddle t (PCs f l) = forceMatchingMiddleOrLast ((== t) . label) False NilRL f l -- | Turn 'InFirst' patches into 'InMiddle' ones and 'InMiddle' into 'InLast' ones. makeEverythingLater :: PatchChoices p wX wY -> PatchChoices p wX wY makeEverythingLater (PCs f ml) = let m = mapFL_FL (pcSetLast False) f ml' = mapFL_FL (\(PC lp _) -> PC lp True) ml in PCs NilFL $ m +>+ ml' -- | Turn 'InMiddle' patches into 'InFirst' and 'InLast' patches into 'InMiddle'. -- Does *not* pull dependencies into 'InFirst', instead patches that -- cannot be commuted past 'InLast' patches stay 'InMiddle'. makeEverythingSooner :: forall p wX wY. Commute p => PatchChoices p wX wY -> PatchChoices p wX wY makeEverythingSooner (PCs f ml) = case mes NilRL NilRL ml of (m :> ml') -> PCs (f +>+ m) ml' where mes :: forall wM1 wM2 wM3 . RL (LabelledPatch p) wM1 wM2 -> RL (LabelledPatch p) wM2 wM3 -> FL (PatchChoice p) wM3 wY -> (FL (LabelledPatch p) :> FL (PatchChoice p)) wM1 wY mes middle bubble (PC lp True :>: mls) = mes middle (bubble :<: lp) mls mes middle bubble (PC lp False :>: mls) = case commuteRL (bubble :> lp) of Nothing -> mes middle (bubble :<: lp) mls Just (lp' :> bubble') -> mes (middle :<: lp') bubble' mls mes middle bubble NilFL = (reverseRL middle) :> mapFL_FL (\lp -> PC lp False) (reverseRL bubble) -- | Substitute a single 'LabelledPatch' with an equivalent list of patches, -- preserving its status as 'InFirst', 'InMiddle' or 'InLast'). -- The patch is looked up using equality of 'Label's. substitute :: forall p wX wY . Sealed2 (LabelledPatch p :||: FL (LabelledPatch p)) -> PatchChoices p wX wY -> PatchChoices p wX wY substitute (Sealed2 (lp :||: new_lps)) (PCs f l) = PCs (concatFL $ mapFL_FL substLp f) (concatFL $ mapFL_FL substPc l) where substLp :: LabelledPatch p wA wB -> FL (LabelledPatch p) wA wB substLp lp' | IsEq <- compareLabels lp lp' = new_lps | otherwise = lp' :>: NilFL substPc :: PatchChoice p wA wB -> FL (PatchChoice p) wA wB substPc (PC lp' c) | IsEq <- compareLabels lp lp' = mapFL_FL (pcSetLast c) new_lps | otherwise = PC lp' c :>: NilFL darcs-2.14.5/src/Darcs/Patch/Commute.hs0000644000000000000000000000507307346545000015724 0ustar0000000000000000module Darcs.Patch.Commute ( Commute(..) , commuteFL , commuteFLorComplain , commuteRL , commuteRLFL , selfCommuter ) where import Prelude () import Darcs.Prelude import Darcs.Patch.CommuteFn ( CommuteFn ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), reverseFL, reverseRL, (:>)(..) ) import Darcs.Patch.Witnesses.Sealed ( Sealed2, seal2 ) -- | Commute represents things that can be (possibly) commuted. class Commute p where commute :: (p :> p) wX wY -> Maybe ((p :> p) wX wY) instance Commute p => Commute (FL p) where commute (NilFL :> x) = Just (x :> NilFL) commute (x :> NilFL) = Just (NilFL :> x) commute (xs :> ys) = do ys' :> rxs' <- commuteRLFL (reverseFL xs :> ys) return $ ys' :> reverseRL rxs' -- |'commuteRLFL' commutes an 'RL' past an 'FL'. commuteRLFL :: Commute p => (RL p :> FL p) wX wY -> Maybe ((FL p :> RL p) wX wY) commuteRLFL (NilRL :> ys) = Just (ys :> NilRL) commuteRLFL (xs :> NilFL) = Just (NilFL :> xs) commuteRLFL (xs :> y :>: ys) = do y' :> xs' <- commuteRL (xs :> y) ys' :> xs'' <- commuteRLFL (xs' :> ys) return (y' :>: ys' :> xs'') instance Commute p => Commute (RL p) where commute (xs :> ys) = do fys' :> xs' <- commuteRLFL (xs :> reverseRL ys) return (reverseFL fys' :> xs') -- |'commuteRL' commutes a RL past a single element. commuteRL :: Commute p => (RL p :> p) wX wY -> Maybe ((p :> RL p) wX wY) commuteRL (zs :<: z :> w) = do w' :> z' <- commute (z :> w) w'' :> zs' <- commuteRL (zs :> w') return (w'' :> zs' :<: z') commuteRL (NilRL :> w) = Just (w :> NilRL) -- |'commuteFL' commutes a single element past a FL. commuteFL :: Commute p => (p :> FL p) wX wY -> Maybe ((FL p :> p) wX wY) commuteFL = either (const Nothing) Just . commuteFLorComplain -- |'commuteFLorComplain' attempts to commute a single element past a FL. If -- any individual commute fails, then we return the patch that first patch that -- cannot be commuted past. commuteFLorComplain :: Commute p => (p :> FL p) wX wY -> Either (Sealed2 p) ((FL p :> p) wX wY) commuteFLorComplain (p :> NilFL) = Right (NilFL :> p) commuteFLorComplain (q :> p :>: ps) = case commute (q :> p) of Just (p' :> q') -> case commuteFLorComplain (q' :> ps) of Right (ps' :> q'') -> Right (p' :>: ps' :> q'') Left l -> Left l Nothing -> Left $ seal2 p -- |Build a commuter between a patch and itself using the operation from the type class. selfCommuter :: Commute p => CommuteFn p p selfCommuter = commute darcs-2.14.5/src/Darcs/Patch/CommuteFn.hs0000644000000000000000000000647107346545000016213 0ustar0000000000000000module Darcs.Patch.CommuteFn ( CommuteFn, commuterIdFL, commuterFLId, commuterIdRL, commuterRLId, MergeFn, mergerIdFL, TotalCommuteFn, totalCommuterIdFL, totalCommuterFLId, totalCommuterFLFL ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Witnesses.Ordered ( (:>)(..) , (:\/:)(..) , (:/\:)(..) , FL(..) , RL(..) ) -- |CommuteFn is the basis of a general framework for building up commutation -- operations between different patch types in a generic manner. Unfortunately -- type classes are not well suited to the problem because of the multiple possible -- routes by which the commuter for (FL p1, FL p2) can be built out of the -- commuter for (p1, p2) - and more complicated problems when we start building -- multiple constructors on top of each other. The type class resolution machinery -- really can't cope with selecting some route, because it doesn't know that all -- possible routes should be equivalent. type CommuteFn p1 p2 = forall wX wY . (p1 :> p2) wX wY -> Maybe ((p2 :> p1) wX wY) type TotalCommuteFn p1 p2 = forall wX wY . (p1 :> p2) wX wY -> (p2 :> p1) wX wY type MergeFn p1 p2 = forall wX wY . (p1 :\/: p2) wX wY -> (p2 :/\: p1) wX wY commuterIdRL :: CommuteFn p1 p2 -> CommuteFn p1 (RL p2) commuterIdRL _ (x :> NilRL) = return (NilRL :> x) commuterIdRL commuter (x :> (ys :<: y)) = do ys' :> x' <- commuterIdRL commuter (x :> ys) y' :> x'' <- commuter (x' :> y) return ((ys' :<: y') :> x'') commuterIdFL :: CommuteFn p1 p2 -> CommuteFn p1 (FL p2) commuterIdFL _ (x :> NilFL) = return (NilFL :> x) commuterIdFL commuter (x :> (y :>: ys)) = do y' :> x' <- commuter (x :> y) ys' :> x'' <- commuterIdFL commuter (x' :> ys) return ((y' :>: ys') :> x'') mergerIdFL :: MergeFn p1 p2 -> MergeFn p1 (FL p2) mergerIdFL _ (x :\/: NilFL) = NilFL :/\: x mergerIdFL merger (x :\/: (y :>: ys)) = case merger (x :\/: y) of y' :/\: x' -> case mergerIdFL merger (x' :\/: ys) of ys' :/\: x'' -> (y' :>: ys') :/\: x'' totalCommuterIdFL :: TotalCommuteFn p1 p2 -> TotalCommuteFn p1 (FL p2) totalCommuterIdFL _ (x :> NilFL) = NilFL :> x totalCommuterIdFL commuter (x :> (y :>: ys)) = case commuter (x :> y) of y' :> x' -> case totalCommuterIdFL commuter (x' :> ys) of ys' :> x'' -> (y' :>: ys') :> x'' commuterFLId :: CommuteFn p1 p2 -> CommuteFn (FL p1) p2 commuterFLId _ (NilFL :> y) = return (y :> NilFL) commuterFLId commuter ((x :>: xs) :> y) = do y' :> xs' <- commuterFLId commuter (xs :> y) y'' :> x' <- commuter (x :> y') return (y'' :> (x' :>: xs')) commuterRLId :: CommuteFn p1 p2 -> CommuteFn (RL p1) p2 commuterRLId _ (NilRL :> y) = return (y :> NilRL) commuterRLId commuter ((xs :<: x) :> y) = do y' :> x' <- commuter (x :> y) y'' :> xs' <- commuterRLId commuter (xs :> y') return (y'' :> (xs' :<: x')) totalCommuterFLId :: TotalCommuteFn p1 p2 -> TotalCommuteFn (FL p1) p2 totalCommuterFLId _ (NilFL :> y) = y :> NilFL totalCommuterFLId commuter ((x :>: xs) :> y) = case totalCommuterFLId commuter (xs :> y) of y' :> xs' -> case commuter (x :> y') of y'' :> x' -> y'' :> (x' :>: xs') totalCommuterFLFL :: TotalCommuteFn p1 p2 -> TotalCommuteFn (FL p1) (FL p2) totalCommuterFLFL commuter = totalCommuterFLId (totalCommuterIdFL commuter) darcs-2.14.5/src/Darcs/Patch/Conflict.hs0000644000000000000000000002212607346545000016052 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy, 2010 Ganesh Sittampalam {-# LANGUAGE ViewPatterns #-} module Darcs.Patch.Conflict ( Conflict(..), CommuteNoConflicts(..), listConflictedFiles , IsConflictedPrim(..), ConflictState(..) , mangleUnravelled ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString.Char8 as BC (pack, last) import qualified Data.ByteString as B (null, ByteString) import Data.Maybe ( isJust ) import Data.List ( sort, intercalate ) import Data.List.Ordered ( nubSort ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.FileHunk ( FileHunk(..), IsHunk, isHunk ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Permutations () import Darcs.Patch.Prim ( PrimPatch, is_filepatch, primIsHunk, primFromHunk ) import Darcs.Patch.Prim.Class ( PrimOf ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), (:>)(..) , mapFL, reverseFL, mapRL, reverseRL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), unseal, mapSeal ) import Darcs.Patch.Witnesses.Show ( Show2, showsPrec2 ) import Darcs.Util.Path ( FileName, fn2fp, fp2fn ) import Darcs.Util.Show ( appPrec ) listConflictedFiles :: Conflict p => p wX wY -> [FilePath] listConflictedFiles p = nubSort $ concatMap (unseal listTouchedFiles) $ concat $ resolveConflicts p class (Effect p, PatchInspect (PrimOf p)) => Conflict p where resolveConflicts :: p wX wY -> [[Sealed (FL (PrimOf p) wY)]] conflictedEffect :: p wX wY -> [IsConflictedPrim (PrimOf p)] class CommuteNoConflicts p where -- | If 'commuteNoConflicts' @x :> y@ succeeds, we know that that @x@ commutes -- past @y@ without any conflicts. This function is useful for patch types -- for which 'commute' is defined to always succeed; so we need some way to -- pick out the specific cases where commutation succeeds without any conflicts. commuteNoConflicts :: (p :> p) wX wY -> Maybe ((p :> p) wX wY) instance (CommuteNoConflicts p, Conflict p) => Conflict (FL p) where resolveConflicts NilFL = [] resolveConflicts x = resolveConflicts $ reverseFL x conflictedEffect = concat . mapFL conflictedEffect instance CommuteNoConflicts p => CommuteNoConflicts (FL p) where commuteNoConflicts (NilFL :> x) = Just (x :> NilFL) commuteNoConflicts (x :> NilFL) = Just (NilFL :> x) commuteNoConflicts (xs :> ys) = do ys' :> rxs' <- commuteNoConflictsRLFL (reverseFL xs :> ys) return $ ys' :> reverseRL rxs' instance (CommuteNoConflicts p, Conflict p) => Conflict (RL p) where -- By definition, a conflicting (primitive) patch is resolved if -- another (primitive) patch depends on the conflict. -- -- So, when looking for conflicts in a list of patches, we go -- through the whole list looking for individual patches that are -- in conflict. But then we try to commute them past all the -- patches we've already seen. If we fail, i.e. there's something -- that depends on the conflict, then we forget about the conflict; -- this is the Nothing case of the 'commuteNoConflictsFL' call. -- -- Note that 'primitive' does not mean Prim (this is a case of bad -- naming) but rather a RepoPatchV1 or RepoPatchV2. Prim patches -- are merely a 'base class' containing everything common to V1 and -- V2 primitive patches. resolveConflicts x = rcs x NilFL where rcs :: RL p wX wY -> FL p wY wW -> [[Sealed (FL (PrimOf p) wW)]] rcs NilRL _ = [] rcs (ps :<: p) passedby | null (resolveConflicts p) = seq passedby rest -- TODO why seq here? | otherwise = case commuteNoConflictsFL (p :> passedby) of Just (_ :> p') -> resolveConflicts p' ++ rest Nothing -> rest where rest = rcs ps (p :>: passedby) conflictedEffect = concat . reverse . mapRL conflictedEffect instance CommuteNoConflicts p => CommuteNoConflicts (RL p) where commuteNoConflicts (NilRL :> x) = Just (x :> NilRL) commuteNoConflicts (x :> NilRL) = Just (NilRL :> x) commuteNoConflicts (xs :> ys) = do ys' :> rxs' <- commuteNoConflictsRLFL (xs :> reverseRL ys) return $ reverseFL ys' :> rxs' data IsConflictedPrim prim where IsC :: !ConflictState -> !(prim wX wY) -> IsConflictedPrim prim data ConflictState = Okay | Conflicted | Duplicated deriving ( Eq, Ord, Show, Read) instance Show2 prim => Show (IsConflictedPrim prim) where showsPrec d (IsC cs prim) = showParen (d > appPrec) $ showString "IsC " . showsPrec (appPrec + 1) cs . showString " " . showsPrec2 (appPrec + 1) prim commuteNoConflictsFL :: CommuteNoConflicts p => (p :> FL p) wX wY -> Maybe ((FL p :> p) wX wY) commuteNoConflictsFL (p :> NilFL) = Just (NilFL :> p) commuteNoConflictsFL (q :> p :>: ps) = do p' :> q' <- commuteNoConflicts (q :> p) ps' :> q'' <- commuteNoConflictsFL (q' :> ps) return (p' :>: ps' :> q'') commuteNoConflictsRL :: CommuteNoConflicts p => (RL p :> p) wX wY -> Maybe ((p :> RL p) wX wY) commuteNoConflictsRL (NilRL :> p) = Just (p :> NilRL) commuteNoConflictsRL (ps :<: p :> q) = do q' :> p' <- commuteNoConflicts (p :> q) q'' :> ps' <- commuteNoConflictsRL (ps :> q') return (q'' :> ps' :<: p') commuteNoConflictsRLFL :: CommuteNoConflicts p => (RL p :> FL p) wX wY -> Maybe ((FL p :> RL p) wX wY) commuteNoConflictsRLFL (NilRL :> ys) = Just (ys :> NilRL) commuteNoConflictsRLFL (xs :> NilFL) = Just (NilFL :> xs) commuteNoConflictsRLFL (xs :> y :>: ys) = do y' :> xs' <- commuteNoConflictsRL (xs :> y) ys' :> xs'' <- commuteNoConflictsRLFL (xs' :> ys) return (y' :>: ys' :> xs'') applyHunks :: IsHunk prim => [Maybe B.ByteString] -> FL prim wX wY -> [Maybe B.ByteString] applyHunks ms ((isHunk -> Just (FileHunk _ l o n)):>:ps) = applyHunks (rls l ms) ps where rls k _ | k <=0 = bug $ "bad hunk: start position <=0 (" ++ show k ++ ")" rls 1 mls = map Just n ++ drop (length o) mls rls i (ml:mls) = ml : rls (i-1) mls rls _ [] = bug "rls in applyHunks" applyHunks ms NilFL = ms applyHunks _ (_:>:_) = impossible getAFilename :: PrimPatch prim => [Sealed (FL prim wX)] -> FileName getAFilename (Sealed ((is_filepatch -> Just f):>:_):_) = f getAFilename _ = fp2fn "" getOld :: PrimPatch prim => [Maybe B.ByteString] -> [Sealed (FL prim wX)] -> [Maybe B.ByteString] getOld = foldl getHunksOld getHunksOld :: PrimPatch prim => [Maybe B.ByteString] -> Sealed (FL prim wX) -> [Maybe B.ByteString] getHunksOld mls (Sealed ps) = applyHunks (applyHunks mls ps) (invert ps) getHunksNew :: IsHunk prim => [Maybe B.ByteString] -> Sealed (FL prim wX) -> [Maybe B.ByteString] getHunksNew mls (Sealed ps) = applyHunks mls ps getHunkline :: [[Maybe B.ByteString]] -> Int getHunkline = ghl 1 where ghl :: Int -> [[Maybe B.ByteString]] -> Int ghl n pps = if any (isJust . head) pps then n else ghl (n+1) $ map tail pps makeChunk :: Int -> [Maybe B.ByteString] -> [B.ByteString] makeChunk n mls = pull_chunk $ drop (n-1) mls where pull_chunk (Just l:mls') = l : pull_chunk mls' pull_chunk (Nothing:_) = [] pull_chunk [] = bug "should this be [] in pull_chunk?" mangleUnravelled :: PrimPatch prim => [Sealed (FL prim wX)] -> Sealed (FL prim wX) mangleUnravelled pss = if onlyHunks pss then (:>: NilFL) `mapSeal` mangleUnravelledHunks pss else head pss onlyHunks :: forall prim wX . PrimPatch prim => [Sealed (FL prim wX)] -> Bool onlyHunks [] = False onlyHunks pss = fn2fp f /= "" && all oh pss where f = getAFilename pss oh :: Sealed (FL prim wY) -> Bool oh (Sealed (p:>:ps)) = primIsHunk p && [fn2fp f] == listTouchedFiles p && oh (Sealed ps) oh (Sealed NilFL) = True mangleUnravelledHunks :: PrimPatch prim => [Sealed (FL prim wX)] -> Sealed (prim wX) --mangleUnravelledHunks [[h1],[h2]] = Deal with simple cases handily? mangleUnravelledHunks pss = if null nchs then bug "mangleUnravelledHunks" else Sealed (primFromHunk (FileHunk filename l old new)) where oldf = getOld (repeat Nothing) pss newfs = map (getHunksNew oldf) pss l = getHunkline $ oldf : newfs nchs = sort $ map (makeChunk l) newfs filename = getAFilename pss old = makeChunk l oldf new = [top] ++ old ++ [initial] ++ intercalate [middle] nchs ++ [bottom] top = BC.pack $ "v v v v v v v" ++ eol_c initial= BC.pack $ "=============" ++ eol_c middle = BC.pack $ "*************" ++ eol_c bottom = BC.pack $ "^ ^ ^ ^ ^ ^ ^" ++ eol_c eol_c = if any (\ps -> not (B.null ps) && BC.last ps == '\r') old then "\r" else "" darcs-2.14.5/src/Darcs/Patch/Debug.hs0000644000000000000000000000156407346545000015342 0ustar0000000000000000module Darcs.Patch.Debug ( PatchDebug(..) )where import Darcs.Patch.Witnesses.Ordered ( FL, RL ) -- | PatchDebug is a hook class for temporarily adding debug information. -- To use it, add any methods that are required, implement those methods -- where needed, and then make it available in the relevant contexts. -- For example it can be temporarily added as a superclass of `Patchy`. -- The advantage of having it here already is that everything is -- (or should be) declared as an instance of it, so you can use -- defaulting or just leave out declarations of instance methods and -- code will still compile. class PatchDebug p where -- | A dummy method so we can export/import PatchDebug(..) without -- triggering warnings patchDebugDummy :: p wX wY -> () patchDebugDummy _ = () instance PatchDebug p => PatchDebug (FL p) instance PatchDebug p => PatchDebug (RL p) darcs-2.14.5/src/Darcs/Patch/Depends.hs0000644000000000000000000006073607346545000015704 0ustar0000000000000000-- Copyright (C) 2003-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE ScopedTypeVariables #-} module Darcs.Patch.Depends ( getUncovered , areUnrelatedRepos , findCommonAndUncommon , mergeThem , findCommonWithThem , countUsThem , removeFromPatchSet , slightlyOptimizePatchset , getPatchesBeyondTag , splitOnTag , patchSetUnion , patchSetIntersection , findUncommon , merge2FL , getDeps , SPatchAndDeps ) where import Prelude () import Darcs.Prelude import Prelude hiding ( pi ) import Data.List ( delete, intersect, (\\) ) import Data.Maybe ( fromMaybe ) import Control.Arrow ( (&&&) ) import Darcs.Patch ( RepoPatch ) import Darcs.Patch.Named ( Named (..), patch2patchinfo ) import Darcs.Patch.Named.Wrapped ( getdeps ) import Darcs.Patch.Choices ( Label, patchChoices, forceFirst , PatchChoices, unLabel, getChoices , LabelledPatch, label ) import Darcs.Patch.Commute ( Commute, commute, commuteFL, commuteRL ) import Darcs.Patch.Info ( PatchInfo, isTag, displayPatchInfo, piName ) import Darcs.Patch.Merge ( Merge, mergeFL ) import Darcs.Patch.Permutations ( partitionFL, partitionRL ) import Darcs.Patch.PatchInfoAnd( PatchInfoAnd, hopefully, hopefullyM, info ) import Darcs.Patch.Set ( PatchSet(..), Tagged(..), SealedPatchSet, patchSet2RL, appendPSFL ) import Darcs.Patch.Progress ( progressRL ) import Darcs.Patch.Witnesses.Eq ( EqCheck(..), (=\/=), (=/\=) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP, unsafeCoercePStart ) import Darcs.Patch.Witnesses.Ordered ( (:\/:)(..), (:/\:)(..), (:>)(..), Fork(..), (+>>+), (+<<+), mapFL, RL(..), FL(..), isShorterThanRL, (+<+), reverseFL, reverseRL, mapRL, lengthFL, splitAtFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), FlippedSeal(..), flipSeal, seal, Sealed2(..), seal2 ) import Darcs.Util.Printer ( renderString, vcat ) {- - This module uses the following definitions: - - Explicit dependencies: the set of patches that a patch depends on "by name", - i.e. irrespective of (non-)commutation (non commuting patches are implicit - dependencies, or conflicts). In other words, the set of patch names in a tag - or patch recorded with --ask-deps. - - Covered: a patch p covers another, q, if p's explicit dependencies include - q. E.g. in a repo [a,b,t] where t is a tag and a,b have no explicit - dependencies, then t will cover a and b. - - "Clean" tag: a tag in a repository is clean if all patches prior to the tag - are (transitively-)covered by the tag. An obvious example of obtaining an - unclean tag is by pulling from one repo into another - the tag could have - been commuted past other patches. When patches are created, they are clean, - since they explicitly depend on all uncovered patches. -} -- | S(ealed) Patch and his dependencies. type SPatchAndDeps p = ( Sealed2 (LabelledPatch (Named p)) , Sealed2 (FL (LabelledPatch (Named p))) ) -- | Searchs dependencies in @repoFL@ of the patches in @getDepsFL@. getDeps :: (RepoPatch p) => FL (Named p) wA wR -> FL (PatchInfoAnd rt p) wX wY -> [SPatchAndDeps p] getDeps repoFL getDepsFL = let repoChoices = patchChoices repoFL getDepsFL' = mapFL (piName . info) getDepsFL labelledDeps = getLabelledDeps getDepsFL' repoChoices in map (deps repoChoices) labelledDeps where -- Search dependencies for the patch with label @l@ in @repoChoices@. deps :: (Commute p) => PatchChoices (Named p) wX wY -> (String,Label) -> SPatchAndDeps p deps repoChoices (_,l) = case getChoices $ forceFirst l repoChoices of (ds :> _) -> let i = lengthFL ds in case splitAtFL (i-1) ds of -- Separate last patch in list ds' :> (r :>: NilFL) -> (seal2 r, seal2 ds') _ -> impossible -- Because deps at least -- has r, which is the patch -- that we are looking at -- dependencies. getLabelledDeps :: (Commute p) => [String] -> PatchChoices (Named p) x y -> [(String, Label)] getLabelledDeps patchnames repoChoices = case getChoices repoChoices of a :> (b :> c) -> filterDepsFL patchnames a ++ filterDepsFL patchnames b ++ filterDepsFL patchnames c filterDepsFL :: [String] -> FL (LabelledPatch (Named p)) wX wY -> [(String, Label)] filterDepsFL _ NilFL = [] filterDepsFL patchnames (lp :>: lps) = if fst dep `elem` patchnames then dep : filterDepsFL patchnames lps else filterDepsFL patchnames lps where lpTostring :: LabelledPatch (Named p) wA wB -> String lpTostring = piName . patch2patchinfo . unLabel dep :: (String, Label) dep = lpTostring &&& label $ lp {-| taggedIntersection takes two 'PatchSet's and splits them into a /common/ intersection portion and two sets of patches. The intersection, however, is only lazily determined, so there is no guarantee that all intersecting patches will be included in the intersection 'PatchSet'. This is a pretty efficient function, because it makes use of the already-broken-up nature of 'PatchSet's. Note that the first argument to taggedIntersection should be the repository that is more cheaply accessed (i.e. local), as taggedIntersection does its best to reduce the number of inventories that are accessed from its rightmost argument. -} taggedIntersection :: forall rt p wStart wX wY . Commute p => PatchSet rt p wStart wX -> PatchSet rt p wStart wY -> Fork (RL (Tagged rt p)) (RL (PatchInfoAnd rt p)) (RL (PatchInfoAnd rt p)) wStart wX wY taggedIntersection (PatchSet NilRL ps1) s2 = Fork NilRL ps1 (patchSet2RL s2) taggedIntersection s1 (PatchSet NilRL ps2) = Fork NilRL (patchSet2RL s1) ps2 taggedIntersection s1 (PatchSet (_ :<: Tagged t _ _) ps2) | Just (PatchSet ts1 ps1) <- maybeSplitSetOnTag (info t) s1 = Fork ts1 ps1 (unsafeCoercePStart ps2) taggedIntersection s1 s2@(PatchSet (ts2 :<: Tagged t _ p) ps2) = case hopefullyM t of Just _ -> taggedIntersection s1 (PatchSet ts2 (p :<: t +<+ ps2)) Nothing -> case splitOnTag (info t) s1 of Just (PatchSet com NilRL :> us) -> Fork com us (unsafeCoercePStart ps2) Just _ -> impossible Nothing -> Fork NilRL (patchSet2RL s1) (patchSet2RL s2) -- |'maybeSplitSetOnTag' takes a tag's 'PatchInfo', @t0@, and a 'PatchSet' and -- attempts to find @t0@ in one of the 'Tagged's in the PatchSet. If the tag is -- found, the PatchSet is split up, on that tag, such that all later patches -- are in the "since last tag" patch list. If the tag is not found, 'Nothing' -- is returned. maybeSplitSetOnTag :: PatchInfo -> PatchSet rt p wStart wX -> Maybe (PatchSet rt p wStart wX) maybeSplitSetOnTag t0 origSet@(PatchSet (ts :<: Tagged t _ pst) ps) | t0 == info t = Just origSet | otherwise = do PatchSet ts' ps' <- maybeSplitSetOnTag t0 (PatchSet ts (pst :<: t)) Just $ PatchSet ts' (ps' +<+ ps) maybeSplitSetOnTag _ _ = Nothing getPatchesBeyondTag :: Commute p => PatchInfo -> PatchSet rt p wStart wX -> FlippedSeal (RL (PatchInfoAnd rt p)) wX getPatchesBeyondTag t (PatchSet (_ :<: Tagged hp _ _) ps) | info hp == t = flipSeal ps getPatchesBeyondTag t patchset@(PatchSet ts (ps :<: hp)) = if info hp == t then if getUncovered patchset == [info hp] -- special case to avoid looking at redundant patches then flipSeal NilRL else case splitOnTag t patchset of Just (_ :> e) -> flipSeal e _ -> impossible else case getPatchesBeyondTag t (PatchSet ts ps) of FlippedSeal xxs -> FlippedSeal (xxs :<: hp) getPatchesBeyondTag t (PatchSet NilRL NilRL) = bug $ "tag\n" ++ renderString (displayPatchInfo t) ++ "\nis not in the patchset in getPatchesBeyondTag." getPatchesBeyondTag t0 (PatchSet (ts :<: Tagged t _ ps) NilRL) = getPatchesBeyondTag t0 (PatchSet ts (ps :<: t)) -- |splitOnTag takes a tag's 'PatchInfo', and a 'PatchSet', and attempts to -- find the tag in the PatchSet, returning a pair: the clean PatchSet "up to" -- the tag, and a RL of patches after the tag; If the tag is not in the -- PatchSet, we return Nothing. splitOnTag :: Commute p => PatchInfo -> PatchSet rt p wStart wX -> Maybe ((PatchSet rt p :> RL (PatchInfoAnd rt p)) wStart wX) -- If the tag we are looking for is the first Tagged tag of the patchset, just -- separate out the patchset's patches. splitOnTag t (PatchSet ts@(_ :<: Tagged hp _ _) ps) | info hp == t = Just $ PatchSet ts NilRL :> ps -- If the tag is the most recent patch in the set, we check if the patch is the -- only non-depended-on patch in the set (i.e. it is a clean tag); creating a -- new Tagged out of the patches and tag, and adding it to the patchset, if -- this is the case. Otherwise, we try to make the tag clean. splitOnTag t patchset@(PatchSet ts hps@(ps :<: hp)) | info hp == t = if getUncovered patchset == [t] then Just $ PatchSet (ts :<: Tagged hp Nothing ps) NilRL :> NilRL else case partitionRL ((`notElem` (t : ds)) . info) hps of -- Partition hps by those that are the tag and its explicit deps. tagAndDeps@(ds' :<: hp') :> nonDeps -> -- If @ds@ doesn't contain the tag of the first Tagged, that -- tag will also be returned by the call to getUncovered - so -- we need to unwrap the next Tagged in order to expose it to -- being partitioned out in the recursive call to splitOnTag. if getUncovered (PatchSet ts tagAndDeps) == [t] then let tagged = Tagged hp' Nothing ds' in return $ PatchSet (ts :<: tagged) NilRL :> nonDeps else do unfolded <- unwrapOneTagged $ PatchSet ts tagAndDeps xx :> yy <- splitOnTag t unfolded return $ xx :> (yy +<+ nonDeps) _ -> impossible where ds = getdeps (hopefully hp) -- We drop the leading patch, to try and find a non-Tagged tag. splitOnTag t (PatchSet ts (ps :<: p)) = do ns :> x <- splitOnTag t (PatchSet ts ps) return $ ns :> (x :<: p) -- If there are no patches left, we "unfold" the next Tagged, and try again. splitOnTag t0 patchset@(PatchSet (_ :<: Tagged _ _ _s) NilRL) = unwrapOneTagged patchset >>= splitOnTag t0 -- If we've checked all the patches, but haven't found the tag, return Nothing. splitOnTag _ (PatchSet NilRL NilRL) = Nothing -- |'unwrapOneTagged' unfolds a single Tagged object in a PatchSet, adding the -- tag and patches to the PatchSet's patch list. unwrapOneTagged :: PatchSet rt p wX wY -> Maybe (PatchSet rt p wX wY) unwrapOneTagged (PatchSet (ts :<: Tagged t _ tps) ps) = Just $ PatchSet ts (tps :<: t +<+ ps) unwrapOneTagged _ = Nothing -- | @getUncovered ps@ returns the 'PatchInfo' for all the patches in -- @ps@ that are not depended on by anything else *through explicit -- dependencies*. Tags are a likely candidate, although we may also -- find some non-tag patches in this list. -- -- Keep in mind that in a typical repository with a lot of tags, only a small -- fraction of tags would be returned as they would be at least indirectly -- depended on by the topmost ones. getUncovered :: PatchSet rt p wStart wX -> [PatchInfo] getUncovered patchset = case patchset of (PatchSet NilRL ps) -> findUncovered (mapRL infoAndExplicitDeps ps) (PatchSet (_ :<: Tagged t _ _) ps) -> findUncovered (mapRL infoAndExplicitDeps (NilRL :<: t +<+ ps)) where findUncovered :: [(PatchInfo, Maybe [PatchInfo])] -> [PatchInfo] findUncovered [] = [] findUncovered ((pi, Nothing) : rest) = pi : findUncovered rest findUncovered ((pi, Just deps) : rest) = pi : findUncovered (dropDepsIn deps rest) -- |dropDepsIn traverses the list of patches, dropping any patches that -- occur in the dependency list; when a patch is dropped, its dependencies -- are added to the dependency list used for later patches. dropDepsIn :: [PatchInfo] -> [(PatchInfo, Maybe [PatchInfo])] -> [(PatchInfo, Maybe [PatchInfo])] dropDepsIn [] pps = pps dropDepsIn _ [] = [] dropDepsIn ds (hp : pps) | fst hp `elem` ds = let extraDeps = fromMaybe [] $ snd hp in dropDepsIn (extraDeps ++ delete (fst hp) ds) pps | otherwise = hp : dropDepsIn ds pps -- |infoAndExplicitDeps returns the patch info and (for tags only) the list -- of explicit dependencies of a patch. infoAndExplicitDeps :: PatchInfoAnd rt p wX wY -> (PatchInfo, Maybe [PatchInfo]) infoAndExplicitDeps p | isTag (info p) = (info p, getdeps `fmap` hopefullyM p) | otherwise = (info p, Nothing) -- | @slightlyOptimizePatchset@ only works on the surface inventory -- (see 'optimizePatchset') and only optimises at most one tag in -- there, going for the most recent tag which has no non-depended -- patch after it. Older tags won't be 'clean', which means the -- PatchSet will not be in 'clean :> unclean' state. slightlyOptimizePatchset :: PatchSet rt p wStart wX -> PatchSet rt p wStart wX slightlyOptimizePatchset (PatchSet ps0 ts0) = sops $ PatchSet (prog ps0) ts0 where prog = progressRL "Optimizing inventory" sops :: PatchSet rt p wStart wY -> PatchSet rt p wStart wY sops patchset@(PatchSet _ NilRL) = patchset sops patchset@(PatchSet ts (ps :<: hp)) | isTag (info hp) = if getUncovered patchset == [info hp] -- exactly one tag and it depends on everything not already -- archived then PatchSet (ts :<: Tagged hp Nothing ps) NilRL -- other tags or other top-level patches too (so move past hp) else let ps' = sops $ PatchSet ts (prog ps) in appendPSFL ps' (hp :>: NilFL) | otherwise = appendPSFL (sops $ PatchSet ts ps) (hp :>: NilFL) removeFromPatchSet :: Commute p => FL (PatchInfoAnd rt p) wX wY -> PatchSet rt p wStart wY -> Maybe (PatchSet rt p wStart wX) removeFromPatchSet bad (PatchSet ts ps) | all (`elem` mapRL info ps) (mapFL info bad) = do ps' <- fastRemoveSubsequenceRL (reverseFL bad) ps return (PatchSet ts ps') removeFromPatchSet _ (PatchSet NilRL _) = Nothing removeFromPatchSet bad (PatchSet (ts :<: Tagged t _ tps) ps) = removeFromPatchSet bad (PatchSet ts (tps :<: t +<+ ps)) fastRemoveSubsequenceRL :: Commute p => RL (PatchInfoAnd rt p) wY wZ -> RL (PatchInfoAnd rt p) wX wZ -> Maybe (RL (PatchInfoAnd rt p) wX wY) fastRemoveSubsequenceRL NilRL ys = Just ys fastRemoveSubsequenceRL (xs:<:x) ys = fastRemoveRL x ys >>= fastRemoveSubsequenceRL xs findCommonAndUncommon :: forall rt p wStart wX wY . Commute p => PatchSet rt p wStart wX -> PatchSet rt p wStart wY -> Fork (PatchSet rt p) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wStart wX wY findCommonAndUncommon us them = case taggedIntersection us them of Fork common us' them' -> case partitionFL (infoIn them') $ reverseRL us' of _ :> bad@(_ :>: _) :> _ -> bug $ "Failed to commute common patches:\n" ++ renderString (vcat $ mapRL (displayPatchInfo . info) $ reverseFL bad) (common2 :> NilFL :> only_ours) -> case partitionFL (infoIn us') $ reverseRL them' of _ :> bad@(_ :>: _) :> _ -> bug $ "Failed to commute common patches:\n" ++ renderString (vcat $ mapRL (displayPatchInfo . info) $ reverseFL bad) _ :> NilFL :> only_theirs -> Fork (PatchSet common (reverseFL common2)) only_ours (unsafeCoercePStart only_theirs) where infoIn inWhat = (`elem` mapRL info inWhat) . info findCommonWithThem :: Commute p => PatchSet rt p wStart wX -> PatchSet rt p wStart wY -> (PatchSet rt p :> FL (PatchInfoAnd rt p)) wStart wX findCommonWithThem us them = case taggedIntersection us them of Fork common us' them' -> case partitionFL ((`elem` mapRL info them') . info) $ reverseRL us' of _ :> bad@(_ :>: _) :> _ -> bug $ "Failed to commute common patches:\n" ++ renderString (vcat $ mapRL (displayPatchInfo . info) $ reverseFL bad) common2 :> _nilfl :> only_ours -> PatchSet common (reverseFL common2) :> unsafeCoerceP only_ours findUncommon :: Commute p => PatchSet rt p wStart wX -> PatchSet rt p wStart wY -> (FL (PatchInfoAnd rt p) :\/: FL (PatchInfoAnd rt p)) wX wY findUncommon us them = case findCommonWithThem us them of _common :> us' -> case findCommonWithThem them us of _ :> them' -> unsafeCoercePStart us' :\/: them' countUsThem :: Commute p => PatchSet rt p wStart wX -> PatchSet rt p wStart wY -> (Int, Int) countUsThem us them = case taggedIntersection us them of Fork _ us' them' -> let uu = mapRL info us' tt = mapRL info them' in (length $ uu \\ tt, length $ tt \\ uu) mergeThem :: (Merge p) => PatchSet rt p wStart wX -> PatchSet rt p wStart wY -> Sealed (FL (PatchInfoAnd rt p) wX) mergeThem us them = case taggedIntersection us them of Fork _ us' them' -> case merge2FL (reverseRL us') (reverseRL them') of them'' :/\: _ -> Sealed them'' patchSetIntersection :: Commute p => [SealedPatchSet rt p wStart] -> SealedPatchSet rt p wStart patchSetIntersection [] = seal $ PatchSet NilRL NilRL patchSetIntersection [x] = x patchSetIntersection (Sealed y : ys) = case patchSetIntersection ys of Sealed z -> case taggedIntersection y z of Fork common a b -> case mapRL info a `intersect` mapRL info b of morecommon -> case partitionRL (\e -> info e `notElem` morecommon) a of commonps :> _ -> seal $ PatchSet common commonps patchSetUnion :: (Merge p) => [SealedPatchSet rt p wStart] -> SealedPatchSet rt p wStart patchSetUnion [] = seal $ PatchSet NilRL NilRL patchSetUnion [x] = x patchSetUnion (Sealed y@(PatchSet tsy psy) : Sealed y2 : ys) = case mergeThem y y2 of Sealed p2 -> patchSetUnion $ seal (PatchSet tsy (psy +<+ reverseFL p2)) : ys -- | Merge two FLs (say L and R), starting in a common context. The result is a -- FL starting in the original end context of L, going to a new context that is -- the result of applying all patches from R on top of patches from L. -- -- While this function is similar to 'mergeFL', there are some important -- differences to keep in mind: -- -- * 'mergeFL' does not correctly deal with duplicate patches whereas this one -- does -- (Question from Eric Kow: in what sense? Why not fix 'mergeFL'?) -- (bf: I guess what was meant here is that 'merge2FL' works in the -- the way it does because it considers patch meta data whereas -- 'mergeFL' cannot since it must work for primitive patches, too. merge2FL :: (Merge p) => FL (PatchInfoAnd rt p) wX wY -> FL (PatchInfoAnd rt p) wX wZ -> (FL (PatchInfoAnd rt p) :/\: FL (PatchInfoAnd rt p)) wY wZ merge2FL xs NilFL = NilFL :/\: xs merge2FL NilFL ys = ys :/\: NilFL merge2FL xs (y :>: ys) | Just xs' <- fastRemoveFL y xs = merge2FL xs' ys merge2FL (x :>: xs) ys | Just ys' <- fastRemoveFL x ys = merge2FL xs ys' | otherwise = case mergeFL (x :\/: ys) of ys' :/\: x' -> case merge2FL xs ys' of ys'' :/\: xs' -> ys'' :/\: (x' :>: xs') areUnrelatedRepos :: Commute p => PatchSet rt p wStart wX -> PatchSet rt p wStart wY -> Bool areUnrelatedRepos us them = case taggedIntersection us them of Fork c u t -> checkit c u t where checkit (_ :<: Tagged{}) _ _ = False checkit _ u t | t `isShorterThanRL` 5 = False | u `isShorterThanRL` 5 = False | otherwise = null $ intersect (mapRL info u) (mapRL info t) -- | Remove a patch from FL, using PatchInfo equality. The result is Just -- whenever the patch has been found and removed. If the patch is not present -- in the sequence at all or any commutation fails, we get Nothing. First two -- cases are optimisations for the common cases where the head of the list is -- the patch to remove, or the patch is not there at all. -- -- A note on the witness types: the patch to be removed is typed as if it had -- to be the first in the list, since it has the same pre-context as the list. -- The types fit together (internally, in this module) because we commute the -- patch to the front before removing it and commutation inside a sequence does -- not change the sequence's contexts. fastRemoveFL :: Commute p => PatchInfoAnd rt p wX wY -- this type assumes element is at the front -> FL (PatchInfoAnd rt p) wX wZ -> Maybe (FL (PatchInfoAnd rt p) wY wZ) fastRemoveFL _ NilFL = Nothing fastRemoveFL a (b :>: bs) | IsEq <- a =\/= b = Just bs | info a `notElem` mapFL info bs = Nothing fastRemoveFL a (b :>: bs) = do a' :> bs' <- pullout NilRL bs a'' :> b' <- commute (b :> a') IsEq <- return (a'' =\/= a) Just (b' :>: bs') where i = info a pullout :: Commute p => RL (PatchInfoAnd rt p) wA wB -> FL (PatchInfoAnd rt p) wB wC -> Maybe ((PatchInfoAnd rt p :> FL (PatchInfoAnd rt p)) wA wC) pullout _ NilFL = Nothing pullout acc (x :>: xs) | info x == i = do x' :> acc' <- commuteRL (acc :> x) Just (x' :> acc' +>>+ xs) | otherwise = pullout (acc :<: x) xs -- | Same as 'fastRemoveFL' only for 'RL'. fastRemoveRL :: Commute p => PatchInfoAnd rt p wY wZ -- this type assumes element is at the back -> RL (PatchInfoAnd rt p) wX wZ -> Maybe (RL (PatchInfoAnd rt p) wX wY) fastRemoveRL _ NilRL = Nothing fastRemoveRL a (bs :<: b) | IsEq <- b =/\= a = Just bs | info a `notElem` mapRL info bs = Nothing fastRemoveRL a (bs :<: b) = do bs' :> a' <- pullout bs NilFL b' :> a'' <- commute (a' :> b) IsEq <- return (a'' =/\= a) Just (bs' :<: b') where i = info a pullout :: Commute p => RL (PatchInfoAnd rt p) wA wB -> FL (PatchInfoAnd rt p) wB wC -> Maybe ((RL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wA wC) pullout NilRL _ = Nothing pullout (xs :<: x) acc | info x == i = do acc' :> x' <- commuteFL (x :> acc) Just (xs +<<+ acc' :> x') | otherwise = pullout xs (x :>: acc) darcs-2.14.5/src/Darcs/Patch/Dummy.hs0000644000000000000000000000533007346545000015402 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-missing-methods #-} {-# LANGUAGE EmptyDataDecls #-} module Darcs.Patch.Dummy ( DummyPatch ) where import Darcs.Patch.Annotate ( Annotate ) import Darcs.Patch.Conflict ( Conflict, CommuteNoConflicts ) import Darcs.Patch.Debug ( PatchDebug(..) ) import Darcs.Patch.Effect ( Effect ) import Darcs.Patch.FileHunk ( IsHunk ) import Darcs.Patch.Format ( PatchListFormat ) import Darcs.Patch.Matchable ( Matchable ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute ) import Darcs.Patch.Invert ( Invert ) import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Patch.Read ( ReadPatch ) import Darcs.Patch.Show ( ShowPatch ) import Darcs.Patch.Prim ( FromPrim, PrimPatchCommon, PrimPatch, PrimPatchBase(..) ) import Darcs.Patch.Prim.Class ( PrimConstruct, PrimCanonize, PrimClassify , PrimDetails, PrimShow, PrimRead, PrimApply ) import Darcs.Patch.Merge ( Merge) import Darcs.Patch.Repair ( Check, RepairToFL ) import Darcs.Patch.RepoPatch ( RepoPatch ) import Darcs.Patch.Show ( ShowPatchBasic, ShowContextPatch ) import Darcs.Patch.Witnesses.Eq ( Eq2 ) import Darcs.Patch.Witnesses.Show ( Show2 ) import Darcs.Util.Tree( Tree ) data DummyPrim wX wY data DummyPatch wX wY instance IsHunk DummyPrim instance PatchListFormat DummyPrim instance Eq2 DummyPrim instance Invert DummyPrim instance PatchInspect DummyPrim instance ReadPatch DummyPrim instance ShowPatchBasic DummyPrim instance ShowPatch DummyPrim instance ShowContextPatch DummyPrim instance Commute DummyPrim instance Apply DummyPrim where type ApplyState DummyPrim = Tree instance RepairToFL DummyPrim instance PrimConstruct DummyPrim instance PrimCanonize DummyPrim instance PrimClassify DummyPrim instance PrimDetails DummyPrim instance PrimShow DummyPrim instance PrimRead DummyPrim instance PrimApply DummyPrim instance PrimPatch DummyPrim instance Show2 DummyPrim instance PatchDebug DummyPrim instance PrimPatchCommon DummyPrim instance IsHunk DummyPatch instance PatchListFormat DummyPatch instance Eq2 DummyPatch instance Invert DummyPatch instance PatchInspect DummyPatch instance ReadPatch DummyPatch instance ShowPatchBasic DummyPatch instance ShowPatch DummyPatch instance ShowContextPatch DummyPatch instance Show2 DummyPatch instance Commute DummyPatch instance Apply DummyPatch where type ApplyState DummyPatch = Tree instance Matchable DummyPatch instance Annotate DummyPatch instance Effect DummyPatch instance Merge DummyPatch instance Conflict DummyPatch instance FromPrim DummyPatch instance CommuteNoConflicts DummyPatch instance Check DummyPatch instance RepairToFL DummyPatch instance PrimPatchBase DummyPatch where type PrimOf DummyPatch = DummyPrim instance RepoPatch DummyPatch instance PatchDebug DummyPatch darcs-2.14.5/src/Darcs/Patch/Effect.hs0000644000000000000000000000174107346545000015505 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-unrecognised-pragmas #-} module Darcs.Patch.Effect ( Effect(..) ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Prim.Class ( PrimOf ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), reverseFL, reverseRL , concatFL, concatRL, mapFL_FL, mapRL_RL ) -- | Patches whose concrete effect which can be expressed as a list of -- primitive patches. -- -- A minimal definition would be either of @effect@ or @effectRL@. class Effect p where effect :: p wX wY -> FL (PrimOf p) wX wY effect = reverseRL . effectRL effectRL :: p wX wY -> RL (PrimOf p) wX wY effectRL = reverseFL . effect {-# MINIMAL effect | effectRL #-} instance Effect p => Effect (FL p) where effect p = concatFL $ mapFL_FL effect p effectRL p = concatRL $ mapRL_RL effectRL $ reverseFL p instance Effect p => Effect (RL p) where effect p = concatFL $ mapFL_FL effect $ reverseRL p effectRL p = concatRL $ mapRL_RL effectRL p darcs-2.14.5/src/Darcs/Patch/FileHunk.hs0000644000000000000000000000160607346545000016016 0ustar0000000000000000module Darcs.Patch.FileHunk ( FileHunk(..), IsHunk(..), showFileHunk ) where import Prelude () import Darcs.Prelude import Darcs.Util.Path ( FileName ) import Darcs.Patch.Format ( FileNameFormat ) import Darcs.Patch.Show ( formatFileName ) import Darcs.Util.Printer ( Doc, blueText, text, lineColor, vcat, userchunkPS , prefix, ($$), (<+>), Color(Cyan, Magenta) ) import qualified Data.ByteString as B ( ByteString ) data FileHunk wX wY = FileHunk !FileName !Int [B.ByteString] [B.ByteString] class IsHunk p where isHunk :: p wX wY -> Maybe (FileHunk wX wY) showFileHunk :: FileNameFormat -> FileHunk wX wY -> Doc showFileHunk x (FileHunk f line old new) = blueText "hunk" <+> formatFileName x f <+> text (show line) $$ lineColor Magenta (prefix "-" (vcat $ map userchunkPS old)) $$ lineColor Cyan (prefix "+" (vcat $ map userchunkPS new)) darcs-2.14.5/src/Darcs/Patch/Format.hs0000644000000000000000000000302407346545000015535 0ustar0000000000000000module Darcs.Patch.Format ( PatchListFormat(..) , ListFormat(..) , FileNameFormat(..) ) where -- | Showing and reading lists of patches. This class allows us to control how -- lists of patches are formatted on disk. For legacy reasons V1 patches have -- their own special treatment (see 'ListFormat'). Other patch types use the -- default format which just puts them in a sequence without separators or any -- prelude/epilogue. -- -- This means that 'FL (FL p)' etc would be ambiguous, so there are no -- instances for 'FL p' or other list types. class PatchListFormat p where patchListFormat :: ListFormat p patchListFormat = ListFormatDefault -- | This type is used to tweak the way that lists of 'p' are shown for a given -- 'Patch' type 'p'. It is needed to maintain backwards compatibility for V1 -- and V2 patches. data ListFormat (p :: (* -> * -> *)) = ListFormatDefault -- ^ Show and read lists without braces. | ListFormatV1 -- ^ Show lists with a single layer of braces around -- the outside, except for singletons which have no -- braces. Read with arbitrary nested braces and parens -- and flatten them out. | ListFormatV2 -- ^ Show lists without braces. Read with arbitrary -- nested parens and flatten them out. data FileNameFormat = OldFormat -- ^ on-disk format for V1 patches | NewFormat -- ^ on-disk format for V2 patches | UserFormat -- ^ display format deriving (Eq, Show) darcs-2.14.5/src/Darcs/Patch/Index/0000755000000000000000000000000007346545000015021 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/Index/Monad.hs0000644000000000000000000001072607346545000016421 0ustar0000000000000000-- Copyright (C) 2009 Benedikt Schmidt -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} module Darcs.Patch.Index.Monad ( withPatchMods , applyToFileMods , makePatchID ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Index.Types ( PatchMod(..), PatchId(..) ) import Darcs.Patch.Info ( makePatchname, PatchInfo ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.ApplyMonad ( ApplyMonad(..), ApplyMonadTree(..) ) import Control.Monad.State import Control.Arrow import Darcs.Util.Path ( FileName, fn2fp, movedirfilename ) import qualified Data.Set as S import Data.Set ( Set ) import Data.List ( isPrefixOf ) import Darcs.Util.Tree (Tree) newtype FileModMonad a = FMM (State (Set FileName, [PatchMod FileName]) a) deriving (Functor, Applicative, Monad, MonadState (Set FileName, [PatchMod FileName])) withPatchMods :: FileModMonad a -> Set FileName -> (Set FileName, [PatchMod FileName]) withPatchMods (FMM m) fps = second reverse $ execState m (fps,[]) -- These instances are defined to be used only with -- apply. instance ApplyMonad Tree FileModMonad where type ApplyMonadBase FileModMonad = FileModMonad nestedApply _ _ = bug "nestedApply FileModMonad" liftApply _ _ = bug "liftApply FileModMonad" getApplyState = bug "getApplyState FileModMonad" instance ApplyMonadTree FileModMonad where mDoesDirectoryExist d = do fps <- gets fst return $ S.member d fps mDoesFileExist f = do fps <- gets fst return $ S.member f fps mReadFilePS _ = bug "mReadFilePS FileModMonad" mCreateFile = createFile mCreateDirectory = createDir mRemoveFile = remove mRemoveDirectory = remove mRename a b = do fns <- gets fst if S.notMember a fns then addMod (PInvalid a) -- works around some old repo inconsistencies else do -- we have to account for directory moves addMod (PRename a b) modifyFps (S.delete a) addFile b forM_ (S.toList fns) $ \fn -> when (fn2fp a `isPrefixOf` fn2fp fn) $ do modifyFps (S.delete fn) let newfn = movedirfilename a b fn addFile newfn addMod (PRename fn newfn) mModifyFilePS f _ = addMod (PTouch f) -- --------------------------------------------------------------------- -- State Handling Functions addMod :: PatchMod FileName -> FileModMonad () addMod pm = modify $ second (pm :) addFile :: FileName -> FileModMonad () addFile f = modifyFps (S.insert f) createFile :: FileName -> FileModMonad () createFile fn = do errorIfPresent fn True addMod (PCreateFile fn) addFile fn createDir :: FileName -> FileModMonad () createDir fn = do errorIfPresent fn False addMod (PCreateDir fn) addFile fn errorIfPresent :: FileName -> Bool -> FileModMonad () errorIfPresent fn isFile = do fs <- gets fst when (S.member fn fs) $ error $ unwords [ "error: patch index entry for" , if isFile then "file" else "directory" , fn2fp fn , "created >1 times. Run `darcs repair` and try again." ] remove :: FileName -> FileModMonad () remove f = addMod (PRemove f) >> modifyFps (S.delete f) modifyFps :: (Set FileName -> Set FileName) -> FileModMonad () modifyFps f = modify $ first f makePatchID :: PatchInfo -> PatchId makePatchID = PID . makePatchname -------------------------------------------------------------------------------- -- | Apply a patch to set of 'FileName's, yielding the new set of 'FileName's and 'PatchMod's applyToFileMods :: (Apply p, ApplyState p ~ Tree) => p wX wY -> Set FileName -> (Set FileName, [PatchMod FileName]) applyToFileMods patch = withPatchMods (apply patch) darcs-2.14.5/src/Darcs/Patch/Index/Types.hs0000644000000000000000000000515207346545000016464 0ustar0000000000000000{-# LANGUAGE DeriveFunctor #-} -- Copyright (C) 2009-2010 Benedikt Schmidt -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.Index.Types where import Prelude () import Darcs.Prelude import Darcs.Util.Hash( SHA1, sha1short, sha1zero ) import Darcs.Util.Path ( fn2fp, FileName ) import Data.Binary ( Binary(..) ) import Data.Word ( Word32 ) -- | The FileId for a file consists of the FilePath (creation name) -- and an index. The index denotes how many files -- with the same name have been added before (and subsequently -- deleted or moved) data FileId = FileId {cname::FileName,count::Int} deriving (Eq,Show,Ord) instance Binary FileId where put (FileId rfp i) = put (rfp,i) get = do (rfp,cnt) <- get return $ FileId rfp cnt -- | Convert FileId to string showFileId :: FileId -> String showFileId (FileId fn i) = show i++"#"++fn2fp fn -- | The PatchId identifies a patch and can be created from a PatchInfo with makePatchname newtype PatchId = PID {patchId :: SHA1} deriving (Show,Ord,Eq) instance Binary PatchId where put (PID p) = put p get = PID `fmap` get pid2string :: PatchId -> String pid2string = show . patchId -- | This is used to track changes to files data PatchMod a = PTouch a | PCreateFile a | PCreateDir a | PRename a a | PRemove a | PInvalid a -- ^ This is an invalid patch -- e.g. there is a patch 'Move Autoconf.lhs Autoconf.lhs.in' -- where there is no Autoconf.lhs in the darcs repo | PDuplicateTouch a -- ^ this is used for duplicate patches that don't -- have any effect, but we still want to keep -- track of them deriving (Show, Eq, Functor) short :: PatchId -> Word32 short (PID sha1) = sha1short sha1 zero :: PatchId zero = PID sha1zero darcs-2.14.5/src/Darcs/Patch/Info.hs0000644000000000000000000003531607346545000015211 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.Info ( PatchInfo(..) -- constructor and fields exported *only for tests* , rawPatchInfo -- exported *only for tests* , patchinfo , invertName , addJunk , makePatchname , readPatchInfo , justName , justAuthor , justLog , displayPatchInfo , toXml , toXmlShort , piDate , setPiDate , piDateString , piName , piRename , piAuthor , piTag , piLog , showPatchInfo , isTag , escapeXML , validDate , validLog , validAuthor , validDatePS , validLogPS , validAuthorPS ) where import Prelude ( (^) ) import Darcs.Prelude import Data.Char ( isAscii ) import System.Random ( randomRIO ) import Numeric ( showHex ) import Control.Monad ( when, unless, void ) import Darcs.Util.ByteString ( decodeLocale , packStringToUTF8 , unlinesPS , unpackPSFromUTF8 ) import qualified Darcs.Patch.ReadMonads as RM ( take ) import Darcs.Patch.ReadMonads as RM ( skipSpace, char, takeTill, anyChar, ParserM, option, takeTillChar, linesStartingWithEndingWith) import Darcs.Patch.Show ( ShowPatchFor(..) ) import qualified Data.ByteString as B (length, splitAt, null ,isPrefixOf, tail, concat ,empty, head, cons, append ,ByteString ) import qualified Data.ByteString.Char8 as BC ( index, head, notElem, all, unpack, pack ) import Data.List( isPrefixOf ) import Darcs.Util.Printer ( Doc, packedString, empty, ($$), (<+>), vcat, text, cyanText, blueText, prefix ) import Darcs.Util.IsoDate ( readUTCDate ) import System.Time ( CalendarTime, calendarTimeToString, toClockTime, toCalendarTime ) import System.IO.Unsafe ( unsafePerformIO ) import Darcs.Util.Hash ( sha1PS, SHA1 ) import Darcs.Util.Prompt ( promptYorn ) import Darcs.Util.Show ( appPrec ) -- | A PatchInfo value contains the metadata of a patch. The date, name, author -- and log fields are UTF-8 encoded text in darcs 2.4 and later, and just -- sequences of bytes (decoded with whatever is the locale when displayed) in -- earlier darcs. -- -- The members with names that start with '_' are not supposed to be used -- directly in code that does not care how the patch info is stored. data PatchInfo = PatchInfo { _piDate :: !B.ByteString , _piName :: !B.ByteString , _piAuthor :: !B.ByteString , _piLog :: ![B.ByteString] , isInverted :: !Bool } deriving (Eq,Ord) instance Show PatchInfo where showsPrec d (PatchInfo date name author log inverted) = showParen (d > appPrec) $ showString "rawPatchInfo " . showsPrec (appPrec + 1) date . showString " " . showsPrec (appPrec + 1) name . showString " " . showsPrec (appPrec + 1) author . showString " " . showsPrec (appPrec + 1) log . showString " " . showsPrec (appPrec + 1) inverted -- Validation -- We need these functions to ensure that we can parse the -- result of showPatchInfo. validDate :: String -> Bool validDate = all validCharForDate validDatePS :: B.ByteString -> Bool validDatePS = BC.all validCharForDate -- | The isAscii limitation is due to the use of BC.pack below. validCharForDate :: Char -> Bool validCharForDate c = isAscii c && c /= '\n' && c /= ']' validLog :: String -> Bool validLog = notElem '\n' validLogPS :: B.ByteString -> Bool validLogPS = BC.notElem '\n' validAuthor :: String -> Bool validAuthor = notElem '*' validAuthorPS :: B.ByteString -> Bool validAuthorPS = BC.notElem '*' rawPatchInfo :: String -> String -> String -> [String] -> Bool -> PatchInfo rawPatchInfo date name author log inverted = PatchInfo { _piDate = BC.pack $ validateDate date , _piName = packStringToUTF8 $ validateName name , _piAuthor = packStringToUTF8 $ validateAuthor author , _piLog = map (packStringToUTF8 . validateLog) log , isInverted = inverted } where validateAuthor = validate validAuthor "author" validateName = validate validLog "patch name" validateLog = validate validLog "log line" validateDate = validate validDate "date" validate test meta x = if test x then x else error (unwords ["invalid",meta,show x]) -- | @patchinfo date name author log@ constructs a new 'PatchInfo' value -- with the given details, automatically assigning an Ignore-this header -- to guarantee the patch is unique. The function does not verify -- the date string's sanity. patchinfo :: String -> String -> String -> [String] -> IO PatchInfo patchinfo date name author log = addJunk $ rawPatchInfo date name author log False -- | addJunk adds a line that contains a random number to make the patch -- unique. addJunk :: PatchInfo -> IO PatchInfo addJunk pinf = do x <- randomRIO (0,2^(128 ::Integer) :: Integer) when (_piLog pinf /= ignoreJunk (_piLog pinf)) $ do putStrLn $ "Lines beginning with 'Ignore-this: ' " ++ "will not be shown when displaying a patch." confirmed <- promptYorn "Proceed? " unless confirmed $ fail "User cancelled because of Ignore-this." return $ pinf { _piLog = BC.pack (head ignored++showHex x ""): _piLog pinf } ignored :: [String] -- this is a [String] so we can change the junk header. ignored = ["Ignore-this: "] ignoreJunk :: [B.ByteString] -> [B.ByteString] ignoreJunk = filter isnt_ignored where isnt_ignored x = doesnt_start_with x (map BC.pack ignored) -- TODO doesnt_start_with x ys = not $ any (`B.isPrefixOf` x) ys -- * Patch info formatting invertName :: PatchInfo -> PatchInfo invertName pi = pi { isInverted = not (isInverted pi) } -- | Get the name, including an "UNDO: " prefix if the patch is inverted. justName :: PatchInfo -> String justName pinf = if isInverted pinf then "UNDO: " ++ nameString else nameString where nameString = metadataToString (_piName pinf) -- | Returns the author of a patch. justAuthor :: PatchInfo -> String justAuthor = metadataToString . _piAuthor justLog :: PatchInfo -> String justLog = unlines . map BC.unpack . _piLog displayPatchInfo :: PatchInfo -> Doc displayPatchInfo pi = cyanText "patch " <> cyanText (show $ makePatchname pi) $$ text "Author: " <> text (piAuthor pi) $$ text "Date: " <> text (friendlyD $ _piDate pi) $$ hfn (piName pi) $$ vcat (map ((text " " <>) . text) (piLog pi)) where hfn x = case piTag pi of Nothing -> inverted <+> text x Just t -> text " tagged" <+> text t inverted = if isInverted pi then text " UNDO:" else text " *" -- | Returns the name of the patch. Unlike 'justName', it does not preprend -- "UNDO: " to the name if the patch is inverted. piName :: PatchInfo -> String piName = metadataToString . _piName piRename :: PatchInfo -> String -> PatchInfo piRename x n = x { _piName = packStringToUTF8 n } -- | Returns the author of a patch. piAuthor :: PatchInfo -> String piAuthor = metadataToString . _piAuthor isTag :: PatchInfo -> Bool isTag pinfo = "TAG " `isPrefixOf` justName pinfo -- | Read the date from raw patch (meta) data and convert it to UTC. -- The raw data may contain timezone info. This is for compatibiltity -- with patches that were created before 2003-11, when darcs still -- created patches that contained localized date strings. readPatchDate :: B.ByteString -> CalendarTime readPatchDate = readUTCDate . BC.unpack piDate :: PatchInfo -> CalendarTime piDate = readPatchDate . _piDate piDateString :: PatchInfo -> String piDateString = BC.unpack . _piDate setPiDate :: String -> PatchInfo -> PatchInfo setPiDate date pi = pi { _piDate = BC.pack date } -- | Get the log message of a patch. piLog :: PatchInfo -> [String] piLog = map metadataToString . ignoreJunk . _piLog -- | Get the tag name, if the patch is a tag patch. piTag :: PatchInfo -> Maybe String piTag pinf = if l == t then Just $ metadataToString r else Nothing where (l, r) = B.splitAt (B.length t) (_piName pinf) t = BC.pack "TAG " -- | Convert a metadata ByteString to a string. It first tries to convert -- using UTF-8, and if that fails, tries the locale encoding. -- We try UTF-8 first because UTF-8 is clearly recognizable, widely used, -- and people may have UTF-8 patches even when UTF-8 is not their locale. metadataToString :: B.ByteString -> String metadataToString bs | '\xfffd' `notElem` bsUtf8 = bsUtf8 | otherwise = decodeLocale bs where bsUtf8 = unpackPSFromUTF8 bs friendlyD :: B.ByteString -> String friendlyD d = unsafePerformIO $ do ct <- toCalendarTime $ toClockTime $ readPatchDate d return $ calendarTimeToString ct toXml :: PatchInfo -> Doc toXml = toXml' True toXmlShort :: PatchInfo -> Doc toXmlShort = toXml' False toXml' :: Bool -> PatchInfo -> Doc toXml' includeComments pi = text " text "author='" <> escapeXMLByteString (_piAuthor pi) <> text "'" <+> text "date='" <> escapeXMLByteString (_piDate pi) <> text "'" <+> text "local_date='" <> escapeXML (friendlyD $ _piDate pi) <> text "'" <+> text "inverted='" <> text (show $ isInverted pi) <> text "'" <+> text "hash='" <> text (show $ makePatchname pi) <> text "'>" $$ indent abstract $$ text "" where indent = prefix " " name = text "" <> escapeXMLByteString (_piName pi) <> text "" abstract | includeComments = name $$ commentsAsXml (_piLog pi) | otherwise = name commentsAsXml :: [B.ByteString] -> Doc commentsAsXml comments | B.length comments' > 0 = text "" <> escapeXMLByteString comments' <> text "" | otherwise = empty where comments' = unlinesPS comments -- escapeXML is duplicated in Patch.lhs and Annotate.lhs -- It should probably be refactored to exist in one place. escapeXML :: String -> Doc escapeXML = text . strReplace '\'' "'" . strReplace '"' """ . strReplace '>' ">" . strReplace '<' "<" . strReplace '&' "&" -- Escape XML characters in a UTF-8 encoded ByteString, and turn it into a Doc. -- The data will be in the Doc as a bytestring. escapeXMLByteString :: B.ByteString -> Doc escapeXMLByteString = packedString . bstrReplace '\'' "'" . bstrReplace '"' """ . bstrReplace '>' ">" . bstrReplace '<' "<" . bstrReplace '&' "&" strReplace :: Char -> String -> String -> String strReplace _ _ [] = [] strReplace x y (z:zs) | x == z = y ++ strReplace x y zs | otherwise = z : strReplace x y zs bstrReplace :: Char -> String -> B.ByteString -> B.ByteString bstrReplace c s bs | B.null bs = B.empty | otherwise = if BC.head bs == c then B.append (BC.pack s) (bstrReplace c s (B.tail bs)) else B.cons (B.head bs) (bstrReplace c s (B.tail bs)) -- | Hash on patch metadata (patch name, author, date, log, and \"inverted\" -- flag. Robust against context changes but does not garantee patch contents. -- Usually used as matcher or patch identifier (see Darcs.Patch.Match). makePatchname :: PatchInfo -> SHA1 makePatchname pi = sha1PS sha1_me where b2ps True = BC.pack "t" b2ps False = BC.pack "f" sha1_me = B.concat [_piName pi, _piAuthor pi, _piDate pi, B.concat $ _piLog pi, b2ps $ isInverted pi] showPatchInfo :: ShowPatchFor -> PatchInfo -> Doc showPatchInfo ForDisplay = displayPatchInfo showPatchInfo ForStorage = storePatchInfo -- |Patch is stored between square brackets. -- -- > [ -- > * -- > (indented one) -- > -- > -- > -- > ] -- -- note that below I assume the name has no newline in it. -- See 'readPatchInfo' for the inverse operation. -- There are more assumptions, see validation functions above. storePatchInfo :: PatchInfo -> Doc storePatchInfo pi = blueText "[" <> packedString (_piName pi) $$ packedString (_piAuthor pi) <> text inverted <> packedString (_piDate pi) <> myunlines (_piLog pi) <> blueText "] " where inverted = if isInverted pi then "*-" else "**" myunlines [] = empty myunlines xs = foldr (\s -> ((text "\n " <> packedString s) <>)) (text "\n") xs -- |Parser for 'PatchInfo' as stored in patch bundles and inventory files, -- for example: -- -- > [Document the foo interface -- > John Doe **20110615084241 -- > Ignore-this: 85b94f67d377c4ab671101266ef9c229 -- > Nobody knows what a 'foo' is, so describe it. -- > ] -- -- See 'showPatchInfo' for the inverse operation. readPatchInfo :: ParserM m => m PatchInfo readPatchInfo = do skipSpace char '[' name <- takeTillChar '\n' _ <- anyChar author <- takeTillChar '*' s2 <- RM.take 2 ct <- takeTill (\c->c==']'||c=='\n') option () (void (char '\n')) -- consume newline char, if present log <- linesStartingWithEndingWith ' ' ']' return PatchInfo { _piDate = ct , _piName = name , _piAuthor = author , _piLog = log , isInverted = BC.index s2 1 /= '*' } darcs-2.14.5/src/Darcs/Patch/Inspect.hs0000644000000000000000000000130707346545000015714 0ustar0000000000000000module Darcs.Patch.Inspect ( PatchInspect(..) ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Witnesses.Ordered ( FL, RL, reverseRL, mapFL ) import qualified Data.ByteString.Char8 as BC import Data.List ( nub ) class PatchInspect p where listTouchedFiles :: p wX wY -> [FilePath] hunkMatches :: (BC.ByteString -> Bool) -> p wX wY -> Bool instance PatchInspect p => PatchInspect (FL p) where listTouchedFiles xs = nub $ concat $ mapFL listTouchedFiles xs hunkMatches f = or . mapFL (hunkMatches f) instance PatchInspect p => PatchInspect (RL p) where listTouchedFiles = listTouchedFiles . reverseRL hunkMatches f = hunkMatches f . reverseRL darcs-2.14.5/src/Darcs/Patch/Invert.hs0000644000000000000000000000135607346545000015562 0ustar0000000000000000module Darcs.Patch.Invert ( Invert(..), invertFL, invertRL ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), reverseFL, reverseRL, (:>)(..) ) class Invert p where invert :: p wX wY -> p wY wX invertFL :: Invert p => FL p wX wY -> RL p wY wX invertFL NilFL = NilRL invertFL (x:>:xs) = invertFL xs :<: invert x invertRL :: Invert p => RL p wX wY -> FL p wY wX invertRL NilRL = NilFL invertRL (xs:<:x) = invert x :>: invertRL xs instance Invert p => Invert (FL p) where invert = reverseRL . invertFL instance Invert p => Invert (RL p) where invert = reverseFL . invertRL instance Invert p => Invert (p :> p) where invert (a :> b) = invert b :> invert a darcs-2.14.5/src/Darcs/Patch/Match.hs0000644000000000000000000007665307346545000015363 0ustar0000000000000000-- Copyright (C) 2004-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE ScopedTypeVariables, MultiParamTypeClasses, FlexibleInstances #-} -- | /First matcher, Second matcher and Nonrange matcher/ -- -- When we match for patches, we have a PatchSet, of which we want a -- subset. This subset is formed by the patches in a given interval -- which match a given criterion. If we represent time going left to -- right, then we have (up to) three 'Matcher's: -- -- * the 'firstMatcher' is the left bound of the interval, -- -- * the 'secondMatcher' is the right bound, and -- -- * the 'nonrangeMatcher' is the criterion we use to select among -- patches in the interval. --- -- Each of these matchers can be present or not according to the -- options. The patches we want would then be the ones that all -- present matchers have in common. -- -- (Implementation note: keep in mind that the PatchSet is written -- backwards with respect to the timeline, ie., from right to left) module Darcs.Patch.Match ( matchParser , helpOnMatchers , addInternalMatcher , matchFirstPatchset , matchSecondPatchset , splitSecondFL , matchPatch , matchAPatch , getNonrangeMatchS , firstMatch , secondMatch , haveNonrangeMatch , haveNonrangeExplicitMatch , havePatchsetMatch , checkMatchSyntax , applyInvToMatcher , nonrangeMatcher , InclusiveOrExclusive(..) , matchExists , applyNInv , hasIndexRange , getMatchingTag , matchAPatchset , getFirstMatchS , nonrangeMatcherIsTag , MatchFlag(..) ) where import Prelude () import Darcs.Prelude import Control.Exception ( throw ) import Text.ParserCombinators.Parsec ( parse , CharParser , () , (<|>) , noneOf , option , eof , many , try , between , spaces , char , oneOf , string , choice ) import Text.ParserCombinators.Parsec.Expr ( OperatorTable , Assoc( AssocLeft ) , Operator ( Infix, Prefix ) , buildExpressionParser ) import Text.Regex ( mkRegex, matchRegex ) import Data.Maybe ( isJust ) import System.IO.Unsafe ( unsafePerformIO ) import Control.Monad ( when ) import Data.List ( isPrefixOf, intercalate ) import Data.Char ( toLower ) import Darcs.Util.Path ( AbsolutePath ) import Darcs.Patch ( IsRepoType , hunkMatches , listTouchedFiles , invert , invertRL , apply ) import Darcs.Patch.Info ( justName, justAuthor, justLog, makePatchname, piDate ) import Darcs.Patch.Named.Wrapped ( WrappedNamed , patch2patchinfo ) import qualified Data.ByteString.Char8 as BC import Darcs.Patch.Dummy ( DummyPatch ) import Darcs.Patch.Matchable ( Matchable ) import Darcs.Patch.MonadProgress ( MonadProgress ) import Darcs.Patch.Named.Wrapped ( runInternalChecker, namedIsInternal, namedInternalChecker ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info, conscientiously, hopefully ) import Darcs.Patch.Set ( PatchSet(..), Tagged(..), SealedPatchSet, patchSet2RL, Origin ) import Darcs.Patch.Type ( PatchType(..) ) import Darcs.Patch.Apply( Apply, ApplyState ) import Darcs.Patch.ApplyPatches( applyPatches ) import Darcs.Patch.Depends ( getPatchesBeyondTag, splitOnTag ) import Darcs.Patch.Invert( Invert ) import Darcs.Patch.Witnesses.Eq ( isIsEq ) import Darcs.Patch.Witnesses.Ordered ( RL(..), snocRLSealed, FL(..), (:>)(..) ) import Darcs.Patch.Witnesses.Sealed ( FlippedSeal(..), Sealed2(..), seal, flipSeal, seal2, unsealFlipped, unseal2, unseal ) import Darcs.Util.Printer ( text, ($$) ) import Darcs.Patch.ApplyMonad ( ApplyMonad(..) ) import Darcs.Util.DateMatcher ( parseDateMatcher ) import Darcs.Util.Tree ( Tree ) -- | A type for predicates over patches which do not care about -- contexts type MatchFun rt p = Sealed2 (PatchInfoAnd rt p) -> Bool -- | A @Matcher@ is made of a 'MatchFun' which we will use to match -- patches and a @String@ representing it. data Matcher rt p = MATCH String (MatchFun rt p) instance Show (Matcher rt p) where show (MATCH s _) = '"':s ++ "\"" data MatchFlag = OnePattern String | SeveralPattern String | AfterPattern String | UpToPattern String | OnePatch String | OneHash String | AfterHash String | UpToHash String | SeveralPatch String | AfterPatch String | UpToPatch String | OneTag String | AfterTag String | UpToTag String | LastN Int | PatchIndexRange Int Int | Context AbsolutePath deriving ( Show ) makeMatcher :: String -> MatchFun rt p -> Matcher rt p makeMatcher = MATCH -- | @applyMatcher@ applies a matcher to a patch. applyMatcher :: Matcher rt p -> PatchInfoAnd rt p wX wY -> Bool applyMatcher (MATCH _ m) = m . seal2 parseMatch :: Matchable p => String -> Either String (MatchFun rt p) parseMatch pattern = case parse matchParser "match" pattern of Left err -> Left $ "Invalid --match pattern '"++ pattern ++ "'.\n"++ unlines (map (" "++) $ lines $ show err) -- indent Right m -> Right m matchPattern :: Matchable p => String -> Matcher rt p matchPattern pattern = case parseMatch pattern of Left err -> error err Right m -> makeMatcher pattern m addInternalMatcher :: (IsRepoType rt) => Maybe (Matcher rt p) -> Maybe (Matcher rt p) addInternalMatcher om = case namedInternalChecker of Nothing -> om Just f -> let matchFun = unseal2 (not . isIsEq . runInternalChecker f . hopefully) in case om of Nothing -> Just (MATCH "internal patch" matchFun) Just (MATCH s oldFun) -> Just (MATCH s (\p -> matchFun p && oldFun p)) matchParser :: Matchable p => CharParser st (MatchFun rt p) matchParser = submatcher helpfulErrorMsg where submatcher = do m <- option matchAnyPatch submatch eof return m -- When using , Parsec prepends "expecting " to the given error message, -- so the phrasing below makes sense. helpfulErrorMsg = "valid expressions over: " ++ intercalate ", " (map (\(name, _, _, _, _) -> name) ps) ++ "\nfor more help, see `darcs help patterns`." -- This type signature is just to bind an ambiguous type var. ps :: [(String, String, String, [String], String -> MatchFun rt DummyPatch)] ps = primitiveMatchers -- matchAnyPatch is returned if submatch fails without consuming any -- input, i.e. if we pass --match '', we want to match anything. matchAnyPatch :: MatchFun rt p matchAnyPatch = const True submatch :: Matchable p => CharParser st (MatchFun rt p) submatch = buildExpressionParser table match table :: OperatorTable Char st (MatchFun rt p) table = [ [prefix "not" negate_match, prefix "!" negate_match ] , [binary "||" or_match, binary "or" or_match, binary "&&" and_match, binary "and" and_match ] ] where binary name fun = Infix (tryNameAndUseFun name fun) AssocLeft prefix name fun = Prefix $ tryNameAndUseFun name fun tryNameAndUseFun name fun = do _ <- trystring name spaces return fun negate_match a p = not (a p) or_match m1 m2 p = m1 p || m2 p and_match m1 m2 p = m1 p && m2 p trystring :: String -> CharParser st String trystring s = try $ string s match :: Matchable p => CharParser st (MatchFun rt p) match = between spaces spaces (parens submatch <|> choice matchers_) where matchers_ = map createMatchHelper primitiveMatchers createMatchHelper :: (String, String, String, [String], String -> MatchFun rt p) -> CharParser st (MatchFun rt p) createMatchHelper (key,_,_,_,matcher) = do _ <- trystring key spaces q <- quoted return $ matcher q -- | The string that is emitted when the user runs @darcs help patterns@. helpOnMatchers :: [String] helpOnMatchers = ["Selecting Patches:", "", "The --patches option yields patches with names matching an *extended*", "regular expression. See regex(7) for details. The --matches option", "yields patches that match a logical (Boolean) expression: one or more", "primitive expressions combined by grouping (parentheses) and the", "complement (not), conjunction (and) and disjunction (or) operators.", "The C notation for logic operators (!, && and ||) can also be used.", "", "- --patches=regex is a synonym for --matches='name regex'", "- --hash=HASH is a synonym for --matches='hash HASH'", "- --from-patch and --to-patch are synonyms for --from-match='name... and --to-match='name...", "- --from-patch and --to-match can be unproblematically combined:", " `darcs log --from-patch='html.*documentation' --to-match='date 20040212'`", "", "The following primitive Boolean expressions are supported:" ,""] ++ keywords ++ ["", "Here are some examples:", ""] ++ examples where -- This type signature exists to appease GHC. ps :: [(String, String, String, [String], String -> MatchFun rt DummyPatch)] ps = primitiveMatchers keywords = [showKeyword (unwords [k,a]) d | (k,a,d,_,_) <- ps] examples = [showExample k e | (k,_,_,es,_) <- ps, e <- es] showKeyword keyword description = " " ++ keyword ++ " - " ++ description ++ "." showExample keyword example = " darcs log --match " ++ "'" ++ keyword ++ " " ++ example ++ "'" primitiveMatchers :: Matchable p => [(String, String, String, [String], String -> MatchFun rt p)] -- ^ keyword (operator), argument name, help description, list -- of examples, matcher function primitiveMatchers = [ ("exact", "STRING", "check literal STRING is equal to patch name" , ["\"Resolve issue17: use dynamic memory allocation.\""] , exactmatch ) , ("name", "REGEX", "match REGEX against patch name" , ["issue17", "\"^[Rr]esolve issue17\\>\""] , namematch ) , ("author", "REGEX", "match REGEX against patch author" , ["\"David Roundy\"", "droundy", "droundy@darcs.net"] , authormatch ) , ("hunk", "REGEX", "match REGEX against contents of a hunk patch" , ["\"foo = 2\"", "\"^instance .* Foo where$\""] , hunkmatch ) , ("comment", "REGEX", "match REGEX against the full log message" , ["\"prevent deadlocks\""] , logmatch ) , ("hash", "HASH", "match HASH against (a prefix of) the hash of a patch" , ["c719567e92c3b0ab9eddd5290b705712b8b918ef","c7195"] , hashmatch ) , ("date", "DATE", "match DATE against the patch date" , ["\"2006-04-02 22:41\"", "\"tea time yesterday\""] , datematch ) , ("touch", "REGEX", "match file paths for a patch" , ["src/foo.c", "src/", "\"src/*.(c|h)\""] , touchmatch ) ] parens :: CharParser st (MatchFun rt p) -> CharParser st (MatchFun rt p) parens = between (string "(") (string ")") quoted :: CharParser st String quoted = between (char '"') (char '"') (many $ do { _ <- char '\\' -- allow escapes ; try (oneOf "\\\"") <|> return '\\' } <|> noneOf "\"") <|> between spaces spaces (many $ noneOf " ()") "string" datematch, hashmatch, authormatch, exactmatch, namematch, logmatch :: String -> MatchFun rt p hunkmatch, touchmatch :: Matchable p => String -> MatchFun rt p namematch r (Sealed2 hp) = isJust $ matchRegex (mkRegex r) $ justName (info hp) exactmatch r (Sealed2 hp) = r == justName (info hp) authormatch a (Sealed2 hp) = isJust $ matchRegex (mkRegex a) $ justAuthor (info hp) logmatch l (Sealed2 hp) = isJust $ matchRegex (mkRegex l) $ justLog (info hp) hunkmatch r (Sealed2 hp) = let regexMatcher = isJust . matchRegex (mkRegex r) . BC.unpack in hunkMatches regexMatcher hp hashmatch h (Sealed2 hp) = let rh = show $ makePatchname (info hp) lh = map toLower h in (lh `isPrefixOf` rh) || (lh == rh ++ ".gz") datematch d (Sealed2 hp) = let dm = unsafePerformIO $ parseDateMatcher d in dm $ piDate (info hp) touchmatch r (Sealed2 hp) = let files = listTouchedFiles hp in any (isJust . matchRegex (mkRegex r)) files data InclusiveOrExclusive = Inclusive | Exclusive deriving Eq data IncludeInternalPatches = IncludeInternalPatches | ExcludeInternalPatches deriving Eq -- | @haveNonrangeMatch flags@ tells whether there is a flag in -- @flags@ which corresponds to a match that is "non-range". Thus, -- @--match@, @--patch@, @--hash@ and @--index@ make @haveNonrangeMatch@ -- true, but not @--from-patch@ or @--to-patch@. haveNonrangeMatch :: forall rt p . (IsRepoType rt, Matchable p) => PatchType rt p -> [MatchFlag] -> Bool haveNonrangeMatch pt fs = haveNonrangeMatch' IncludeInternalPatches pt fs -- | @haveNonrangeExplicitMatch flags@ is just like @haveNonrangeMatch flags@, -- but ignores "internal matchers" used to mask "internal patches" haveNonrangeExplicitMatch :: forall rt p . (IsRepoType rt, Matchable p) => PatchType rt p -> [MatchFlag] -> Bool haveNonrangeExplicitMatch pt fs = haveNonrangeMatch' ExcludeInternalPatches pt fs haveNonrangeMatch' :: forall rt p . (IsRepoType rt, Matchable p) => IncludeInternalPatches -> PatchType rt p -> [MatchFlag] -> Bool haveNonrangeMatch' i _ fs = case hasIndexRange fs of Just (m,n) | m == n -> True; _ -> False || isJust (nonrangeMatch::Maybe (Matcher rt p)) where nonrangeMatch | i == IncludeInternalPatches = nonrangeMatcher fs | otherwise = nonrangeMatcherArgs fs -- | @havePatchsetMatch flags@ tells whether there is a "patchset -- match" in the flag list. A patchset match is @--match@ or -- @--patch@, or @--context@, but not @--from-patch@ nor (!) -- @--index@. -- Question: Is it supposed not to be a subset of @haveNonrangeMatch@? havePatchsetMatch :: forall rt p . (IsRepoType rt, Matchable p) => PatchType rt p -> [MatchFlag] -> Bool havePatchsetMatch _ fs = isJust (nonrangeMatcher fs::Maybe (Matcher rt p)) || hasC fs where hasC [] = False hasC (Context _:_) = True hasC (_:xs) = hasC xs getNonrangeMatchS :: ( ApplyMonad (ApplyState p) m, MonadProgress m , IsRepoType rt, Matchable p, ApplyState p ~ Tree ) => [MatchFlag] -> PatchSet rt p Origin wX -> m () getNonrangeMatchS fs repo = case nonrangeMatcher fs of Just m -> if nonrangeMatcherIsTag fs then getTagS m repo else getMatcherS Exclusive m repo Nothing -> throw $ userError "Pattern not specified in getNonrangeMatch." -- | @firstMatch fs@ tells whether @fs@ implies a "first match", that -- is if we match against patches from a point in the past on, rather -- than against all patches since the creation of the repository. firstMatch :: [MatchFlag] -> Bool firstMatch fs = isJust (hasLastn fs) || isJust (firstMatcher fs::Maybe (Matcher rt DummyPatch)) || isJust (hasIndexRange fs) getFirstMatchS :: (ApplyMonad (ApplyState p) m, MonadProgress m, Matchable p, IsRepoType rt) => [MatchFlag] -> PatchSet rt p Origin wX -> m () getFirstMatchS fs repo = case hasLastn fs of Just n -> unpullLastN repo n Nothing -> case hasIndexRange fs of Just (_,b) -> unpullLastN repo b -- b is chronologically earlier than a Nothing -> case firstMatcher fs of Nothing -> throw $ userError "Pattern not specified in getFirstMatchS." Just m -> if firstMatcherIsTag fs then getTagS m repo else getMatcherS Inclusive m repo -- | @secondMatch fs@ tells whether @fs@ implies a "second match", that -- is if we match against patches up to a point in the past on, rather -- than against all patches until now. secondMatch :: [MatchFlag] -> Bool secondMatch fs = isJust (secondMatcher fs::Maybe (Matcher rt DummyPatch)) || isJust (hasIndexRange fs) unpullLastN :: (Apply p, Invert p, ApplyMonad (ApplyState p) m, MonadProgress m, IsRepoType rt) => PatchSet rt p wX wY -> Int -> m () unpullLastN repo n = applyInvRL `unsealFlipped` safetake n (patchSet2RL repo) checkMatchSyntax :: [MatchFlag] -> IO () checkMatchSyntax opts = case getMatchPattern opts of Nothing -> return () Just p -> either (throw . userError) (const $ return ()) (parseMatch p::Either String (MatchFun rt DummyPatch)) getMatchPattern :: [MatchFlag] -> Maybe String getMatchPattern [] = Nothing getMatchPattern (OnePattern m:_) = Just m getMatchPattern (SeveralPattern m:_) = Just m getMatchPattern (_:fs) = getMatchPattern fs tagmatch :: String -> Matcher rt p tagmatch r = makeMatcher ("tag-name "++r) tm where tm (Sealed2 p) = let n = justName (info p) in "TAG " `isPrefixOf` n && isJust (matchRegex (mkRegex r) $ drop 4 n) patchmatch :: String -> Matcher rt p patchmatch r = makeMatcher ("patch-name "++r) (namematch r) hashmatch' :: String -> Matcher rt p hashmatch' r = makeMatcher ("hash "++r) (hashmatch r) -- | strictJust is a strict version of the Just constructor, used to ensure -- that if we claim we've got a pattern match, that the pattern will -- actually match (rathern than fail to compile properly). strictJust :: a -> Maybe a strictJust x = Just $! x -- | @nonrangeMatcher@ is the criterion that is used to match against -- patches in the interval. It is 'Just m' when the @--patch@, @--match@, -- @--tag@ options are passed (or their plural variants). nonrangeMatcher :: (IsRepoType rt, Matchable p) => [MatchFlag] -> Maybe (Matcher rt p) nonrangeMatcherArgs :: Matchable p => [MatchFlag] -> Maybe (Matcher rt p) nonrangeMatcher fs = addInternalMatcher $ nonrangeMatcherArgs fs nonrangeMatcherArgs [] = Nothing nonrangeMatcherArgs (OnePattern m:_) = strictJust $ matchPattern m nonrangeMatcherArgs (OneTag t:_) = strictJust $ tagmatch t nonrangeMatcherArgs (OnePatch p:_) = strictJust $ patchmatch p nonrangeMatcherArgs (OneHash h:_) = strictJust $ hashmatch' h nonrangeMatcherArgs (SeveralPattern m:_) = strictJust $ matchPattern m nonrangeMatcherArgs (SeveralPatch p:_) = strictJust $ patchmatch p nonrangeMatcherArgs (_:fs) = nonrangeMatcherArgs fs -- | @nonrangeMatcherIsTag@ returns true if the matching option was -- '--tag' nonrangeMatcherIsTag :: [MatchFlag] -> Bool nonrangeMatcherIsTag [] = False nonrangeMatcherIsTag (OneTag _:_) = True nonrangeMatcherIsTag (_:fs) = nonrangeMatcherIsTag fs -- | @firstMatcher@ returns the left bound of the matched interval. -- This left bound is also specified when we use the singular versions -- of @--patch@, @--match@ and @--tag@. Otherwise, @firstMatcher@ -- returns @Nothing@. firstMatcher :: Matchable p => [MatchFlag] -> Maybe (Matcher rt p) firstMatcher [] = Nothing firstMatcher (OnePattern m:_) = strictJust $ matchPattern m firstMatcher (AfterPattern m:_) = strictJust $ matchPattern m firstMatcher (AfterTag t:_) = strictJust $ tagmatch t firstMatcher (OnePatch p:_) = strictJust $ patchmatch p firstMatcher (AfterPatch p:_) = strictJust $ patchmatch p firstMatcher (OneHash h:_) = strictJust $ hashmatch' h firstMatcher (AfterHash h:_) = strictJust $ hashmatch' h firstMatcher (_:fs) = firstMatcher fs firstMatcherIsTag :: [MatchFlag] -> Bool firstMatcherIsTag [] = False firstMatcherIsTag (AfterTag _:_) = True firstMatcherIsTag (_:fs) = firstMatcherIsTag fs secondMatcher :: Matchable p => [MatchFlag] -> Maybe (Matcher rt p) secondMatcher [] = Nothing secondMatcher (OnePattern m:_) = strictJust $ matchPattern m secondMatcher (UpToPattern m:_) = strictJust $ matchPattern m secondMatcher (OnePatch p:_) = strictJust $ patchmatch p secondMatcher (UpToPatch p:_) = strictJust $ patchmatch p secondMatcher (OneHash h:_) = strictJust $ hashmatch' h secondMatcher (UpToHash h:_) = strictJust $ hashmatch' h secondMatcher (UpToTag t:_) = strictJust $ tagmatch t secondMatcher (_:fs) = secondMatcher fs secondMatcherIsTag :: [MatchFlag] -> Bool secondMatcherIsTag [] = False secondMatcherIsTag (UpToTag _:_) = True secondMatcherIsTag (_:fs) = secondMatcherIsTag fs -- | @matchAPatch fs p@ tells whether @p@ matches the matchers in -- the flags @fs@ matchAPatch :: (IsRepoType rt, Matchable p) => [MatchFlag] -> PatchInfoAnd rt p wX wY -> Bool matchAPatch fs p = case nonrangeMatcher fs of Nothing -> True Just m -> applyMatcher m p matchPatch :: (IsRepoType rt, Matchable p) => [MatchFlag] -> PatchSet rt p wStart wX -> Sealed2 (WrappedNamed rt p) matchPatch fs ps = case hasIndexRange fs of Just (a,a') | a == a' -> case unseal myhead $ dropn (a-1) ps of Just (Sealed2 p) -> seal2 $ hopefully p Nothing -> error "Patch out of range!" | otherwise -> bug ("Invalid index range match given to matchPatch: "++ show (PatchIndexRange a a')) where myhead :: PatchSet rt p wStart wX -> Maybe (Sealed2 (PatchInfoAnd rt p)) myhead (PatchSet (_ :<: Tagged t _ _) NilRL) = Just $ seal2 t myhead (PatchSet _ (_:<:x)) = Just $ seal2 x myhead _ = Nothing Nothing -> case nonrangeMatcher fs of Nothing -> bug "Couldn't matchPatch" Just m -> findAPatch m ps -- | @hasLastn fs@ return the @--last@ argument in @fs@, if any. hasLastn :: [MatchFlag] -> Maybe Int hasLastn [] = Nothing hasLastn (LastN (-1):_) = error "--last requires a positive integer argument." hasLastn (LastN n:_) = Just n hasLastn (_:fs) = hasLastn fs hasIndexRange :: [MatchFlag] -> Maybe (Int,Int) hasIndexRange [] = Nothing hasIndexRange (PatchIndexRange x y:_) = Just (x,y) hasIndexRange (_:fs) = hasIndexRange fs -- | @matchFirstPatchset fs ps@ returns the part of @ps@ before its -- first matcher, ie the one that comes first dependencywise. Hence, -- patches in @matchFirstPatchset fs ps@ are the context for the ones -- we don't want. matchFirstPatchset :: (IsRepoType rt, Matchable p) => [MatchFlag] -> PatchSet rt p wStart wX -> SealedPatchSet rt p wStart matchFirstPatchset fs patchset = case hasLastn fs of Just n -> dropn n patchset Nothing -> case hasIndexRange fs of Just (_,b) -> dropn b patchset Nothing -> case firstMatcher fs of Nothing -> bug "Couldn't matchFirstPatchset" Just m -> unseal (dropn 1) $ if firstMatcherIsTag fs then getMatchingTag m patchset else matchAPatchset m patchset -- | @dropn n ps@ drops the @n@ last patches from @ps@. dropn :: IsRepoType rt => Int -> PatchSet rt p wStart wX -> SealedPatchSet rt p wStart dropn n ps | n <= 0 = seal ps dropn n (PatchSet (ts :<: Tagged t _ ps) NilRL) = dropn n $ PatchSet ts (ps:<:t) dropn _ (PatchSet NilRL NilRL) = seal $ PatchSet NilRL NilRL dropn n (PatchSet ts (ps:<:p)) | isIsEq (namedIsInternal (hopefully p)) = dropn n $ PatchSet ts ps dropn n (PatchSet ts (ps:<:_)) = dropn (n-1) $ PatchSet ts ps -- | @matchSecondPatchset fs ps@ returns the part of @ps@ before its -- second matcher, ie the one that comes last dependencywise. matchSecondPatchset :: (IsRepoType rt, Matchable p) => [MatchFlag] -> PatchSet rt p wStart wX -> SealedPatchSet rt p wStart matchSecondPatchset fs ps = case hasIndexRange fs of Just (a,_) -> dropn (a-1) ps Nothing -> case secondMatcher fs of Nothing -> bug "Couldn't matchSecondPatchset" Just m -> if secondMatcherIsTag fs then getMatchingTag m ps else matchAPatchset m ps -- | Split on the second matcher. Note that this picks up the first match starting from -- the earliest patch in a sequence, as opposed to 'matchSecondPatchset' which picks up the -- first match starting from the latest patch splitSecondFL :: Matchable p => (forall wA wB . q wA wB -> Sealed2 (PatchInfoAnd rt p)) -> [MatchFlag] -> FL q wX wY -> (FL q :> FL q) wX wY -- ^The first element is the patches before and including the first patch matching the second matcher, -- the second element is the patches after it splitSecondFL extract fs ps = case hasIndexRange fs of Just _ -> -- selecting the last n doesn't really make sense if we're starting from the earliest patches bug "index matches not supported by splitSecondPatchesFL" Nothing -> case secondMatcher fs of Nothing -> bug "Couldn't splitSecondPatches" Just m -> splitMatchFL extract m ps -- | @findAPatch m ps@ returns the last patch in @ps@ matching @m@, and -- calls 'error' if there is none. findAPatch :: Matchable p => Matcher rt p -> PatchSet rt p wStart wX -> Sealed2 (WrappedNamed rt p) findAPatch m (PatchSet NilRL NilRL) = error $ "Couldn't find patch matching " ++ show m findAPatch m (PatchSet (ts :<: Tagged t _ ps) NilRL) = findAPatch m (PatchSet ts (ps:<:t)) findAPatch m (PatchSet ts (ps:<:p)) | applyMatcher m p = seal2 $ hopefully p | otherwise = findAPatch m (PatchSet ts ps) -- | @matchAPatchset m ps@ returns a prefix of @ps@ -- ending in a patch matching @m@, and calls 'error' if there is none. matchAPatchset :: Matchable p => Matcher rt p -> PatchSet rt p wStart wX -> SealedPatchSet rt p wStart matchAPatchset m (PatchSet NilRL NilRL) = error $ "Couldn't find patch matching " ++ show m matchAPatchset m (PatchSet (ts :<: Tagged t _ ps) NilRL) = matchAPatchset m (PatchSet ts (ps:<:t)) matchAPatchset m (PatchSet ts (ps:<:p)) | applyMatcher m p = seal (PatchSet ts (ps:<:p)) | otherwise = matchAPatchset m (PatchSet ts ps) -- | @getMatchingTag m ps@, where @m@ is a 'Matcher' which matches tags -- returns a 'SealedPatchSet' containing all patches in the last tag which -- matches @m@. Last tag means the most recent tag in repository order, -- i.e. the last one you'd see if you ran darcs log -t @m@. Calls -- 'error' if there is no matching tag. getMatchingTag :: Matchable p => Matcher rt p -> PatchSet rt p wStart wX -> SealedPatchSet rt p wStart getMatchingTag m (PatchSet NilRL NilRL) = error $ "Couldn't find a tag matching " ++ show m getMatchingTag m (PatchSet (ts :<: Tagged t _ ps) NilRL) = getMatchingTag m (PatchSet ts (ps:<:t)) getMatchingTag m (PatchSet ts (ps:<:p)) | applyMatcher m p = -- found a non-clean tag, need to commute out the things that it doesn't depend on case splitOnTag (info p) (PatchSet ts (ps:<:p)) of Nothing -> bug "splitOnTag couldn't find tag we explicitly provided!" Just (patchSet :> _) -> seal patchSet | otherwise = getMatchingTag m (PatchSet ts ps) splitMatchFL :: Matchable p => (forall wA wB . q wA wB -> Sealed2 (PatchInfoAnd rt p)) -> Matcher rt p -> FL q wX wY -> (FL q :> FL q) wX wY splitMatchFL _extract m NilFL = error $ "Couldn't find patch matching " ++ show m splitMatchFL extract m (p :>: ps) | unseal2 (applyMatcher m) . extract $ p = (p :>: NilFL) :> ps | otherwise = case splitMatchFL extract m ps of before :> after -> (p :>: before) :> after -- | @matchExists m ps@ tells whether there is a patch matching -- @m@ in @ps@ matchExists :: Matcher rt p -> PatchSet rt p wStart wX -> Bool matchExists _ (PatchSet NilRL NilRL) = False matchExists m (PatchSet (ts :<: Tagged t _ ps) NilRL) = matchExists m (PatchSet ts (ps:<:t)) matchExists m (PatchSet ts (ps:<:p)) | applyMatcher m p = True | otherwise = matchExists m (PatchSet ts ps) applyInvToMatcher :: (Matchable p, ApplyMonad (ApplyState p) m) => InclusiveOrExclusive -> Matcher rt p -> PatchSet rt p Origin wX -> m () applyInvToMatcher _ _ (PatchSet NilRL NilRL) = impossible applyInvToMatcher ioe m (PatchSet (ts :<: Tagged t _ ps) NilRL) = applyInvToMatcher ioe m (PatchSet ts (ps:<:t)) applyInvToMatcher ioe m (PatchSet xs (ps:<:p)) | applyMatcher m p = when (ioe == Inclusive) (applyInvp p) | otherwise = applyInvp p >> applyInvToMatcher ioe m (PatchSet xs ps) -- | @applyNInv@ n ps applies the inverse of the last @n@ patches of @ps@. applyNInv :: (Matchable p, ApplyMonad (ApplyState p) m) => Int -> PatchSet rt p Origin wX -> m () applyNInv n _ | n <= 0 = return () applyNInv _ (PatchSet NilRL NilRL) = error "Index out of range." applyNInv n (PatchSet (ts :<: Tagged t _ ps) NilRL) = applyNInv n (PatchSet ts (ps :<: t)) applyNInv n (PatchSet xs (ps :<: p)) = applyInvp p >> applyNInv (n - 1) (PatchSet xs ps) getMatcherS :: (ApplyMonad (ApplyState p) m, Matchable p) => InclusiveOrExclusive -> Matcher rt p -> PatchSet rt p Origin wX -> m () getMatcherS ioe m repo = if matchExists m repo then applyInvToMatcher ioe m repo else throw $ userError $ "Couldn't match pattern "++ show m getTagS :: (ApplyMonad (ApplyState p) m, MonadProgress m, Matchable p) => Matcher rt p -> PatchSet rt p Origin wX -> m () getTagS matcher repo = do let pinfo = patch2patchinfo `unseal2` findAPatch matcher repo case getPatchesBeyondTag pinfo repo of FlippedSeal extras -> applyInvRL extras -- | @applyInvp@ tries to get the patch that's in a 'PatchInfoAnd -- patch', and to apply its inverse. If we fail to fetch the patch -- then we share our sorrow with the user. applyInvp :: (Apply p, Invert p, ApplyMonad (ApplyState p) m) => PatchInfoAnd rt p wX wY -> m () applyInvp hp = apply (invert $ fromHopefully hp) where fromHopefully = conscientiously $ \e -> text "Sorry, patch not available:" $$ e $$ text "" $$ text "If you think what you're trying to do is ok then" $$ text "report this as a bug on the darcs-user list." -- | a version of 'take' for 'RL' lists that cater for contexts. safetake :: IsRepoType rt => Int -> RL (PatchInfoAnd rt p) wX wY -> FlippedSeal (RL (PatchInfoAnd rt p)) wY safetake 0 _ = flipSeal NilRL safetake _ NilRL = error "There aren't that many patches..." safetake i (as:<:a) | isIsEq (namedIsInternal (hopefully a)) = safetake i as `snocRLSealed` a safetake i (as:<:a) = safetake (i-1) as `snocRLSealed` a applyInvRL :: (Apply p, Invert p, ApplyMonad (ApplyState p) m, MonadProgress m) => RL (PatchInfoAnd rt p) wX wR -> m () applyInvRL = applyPatches . invertRL -- this gives nicer feedback darcs-2.14.5/src/Darcs/Patch/Matchable.hs0000644000000000000000000000053107346545000016165 0ustar0000000000000000-- Copyright (C) 2013 Ganesh Sittampalam -- -- BSD3 module Darcs.Patch.Matchable ( Matchable ) where import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Invert ( Invert(..) ) class (Apply p, Commute p, Invert p, PatchInspect p) => Matchable p darcs-2.14.5/src/Darcs/Patch/Merge.hs0000644000000000000000000000557707346545000015363 0ustar0000000000000000-- | -- Module : Darcs.Patch.Merge -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.Patch.Merge ( -- * Definitions Merge(..) , selfMerger , mergeFL , naturalMerge -- * Properties , prop_mergeSymmetric , prop_mergeCommute ) where import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.CommuteFn ( MergeFn ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Witnesses.Eq ( Eq2(..), isIsEq ) import Darcs.Patch.Witnesses.Ordered ( (:\/:)(..) , (:/\:)(..) , FL(..) , RL , (:>)(..) , reverseFL , reverseRL ) -- | Things that can always be merged. -- -- Instances should obey the following laws: -- -- * Symmetry -- -- prop> merge (p :\/: q) == q' :/\: p' <=> merge (q :\/: p) == p' :/\: q' -- -- * MergesCommute -- -- prop> merge (p :\/: q) == q' :/\: p' ==> commute (p :> q') == Just (q :> p') -- -- that is, the two branches of a merge commute to each other class Commute p => Merge p where merge :: (p :\/: p) wX wY -> (p :/\: p) wX wY selfMerger :: Merge p => MergeFn p p selfMerger = merge instance Merge p => Merge (FL p) where merge (NilFL :\/: x) = x :/\: NilFL merge (x :\/: NilFL) = NilFL :/\: x merge ((x:>:xs) :\/: ys) = case mergeFL (x :\/: ys) of ys' :/\: x' -> case merge (ys' :\/: xs) of xs' :/\: ys'' -> ys'' :/\: (x' :>: xs') instance Merge p => Merge (RL p) where merge (x :\/: y) = case merge (reverseRL x :\/: reverseRL y) of (ry' :/\: rx') -> reverseFL ry' :/\: reverseFL rx' mergeFL :: Merge p => (p :\/: FL p) wX wY -> (FL p :/\: p) wX wY mergeFL (p :\/: NilFL) = NilFL :/\: p mergeFL (p :\/: (x :>: xs)) = case merge (p :\/: x) of x' :/\: p' -> case mergeFL (p' :\/: xs) of xs' :/\: p'' -> (x' :>: xs') :/\: p'' -- | The natural, non-conflicting merge. naturalMerge :: (Invert p, Commute p) => (p :\/: p) wX wY -> Maybe ((p :/\: p) wX wY) naturalMerge (p :\/: q) = do q' :> ip' <- commute (invert p :> q) -- TODO: find a small convincing example that demonstrates why -- it is necessary to do this extra check here _ <- commute (p :> q') return (q' :/\: invert ip') prop_mergeSymmetric :: (Eq2 p, Merge p) => (p :\/: p) wX wY -> Bool prop_mergeSymmetric (p :\/: q) = case merge (p :\/: q) of q' :/\: p' -> case merge (q :\/: p) of p'' :/\: q'' -> isIsEq (q' =\/= q'') && isIsEq (p' =\/= p'') prop_mergeCommute :: (Eq2 p, Merge p) => (p :\/: p) wX wY -> Bool prop_mergeCommute (p :\/: q) = case merge (p :\/: q) of q' :/\: p' -> case commute (p :> q') of Nothing -> False Just (q'' :> p'') -> isIsEq (q'' =\/= q) && isIsEq (p'' =/\= p') && case commute (q :> p') of Nothing -> False Just (p'' :> q'') -> isIsEq (p'' =\/= p) && isIsEq (q'' =/\= q') darcs-2.14.5/src/Darcs/Patch/MonadProgress.hs0000644000000000000000000000462507346545000017100 0ustar0000000000000000{-# LANGUAGE TypeSynonymInstances #-} -- Copyright (C) 2011 Ganesh Sittampalam -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. module Darcs.Patch.MonadProgress ( MonadProgress(..) , ProgressAction(..) , silentlyRunProgressActions ) where import Prelude () import Darcs.Prelude import Darcs.Util.Printer ( Doc ) import Darcs.Util.Printer.Color () -- for instance Show Doc import qualified Darcs.Util.Tree.Monad as TM -- |a monadic action, annotated with a progress message that could be printed out -- while running the action, and a message that could be printed out on error. -- Actually printing out these messages is optional to allow non-IO monads to -- just run the action. data ProgressAction m a = ProgressAction {paAction :: m a ,paMessage :: Doc ,paOnError :: Doc } class Monad m => MonadProgress m where -- |run a list of 'ProgressAction's. In some monads (typically IO-based ones), -- the progress and error messages will be used. In others they will be -- ignored and just the actions will be run. runProgressActions :: String -> [ProgressAction m ()] -> m () -- |run a list of 'ProgressAction's without any feedback messages silentlyRunProgressActions :: Monad m => String -> [ProgressAction m ()] -> m () silentlyRunProgressActions _ = mapM_ paAction instance (Monad m) => MonadProgress (TM.TreeMonad m) where runProgressActions = silentlyRunProgressActions darcs-2.14.5/src/Darcs/Patch/Named.hs0000644000000000000000000002455307346545000015343 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.Named ( Named(..), infopatch, adddeps, namepatch, anonymous, getdeps, patch2patchinfo, patchname, patchcontents, fmapNamed, fmapFL_Named, commuterIdNamed, commuterNamedId, mergerIdNamed ) where import Prelude () import Darcs.Prelude import Prelude hiding ( pi ) import Darcs.Patch.CommuteFn ( CommuteFn, commuterIdFL, commuterFLId , MergeFn, mergerIdFL ) import Darcs.Patch.Conflict ( Conflict(..), CommuteNoConflicts ) import Darcs.Patch.Debug ( PatchDebug(..) ) import Darcs.Patch.Effect ( Effect(effect, effectRL) ) import Darcs.Patch.FileHunk ( IsHunk(..) ) import Darcs.Patch.Format ( PatchListFormat ) import Darcs.Patch.Info ( PatchInfo, readPatchInfo, showPatchInfo, patchinfo, piName, displayPatchInfo, makePatchname, invertName ) import Darcs.Patch.Merge ( Merge(..) ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.Prim ( PrimPatchBase(..) ) import Darcs.Patch.ReadMonads ( ParserM, option, lexChar, choice, skipWhile, anyChar ) import Darcs.Patch.Repair ( mapMaybeSnd, Repair(..), RepairToFL, Check(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..), ShowPatch(..), ShowContextPatch(..), ShowPatchFor(..) ) import Darcs.Patch.Summary ( plainSummary ) import Darcs.Patch.Viewing () -- for ShowPatch FL instances import Darcs.Patch.Witnesses.Eq ( Eq2(..) ) import Darcs.Patch.Witnesses.Ordered ( (:>)(..), (:\/:)(..), (:/\:)(..), FL, mapFL, mapFL_FL ) import Darcs.Patch.Witnesses.Sealed ( Sealed, mapSeal ) import Darcs.Patch.Witnesses.Show ( ShowDict(..), Show1(..), Show2(..) ) import Darcs.Util.Printer ( Doc, ($$), (<+>), prefix, text, vcat, cyanText, blueText ) -- | The @Named@ type adds a patch info about a patch, that is a name. data Named p wX wY where NamedP :: !PatchInfo -> ![PatchInfo] -> !(FL p wX wY) -> Named p wX wY deriving Show -- ^ @NamedP info deps p@ represents patch @p@ with name -- @info@. @deps@ is a list of dependencies added at the named patch -- level, compared with the unnamed level (ie, dependencies added with -- @darcs record --ask-deps@). instance PrimPatchBase p => PrimPatchBase (Named p) where type PrimOf (Named p) = PrimOf p instance Effect p => Effect (Named p) where effect (NamedP _ _ p) = effect p effectRL (NamedP _ _ p) = effectRL p instance IsHunk (Named p) where isHunk _ = Nothing instance PatchListFormat (Named p) instance (ReadPatch p, PatchListFormat p) => ReadPatch (Named p) where readPatch' = readNamed readNamed :: (ReadPatch p, PatchListFormat p, ParserM m) => m (Sealed (Named p wX)) readNamed = do n <- readPatchInfo d <- readDepends p <- readPatch' return $ (NamedP n d) `mapSeal` p readDepends :: ParserM m => m [PatchInfo] readDepends = option [] $ do lexChar '<' readPis readPis :: ParserM m => m [PatchInfo] readPis = choice [ do pi <- readPatchInfo pis <- readPis return (pi:pis) , do skipWhile (/= '>') _ <- anyChar return [] ] instance Apply p => Apply (Named p) where type ApplyState (Named p) = ApplyState p apply (NamedP _ _ p) = apply p instance RepairToFL p => Repair (Named p) where applyAndTryToFix (NamedP n d p) = mapMaybeSnd (NamedP n d) `fmap` applyAndTryToFix p namepatch :: String -> String -> String -> [String] -> FL p wX wY -> IO (Named p wX wY) namepatch date name author desc p | '\n' `elem` name = error "Patch names cannot contain newlines." | otherwise = do pinf <- patchinfo date name author desc return $ NamedP pinf [] p anonymous :: FL p wX wY -> IO (Named p wX wY) anonymous p = namepatch "today" "anonymous" "unknown" ["anonymous"] p infopatch :: PatchInfo -> FL p wX wY -> Named p wX wY infopatch pi p = NamedP pi [] p adddeps :: Named p wX wY -> [PatchInfo] -> Named p wX wY adddeps (NamedP pi _ p) ds = NamedP pi ds p getdeps :: Named p wX wY -> [PatchInfo] getdeps (NamedP _ ds _) = ds patch2patchinfo :: Named p wX wY -> PatchInfo patch2patchinfo (NamedP i _ _) = i patchname :: Named p wX wY -> String patchname (NamedP i _ _) = show $ makePatchname i patchcontents :: Named p wX wY -> FL p wX wY patchcontents (NamedP _ _ p) = p fmapNamed :: (forall wA wB . p wA wB -> q wA wB) -> Named p wX wY -> Named q wX wY fmapNamed f (NamedP i deps p) = NamedP i deps (mapFL_FL f p) fmapFL_Named :: (FL p wA wB -> FL q wC wD) -> Named p wA wB -> Named q wC wD fmapFL_Named f (NamedP i deps p) = NamedP i deps (f p) instance (Commute p, Eq2 p) => Eq2 (Named p) where unsafeCompare (NamedP n1 d1 p1) (NamedP n2 d2 p2) = n1 == n2 && d1 == d2 && unsafeCompare p1 p2 instance Invert p => Invert (Named p) where invert (NamedP n d p) = NamedP (invertName n) (map invertName d) (invert p) instance Commute p => Commute (Named p) where commute (NamedP n1 d1 p1 :> NamedP n2 d2 p2) = if n2 `elem` d1 || n1 `elem` d2 then Nothing else do (p2' :> p1') <- commute (p1 :> p2) return (NamedP n2 d2 p2' :> NamedP n1 d1 p1') commuterIdNamed :: CommuteFn p1 p2 -> CommuteFn p1 (Named p2) commuterIdNamed commuter (p1 :> NamedP n2 d2 p2) = do p2' :> p1' <- commuterIdFL commuter (p1 :> p2) return (NamedP n2 d2 p2' :> p1') commuterNamedId :: CommuteFn p1 p2 -> CommuteFn (Named p1) p2 commuterNamedId commuter (NamedP n1 d1 p1 :> p2) = do p2' :> p1' <- commuterFLId commuter (p1 :> p2) return (p2' :> NamedP n1 d1 p1') instance Merge p => Merge (Named p) where merge (NamedP n1 d1 p1 :\/: NamedP n2 d2 p2) = case merge (p1 :\/: p2) of (p2' :/\: p1') -> NamedP n2 d2 p2' :/\: NamedP n1 d1 p1' mergerIdNamed :: MergeFn p1 p2 -> MergeFn p1 (Named p2) mergerIdNamed merger (p1 :\/: NamedP n2 d2 p2) = case mergerIdFL merger (p1 :\/: p2) of p2' :/\: p1' -> NamedP n2 d2 p2' :/\: p1' instance PatchInspect p => PatchInspect (Named p) where listTouchedFiles (NamedP _ _ p) = listTouchedFiles p hunkMatches f (NamedP _ _ p) = hunkMatches f p instance (CommuteNoConflicts p, Conflict p) => Conflict (Named p) where resolveConflicts (NamedP _ _ p) = resolveConflicts p conflictedEffect (NamedP _ _ p) = conflictedEffect p instance Check p => Check (Named p) where isInconsistent (NamedP _ _ p) = isInconsistent p -- ForStorage: note the difference between use of <> when there are -- no explicit dependencies vs. <+> when there are showNamedPrefix :: ShowPatchFor -> PatchInfo -> [PatchInfo] -> Doc -> Doc showNamedPrefix f@ForStorage n [] p = showPatchInfo f n <> p showNamedPrefix f@ForStorage n d p = showPatchInfo f n $$ blueText "<" $$ vcat (map (showPatchInfo f) d) $$ blueText ">" <+> p showNamedPrefix f@ForDisplay n [] p = showPatchInfo f n $$ p showNamedPrefix f@ForDisplay n d p = showPatchInfo f n $$ showDependencies ShowDepsVerbose d $$ p data ShowDepsFormat = ShowDepsVerbose | ShowDepsSummary deriving (Eq) showDependencies :: ShowDepsFormat -> [PatchInfo] -> Doc showDependencies format deps = vcat (map showDependency deps) where showDependency d = mark <+> cyanText "patch" <+> cyanText (show (makePatchname d)) $$ asterisk <+> text (piName d) mark | format == ShowDepsVerbose = blueText "depend" | otherwise = text "D" asterisk | format == ShowDepsVerbose = text "*" | otherwise = text " *" instance (PatchListFormat p, ShowPatchBasic p) => ShowPatchBasic (Named p) where showPatch f (NamedP n d p) = showNamedPrefix f n d $ showPatch f p instance (Apply p, IsHunk p, PatchListFormat p, ShowContextPatch p) => ShowContextPatch (Named p) where showContextPatch f (NamedP n d p) = showNamedPrefix f n d <$> showContextPatch f p instance (CommuteNoConflicts p, Conflict p, PatchListFormat p, PrimPatchBase p, ShowPatch p) => ShowPatch (Named p) where description (NamedP n _ _) = displayPatchInfo n summary p@(NamedP _ ds _) = let indent = prefix " " deps | ds == [] = text "" | otherwise = text "" $$ indent (showDependencies ShowDepsSummary ds) in description p $$ deps $$ indent (plainSummary p) -- this isn't summary because summary -- does the wrong thing with -- (Named (FL p)) so that it can get -- the summary of a sequence of named -- patches right. summaryFL = vcat . mapFL summary showNicely p@(NamedP _ ds pt) = let indent = prefix " " deps | ds == [] = text "" | otherwise = text "" $$ indent (showDependencies ShowDepsVerbose ds) in description p <> deps $$ indent (showNicely pt) instance Show2 p => Show1 (Named p wX) where showDict1 = ShowDictClass instance Show2 p => Show2 (Named p) where showDict2 = ShowDictClass instance PatchDebug p => PatchDebug (Named p) darcs-2.14.5/src/Darcs/Patch/Named/0000755000000000000000000000000007346545000014776 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/Named/Wrapped.hs0000644000000000000000000003365507346545000016750 0ustar0000000000000000{-# LANGUAGE StandaloneDeriving, TypeOperators #-} module Darcs.Patch.Named.Wrapped ( WrappedNamed(..) , patch2patchinfo, activecontents , infopatch, namepatch, anonymous , getdeps, adddeps , mkRebase, toRebasing, fromRebasing , runInternalChecker, namedInternalChecker, namedIsInternal, removeInternalFL , fmapFL_WrappedNamed, (:~:)(..), (:~~:)(..) , generaliseRepoTypeWrapped ) where import Prelude () import Darcs.Prelude import Data.Coerce ( coerce ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Conflict ( Conflict(..), CommuteNoConflicts(..) ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.FileHunk ( IsHunk(..) ) import Darcs.Patch.Format ( PatchListFormat(..), ListFormat ) import Darcs.Patch.Info ( PatchInfo, showPatchInfo, displayPatchInfo, patchinfo ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Named ( Named(..), fmapFL_Named ) import qualified Darcs.Patch.Named as Base ( patch2patchinfo, patchcontents , infopatch, namepatch, anonymous , getdeps, adddeps ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Merge ( Merge(..) ) import Darcs.Patch.Prim ( FromPrim ) import Darcs.Patch.Prim.Class ( PrimPatchBase(..) ) import Darcs.Patch.Read ( ReadPatch(..) ) import qualified Darcs.Patch.Rebase.Container as Rebase ( Suspended(..) , addFixupsToSuspended, removeFixupsFromSuspended ) import Darcs.Patch.Repair ( mapMaybeSnd, Repair(..), RepairToFL(..), Check(..) ) import Darcs.Patch.RepoType ( RepoType(..), IsRepoType(..), SRepoType(..) , RebaseType(..), RebaseTypeOf, SRebaseType(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..), ShowPatch(..), ShowContextPatch(..), ShowPatchFor(..) ) import Darcs.Patch.Witnesses.Eq ( EqCheck(..) ) import Darcs.Patch.Witnesses.Sealed ( mapSeal ) import Darcs.Patch.Witnesses.Show ( ShowDict(..), Show1(..), Show2(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), mapFL_FL, mapFL, (:>)(..) , (:\/:)(..), (:/\:)(..) ) import Darcs.Util.IsoDate ( getIsoDateTime ) import Darcs.Util.Text ( formatParas ) import Darcs.Util.Printer ( ($$), vcat, prefix ) import Control.Applicative ( (<|>) ) -- |A layer inbetween the 'Named p' type and 'PatchInfoAnd p' -- design for holding "internal" patches such as the rebase -- container. Ideally these patches would be stored at the -- repository level but this would require some significant -- refactoring/cleaning up of that code. data WrappedNamed (rt :: RepoType) p wX wY where NormalP :: !(Named p wX wY) -> WrappedNamed rt p wX wY RebaseP :: (PrimPatchBase p, FromPrim p, Effect p) => !PatchInfo -- TODO: this should always be the "internal implementation detail" rebase -- patch description, so could be replaced by just the Ignore-this and Date fields -> !(Rebase.Suspended p wX wX) -> WrappedNamed ('RepoType 'IsRebase) p wX wX deriving instance Show2 p => Show (WrappedNamed rt p wX wY) instance Show2 p => Show1 (WrappedNamed rt p wX) where showDict1 = ShowDictClass instance Show2 p => Show2 (WrappedNamed rt p) where showDict2 = ShowDictClass -- TODO use Data.Type.Equality and PolyKinds from GHC 7.8/base 4.7 data (a :: * -> * -> *) :~: b where ReflPatch :: a :~: a data (a :: RebaseType) :~~: b where ReflRebaseType :: a :~~: a -- |lift a function over an 'FL' of patches to one over -- a 'WrappedNamed rt'. -- The function is only applied to "normal" patches, -- and any rebase container patch is left alone. fmapFL_WrappedNamed :: (FL p wA wB -> FL q wA wB) -> (RebaseTypeOf rt :~~: 'IsRebase -> p :~: q) -- ^If the patch might be a rebase container patch, -- then 'p' and 'q' must be the same type, as no -- transformation is applied. This function provides -- a witness to this requirement: if 'RebaseTypeOf rt' -- might be 'IsRebase', then it must be able to return -- a proof that 'p' and 'q' are equal. If 'RebaseTypeOf rt' -- must be 'NoRebase', then this function can never be called -- with a valid value. -> WrappedNamed rt p wA wB -> WrappedNamed rt q wA wB fmapFL_WrappedNamed f _ (NormalP n) = NormalP (fmapFL_Named f n) fmapFL_WrappedNamed _ whenRebase (RebaseP n s) = case whenRebase ReflRebaseType of ReflPatch -> RebaseP n s patch2patchinfo :: WrappedNamed rt p wX wY -> PatchInfo patch2patchinfo (NormalP p) = Base.patch2patchinfo p patch2patchinfo (RebaseP name _) = name namepatch :: String -> String -> String -> [String] -> FL p wX wY -> IO (WrappedNamed rt p wX wY) namepatch date name author desc p = fmap NormalP (Base.namepatch date name author desc p) anonymous :: FL p wX wY -> IO (WrappedNamed rt p wX wY) anonymous p = fmap NormalP (Base.anonymous p) infopatch :: PatchInfo -> FL p wX wY -> WrappedNamed rt p wX wY infopatch i ps = NormalP (Base.infopatch i ps) -- |Return a list of the underlying patches that are actually -- 'active' in the repository, i.e. not suspended as part of a rebase activecontents :: WrappedNamed rt p wX wY -> FL p wX wY activecontents (NormalP p) = Base.patchcontents p activecontents (RebaseP {}) = NilFL adddeps :: WrappedNamed rt p wX wY -> [PatchInfo] -> WrappedNamed rt p wX wY adddeps (NormalP n) pis = NormalP (Base.adddeps n pis) adddeps (RebaseP {}) _ = error "Internal error: can't add dependencies to a rebase internal patch" getdeps :: WrappedNamed rt p wX wY -> [PatchInfo] getdeps (NormalP n) = Base.getdeps n getdeps (RebaseP {}) = [] mkRebase :: (PrimPatchBase p, FromPrim p, Effect p) => Rebase.Suspended p wX wX -> IO (WrappedNamed ('RepoType 'IsRebase) p wX wX) mkRebase s = do let name = "DO NOT TOUCH: Rebase patch" let desc = formatParas 72 ["This patch is an internal implementation detail of rebase, used to store suspended patches, " ++ "and should not be visible in the user interface. Please report a bug if a darcs " ++ "command is showing you this patch."] date <- getIsoDateTime let author = "Invalid " info <- patchinfo date name author desc return $ RebaseP info s toRebasing :: Named p wX wY -> WrappedNamed ('RepoType 'IsRebase) p wX wY toRebasing n = NormalP n fromRebasing :: WrappedNamed ('RepoType 'IsRebase) p wX wY -> Named p wX wY fromRebasing (NormalP n) = n fromRebasing (RebaseP {}) = error "internal error: found rebasing internal patch" generaliseRepoTypeWrapped :: WrappedNamed ('RepoType 'NoRebase) p wA wB -> WrappedNamed rt p wA wB generaliseRepoTypeWrapped (NormalP p) = NormalP p -- Note: the EqCheck result could be replaced by a Bool if clients were changed to commute the patch -- out if necessary. newtype InternalChecker p = InternalChecker { runInternalChecker :: forall wX wY . p wX wY -> EqCheck wX wY } -- |Is the given 'WrappedNamed' patch an internal implementation detail -- that shouldn't be visible in the UI or included in tags/matchers etc? -- Two-level checker for efficiency: if the value of this is 'Nothing' for a given -- patch type then there's no need to inspect patches of this type at all, -- as none of them can be internal. namedInternalChecker :: forall rt p . IsRepoType rt => Maybe (InternalChecker (WrappedNamed rt p)) namedInternalChecker = case singletonRepoType :: SRepoType rt of SRepoType SNoRebase -> Nothing SRepoType SIsRebase -> let isInternal :: WrappedNamed rt p wX wY -> EqCheck wX wY isInternal (NormalP {}) = NotEq isInternal (RebaseP {}) = IsEq in Just (InternalChecker isInternal) -- |Is the given 'WrappedNamed' patch an internal implementation detail -- that shouldn't be visible in the UI or included in tags/matchers etc? namedIsInternal :: IsRepoType rt => WrappedNamed rt p wX wY -> EqCheck wX wY namedIsInternal = maybe (const NotEq) runInternalChecker namedInternalChecker removeInternalFL :: IsRepoType rt => FL (WrappedNamed rt p) wX wY -> FL (Named p) wX wY removeInternalFL NilFL = NilFL removeInternalFL (NormalP n :>: ps) = n :>: removeInternalFL ps removeInternalFL (RebaseP {} :>: ps) = removeInternalFL ps instance PrimPatchBase p => PrimPatchBase (WrappedNamed rt p) where type PrimOf (WrappedNamed rt p) = PrimOf p instance Invert p => Invert (WrappedNamed rt p) where invert (NormalP n) = NormalP (invert n) invert (RebaseP i s) = RebaseP i s -- TODO is this sensible? instance PatchListFormat (WrappedNamed rt p) instance IsHunk (WrappedNamed rt p) where isHunk _ = Nothing instance (ShowPatchBasic p, PatchListFormat p) => ShowPatchBasic (WrappedNamed rt p) where showPatch f (NormalP n) = showPatch f n showPatch f (RebaseP i s) = showPatchInfo f i <> showPatch f s instance ( ShowContextPatch p, PatchListFormat p, Apply p , PrimPatchBase p, IsHunk p ) => ShowContextPatch (WrappedNamed rt p) where showContextPatch f (NormalP n) = showContextPatch f n showContextPatch f@ForDisplay (RebaseP i s) = fmap (showPatchInfo f i $$) $ return (showPatch f s) showContextPatch f@ForStorage (RebaseP i s) = fmap (showPatchInfo f i <>) $ return (showPatch f s) instance ( ShowPatch p, PatchListFormat p, Apply p , PrimPatchBase p, IsHunk p, Conflict p, CommuteNoConflicts p ) => ShowPatch (WrappedNamed rt p) where description (NormalP n) = description n description (RebaseP i _) = displayPatchInfo i summary (NormalP n) = summary n summary (RebaseP i _) = displayPatchInfo i summaryFL = vcat . mapFL summary showNicely (NormalP n) = showNicely n showNicely (RebaseP i s) = displayPatchInfo i $$ prefix " " (showNicely s) instance PatchInspect p => PatchInspect (WrappedNamed rt p) where listTouchedFiles (NormalP n) = listTouchedFiles n listTouchedFiles (RebaseP _ s) = listTouchedFiles s hunkMatches f (NormalP n) = hunkMatches f n hunkMatches f (RebaseP _ s) = hunkMatches f s instance RepairToFL p => Repair (WrappedNamed rt p) where applyAndTryToFix (NormalP n) = fmap (mapMaybeSnd NormalP) $ applyAndTryToFix n applyAndTryToFix (RebaseP i s) = fmap (mapMaybeSnd (RebaseP i)) $ applyAndTryToFix s -- This is a local hack to maintain backwards compatibility with -- the on-disk format for rebases. Previously the rebase container -- was internally represented via a 'Rebasing' type that sat *inside* -- a 'Named', and so the rebase container patch had the structure -- 'NamedP i [] (Suspendended s :>: NilFL)'. This structure was reflected -- in the way it was saved on disk. -- The easiest to read this structure is to use an intermediate type -- that reflects the old structure. -- TODO: switch to a more natural on-disk structure that directly -- saves/reads 'RebaseP'. data ReadRebasing p wX wY where ReadNormal :: p wX wY -> ReadRebasing p wX wY ReadSuspended :: Rebase.Suspended p wX wX -> ReadRebasing p wX wX instance ( ReadPatch p, PrimPatchBase p, FromPrim p, Effect p, PatchListFormat p , IsRepoType rt ) => ReadPatch (WrappedNamed rt p) where readPatch' = case singletonRepoType :: SRepoType rt of SRepoType SIsRebase -> let wrapNamed :: Named (ReadRebasing p) wX wY -> WrappedNamed rt p wX wY wrapNamed (NamedP i [] (ReadSuspended s :>: NilFL)) = RebaseP i s wrapNamed (NamedP i deps ps) = NormalP (NamedP i deps (mapFL_FL unRead ps)) unRead (ReadNormal p) = p unRead (ReadSuspended _) = error "unexpected suspended patch" in fmap (mapSeal wrapNamed) readPatch' _ -> fmap (mapSeal NormalP) readPatch' instance PatchListFormat p => PatchListFormat (ReadRebasing p) where patchListFormat = coerce (patchListFormat :: ListFormat p) instance (ReadPatch p, PatchListFormat p, PrimPatchBase p) => ReadPatch (ReadRebasing p) where readPatch' = mapSeal toSuspended <$> readPatch' <|> mapSeal ReadNormal <$> readPatch' where -- needed to get a suitably polymorphic type toSuspended :: Rebase.Suspended p wX wY -> ReadRebasing p wX wY toSuspended (Rebase.Items ps) = ReadSuspended (Rebase.Items ps) instance (CommuteNoConflicts p, Conflict p) => Conflict (WrappedNamed rt p) where resolveConflicts (NormalP n) = resolveConflicts n resolveConflicts (RebaseP _ s) = resolveConflicts s conflictedEffect (NormalP n) = conflictedEffect n conflictedEffect (RebaseP _ s) = conflictedEffect s instance Check p => Check (WrappedNamed rt p) where isInconsistent (NormalP n) = isInconsistent n isInconsistent (RebaseP _ s) = isInconsistent s instance Apply p => Apply (WrappedNamed rt p) where type ApplyState (WrappedNamed rt p) = ApplyState p apply (NormalP n) = apply n apply (RebaseP _ s) = apply s instance Effect p => Effect (WrappedNamed rt p) where effect (NormalP n) = effect n effect (RebaseP _ s) = effect s effectRL (NormalP n) = effectRL n effectRL (RebaseP _ s) = effectRL s instance Commute p => Commute (WrappedNamed rt p) where commute (NormalP n1 :> NormalP n2) = do n2' :> n1' <- commute (n1 :> n2) return (NormalP n2' :> NormalP n1') commute (RebaseP i1 s1 :> RebaseP i2 s2) = -- Two rebases in sequence must have the same starting context, -- so they should trivially commute. -- This case shouldn't actually happen since each repo only has -- a single Suspended patch. return (RebaseP i2 s2 :> RebaseP i1 s1) commute (NormalP n1 :> RebaseP i2 s2) = return (RebaseP i2 (Rebase.addFixupsToSuspended n1 s2) :> NormalP n1) commute (RebaseP i1 s1 :> NormalP n2) = return (NormalP n2 :> RebaseP i1 (Rebase.removeFixupsFromSuspended n2 s1)) instance Merge p => Merge (WrappedNamed rt p) where merge (NormalP n1 :\/: NormalP n2) = case merge (n1 :\/: n2) of n2' :/\: n1' -> NormalP n2' :/\: NormalP n1' -- shouldn't happen as each repo only has a single Suspended patch merge (RebaseP i1 items1 :\/: RebaseP i2 items2) = RebaseP i2 items2 :/\: RebaseP i1 items1 merge (NormalP n1 :\/: RebaseP i2 s2) = RebaseP i2 (Rebase.removeFixupsFromSuspended n1 s2) :/\: NormalP n1 merge (RebaseP i1 s1 :\/: NormalP n2) = NormalP n2 :/\: RebaseP i1 (Rebase.removeFixupsFromSuspended n2 s1) darcs-2.14.5/src/Darcs/Patch/PatchInfoAnd.hs0000644000000000000000000002710707346545000016613 0ustar0000000000000000-- Copyright (C) 2006 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE CPP #-} module Darcs.Patch.PatchInfoAnd ( Hopefully(..), SimpleHopefully(..), PatchInfoAnd(..), WPatchInfo, unWPatchInfo, compareWPatchInfo, piap, n2pia, patchInfoAndPatch, fmapFLPIAP, generaliseRepoTypePIAP, conscientiously, hopefully, info, winfo, hopefullyM, createHashed, extractHash, actually, unavailable, patchDesc ) where import Prelude () import Darcs.Prelude import System.IO.Unsafe ( unsafeInterleaveIO ) import Darcs.Util.SignalHandler ( catchNonSignal ) import Darcs.Util.Printer ( Doc, renderString, errorDoc, text, ($$), vcat ) import Darcs.Patch.Info ( PatchInfo, showPatchInfo, displayPatchInfo, justName ) import Darcs.Patch.Conflict ( Conflict, CommuteNoConflicts ) import Darcs.Patch.Debug ( PatchDebug(..) ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.FileHunk ( IsHunk(..) ) import Darcs.Patch.Format ( PatchListFormat ) import Darcs.Patch.Merge ( Merge(..) ) import Darcs.Patch.Named.Wrapped ( WrappedNamed, patch2patchinfo, fmapFL_WrappedNamed, (:~:), (:~~:) , generaliseRepoTypeWrapped ) import Darcs.Patch.Prim ( PrimPatchBase(..), FromPrim ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.Show ( ShowPatch(..) ) import Darcs.Patch.Repair ( Repair(..), RepairToFL ) import Darcs.Patch.RepoType ( RepoType(..), IsRepoType, RebaseTypeOf, RebaseType(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..), ShowContextPatch(..) ) import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Patch.Witnesses.Ordered ( (:>)(..), (:\/:)(..), (:/\:)(..), FL, mapFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), seal, mapSeal ) import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..), ShowDict(ShowDictClass) ) import Darcs.Util.Exception ( prettyException ) import Darcs.Util.Tree( Tree ) -- | @'Hopefully' p C@ @(x y)@ is @'Either' String (p C@ @(x y))@ in a -- form adapted to darcs patches. The @C@ @(x y)@ represents the type -- witness for the patch that should be there. The @Hopefully@ type -- just tells whether we expect the patch to be hashed or not, and -- 'SimpleHopefully' does the real work of emulating -- 'Either'. @Hopefully sh@ represents an expected unhashed patch, and -- @Hashed hash sh@ represents an expected hashed patch with its hash. data Hopefully a wX wY = Hopefully (SimpleHopefully a wX wY) | Hashed String (SimpleHopefully a wX wY) deriving Show -- | @SimpleHopefully@ is a variant of @Either String@ adapted for -- type witnesses. @Actually@ is the equivalent of @Right@, while -- @Unavailable@ is @Left@. data SimpleHopefully a wX wY = Actually (a wX wY) | Unavailable String deriving Show -- | @'PatchInfoAnd' p wA wB@ represents a hope we have to get a -- patch through its info. We're not sure we have the patch, but we -- know its info. data PatchInfoAnd rt p wA wB = PIAP !PatchInfo (Hopefully (WrappedNamed rt p) wA wB) deriving Show instance Show2 p => Show1 (PatchInfoAnd rt p wX) where showDict1 = ShowDictClass instance Show2 p => Show2 (PatchInfoAnd rt p) where showDict2 = ShowDictClass instance PrimPatchBase p => PrimPatchBase (PatchInfoAnd rt p) where type PrimOf (PatchInfoAnd rt p) = PrimOf p -- | @'WPatchInfo' wA wB@ represents the info of a patch, marked with -- the patch's witnesses. newtype WPatchInfo wA wB = WPatchInfo { unWPatchInfo :: PatchInfo } -- This is actually unsafe if we ever commute patches and then compare them -- using this function. TODO: consider adding an extra existential to WPatchInfo -- (as with LabelledPatch in Darcs.Patch.Choices) compareWPatchInfo :: WPatchInfo wA wB -> WPatchInfo wC wD -> EqCheck (wA, wB) (wC, wD) compareWPatchInfo (WPatchInfo x) (WPatchInfo y) = if x == y then unsafeCoerceP IsEq else NotEq instance Eq2 WPatchInfo where WPatchInfo x `unsafeCompare` WPatchInfo y = x == y fmapH :: (a wX wY -> b wW wZ) -> Hopefully a wX wY -> Hopefully b wW wZ fmapH f (Hopefully sh) = Hopefully (ff sh) where ff (Actually a) = Actually (f a) ff (Unavailable e) = Unavailable e fmapH f (Hashed h sh) = Hashed h (ff sh) where ff (Actually a) = Actually (f a) ff (Unavailable e) = Unavailable e info :: PatchInfoAnd rt p wA wB -> PatchInfo info (PIAP i _) = i patchDesc :: forall rt p wX wY . PatchInfoAnd rt p wX wY -> String patchDesc p = justName $ info p winfo :: PatchInfoAnd rt p wA wB -> WPatchInfo wA wB winfo (PIAP i _) = WPatchInfo i -- | @'piap' i p@ creates a PatchInfoAnd containing p with info i. piap :: PatchInfo -> WrappedNamed rt p wA wB -> PatchInfoAnd rt p wA wB piap i p = PIAP i (Hopefully $ Actually p) -- | @n2pia@ creates a PatchInfoAnd representing a @Named@ patch. n2pia :: WrappedNamed rt p wX wY -> PatchInfoAnd rt p wX wY n2pia x = patch2patchinfo x `piap` x patchInfoAndPatch :: PatchInfo -> Hopefully (WrappedNamed rt p) wA wB -> PatchInfoAnd rt p wA wB patchInfoAndPatch = PIAP fmapFLPIAP :: (FL p wX wY -> FL q wX wY) -> (RebaseTypeOf rt :~~: 'IsRebase -> p :~: q) -> PatchInfoAnd rt p wX wY -> PatchInfoAnd rt q wX wY fmapFLPIAP f whenRebase (PIAP i hp) = PIAP i (fmapH (fmapFL_WrappedNamed f whenRebase) hp) generaliseRepoTypePIAP :: PatchInfoAnd ('RepoType 'NoRebase) p wA wB -> PatchInfoAnd rt p wA wB generaliseRepoTypePIAP (PIAP i hp) = PIAP i (fmapH generaliseRepoTypeWrapped hp) -- | @'hopefully' hp@ tries to get a patch from a 'PatchInfoAnd' -- value. If it fails, it outputs an error \"failed to read patch: -- \\". We get the description of the patch -- from the info part of 'hp' hopefully :: PatchInfoAnd rt p wA wB -> WrappedNamed rt p wA wB hopefully = conscientiously $ \e -> text "failed to read patch:" $$ e -- | @'conscientiously' er hp@ tries to extract a patch from a 'PatchInfoAnd'. -- If it fails, it applies the error handling function @er@ to a description -- of the patch info component of @hp@. conscientiously :: (Doc -> Doc) -> PatchInfoAnd rt p wA wB -> WrappedNamed rt p wA wB conscientiously er (PIAP pinf hp) = case hopefully2either hp of Right p -> p Left e -> errorDoc $ er (displayPatchInfo pinf $$ text e) -- | @hopefullyM@ is a version of @hopefully@ which calls @fail@ in a -- monad instead of erroring. hopefullyM :: #if MIN_VERSION_base(4,13,0) MonadFail m #else Monad m #endif => PatchInfoAnd rt p wA wB -> m (WrappedNamed rt p wA wB) hopefullyM (PIAP pinf hp) = case hopefully2either hp of Right p -> return p Left e -> fail $ renderString (displayPatchInfo pinf $$ text e) -- Any recommendations for a nice adverb to name the below? hopefully2either :: Hopefully a wX wY -> Either String (a wX wY) hopefully2either (Hopefully (Actually p)) = Right p hopefully2either (Hashed _ (Actually p)) = Right p hopefully2either (Hopefully (Unavailable e)) = Left e hopefully2either (Hashed _ (Unavailable e)) = Left e actually :: a wX wY -> Hopefully a wX wY actually = Hopefully . Actually createHashed :: String -> (String -> IO (Sealed (a wX))) -> IO (Sealed (Hopefully a wX)) createHashed h f = mapSeal (Hashed h) `fmap` unsafeInterleaveIO (f' `catchNonSignal` handler) where f' = do Sealed x <- f h return (Sealed (Actually x)) handler e = return $ seal $ Unavailable $ prettyException e extractHash :: PatchInfoAnd rt p wA wB -> Either (WrappedNamed rt p wA wB) String extractHash (PIAP _ (Hashed s _)) = Right s extractHash hp = Left $ conscientiously (\e -> text "unable to read patch:" $$ e) hp unavailable :: String -> Hopefully a wX wY unavailable = Hopefully . Unavailable -- Equality on PatchInfoAnd is solely determined by the PatchInfo -- It is a global invariant of darcs that once a patch is recorded, -- it should always have the same representation in the same context. instance Eq2 (PatchInfoAnd rt p) where unsafeCompare (PIAP i _) (PIAP i2 _) = i == i2 instance Invert p => Invert (PatchInfoAnd rt p) where invert (PIAP i p) = PIAP i (invert `fmapH` p) instance PatchListFormat (PatchInfoAnd rt p) instance (PatchListFormat p, ShowPatchBasic p) => ShowPatchBasic (PatchInfoAnd rt p) where showPatch f (PIAP n p) = case hopefully2either p of Right x -> showPatch f x Left _ -> showPatchInfo f n instance (Apply p, IsHunk p, PatchListFormat p, PrimPatchBase p, ShowContextPatch p) => ShowContextPatch (PatchInfoAnd rt p) where showContextPatch f (PIAP n p) = case hopefully2either p of Right x -> showContextPatch f x Left _ -> return $ showPatchInfo f n instance (Apply p, Conflict p, CommuteNoConflicts p, IsHunk p, PatchListFormat p, PrimPatchBase p, ShowPatch p, ApplyState p ~ Tree) => ShowPatch (PatchInfoAnd rt p) where description (PIAP n _) = displayPatchInfo n summary (PIAP n p) = case hopefully2either p of Right x -> summary x Left _ -> displayPatchInfo n summaryFL = vcat . mapFL summary showNicely (PIAP n p) = case hopefully2either p of Right x -> showNicely x Left _ -> displayPatchInfo n instance Commute p => Commute (PatchInfoAnd rt p) where commute (x :> y) = do y' :> x' <- commute (hopefully x :> hopefully y) return $ (info y `piap` y') :> (info x `piap` x') instance Merge p => Merge (PatchInfoAnd rt p) where merge (x :\/: y) = case merge (hopefully x :\/: hopefully y) of y' :/\: x' -> (info y `piap` y') :/\: (info x `piap` x') instance PatchInspect p => PatchInspect (PatchInfoAnd rt p) where listTouchedFiles = listTouchedFiles . hopefully hunkMatches f = hunkMatches f . hopefully instance Apply p => Apply (PatchInfoAnd rt p) where type ApplyState (PatchInfoAnd rt p) = ApplyState p apply p = apply $ hopefully p instance RepairToFL p => Repair (PatchInfoAnd rt p) where applyAndTryToFix p = do mp' <- applyAndTryToFix $ hopefully p case mp' of Nothing -> return Nothing Just (e,p') -> return $ Just (e, n2pia p') instance ( ReadPatch p, PatchListFormat p, PrimPatchBase p, Effect p, FromPrim p , IsRepoType rt ) => ReadPatch (PatchInfoAnd rt p) where readPatch' = mapSeal n2pia <$> readPatch' instance Effect p => Effect (PatchInfoAnd rt p) where effect = effect . hopefully effectRL = effectRL . hopefully instance IsHunk (PatchInfoAnd rt p) where isHunk _ = Nothing instance PatchDebug p => PatchDebug (PatchInfoAnd rt p) darcs-2.14.5/src/Darcs/Patch/Permutations.hs0000644000000000000000000003107207346545000017003 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- Copyright (C) 2009 Ganesh Sittampalam -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Permutations ( removeFL, removeRL, removeCommon, commuteWhatWeCanFL, commuteWhatWeCanRL, genCommuteWhatWeCanRL, genCommuteWhatWeCanFL, partitionFL, partitionRL, simpleHeadPermutationsFL, headPermutationsRL, headPermutationsFL, removeSubsequenceFL, removeSubsequenceRL, partitionConflictingFL, inverseCommuter ) where import Prelude () import Darcs.Prelude import Data.Maybe ( mapMaybe ) import Darcs.Patch.Commute ( Commute, commute, commuteFLorComplain, commuteRL ) import Darcs.Patch.CommuteFn ( CommuteFn ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), (:>)(..), (+<+) , reverseFL, (+>+), (:\/:)(..), lengthFL , lengthRL, reverseRL ) -- |split an 'FL' into "left" and "right" lists according to a predicate @p@, using commutation as necessary. -- If a patch does satisfy the predicate but cannot be commuted past one that does not satisfy -- the predicate, it goes in the "middle" list; to sum up, we have: @all p left@ and @all (not.p) right@, while -- midddle is mixed. -- Note that @p@ should be invariant under commutation (i.e. if 'x1' can commute to 'x2' then 'p x1 <=> p x2'). partitionFL :: Commute p => (forall wU wV . p wU wV -> Bool) -- ^predicate; if true we would like the patch in the "left" list -> FL p wX wY -- ^input 'FL' -> (FL p :> FL p :> FL p) wX wY -- ^"left", "middle" and "right" -- optimise by using an accumulating parameter to track all the "right" patches that we've found so far partitionFL' :: Commute p => (forall wU wV . p wU wV -> Bool) -> RL p wA wB -- the "middle" patches found so far -> RL p wB wC -- the "right" patches found so far -> FL p wC wD -> (FL p :> FL p :> FL p) wA wD partitionFL keepleft = partitionFL' keepleft NilRL NilRL partitionFL' _ middle right NilFL = NilFL :> reverseRL middle :> reverseRL right partitionFL' keepleft middle right (p :>: ps) | keepleft p = case commuteRL (right :> p) of Just (p' :> right') -> case commuteRL (middle :> p') of Just (p'' :> middle') -> case partitionFL' keepleft middle' right' ps of (a :> b :> c) -> p'' :>: a :> b :> c Nothing -> partitionFL' keepleft (middle :<: p') right' ps Nothing -> case commuteWhatWeCanRL (right :> p) of (tomiddle :> p' :> right') -> partitionFL' keepleft (middle +<+ tomiddle :<: p') right' ps | otherwise = partitionFL' keepleft middle (right :<: p) ps -- |split an 'RL' into "left" and "right" lists according to a predicate, using commutation as necessary. -- If a patch does satisfy the predicate but cannot be commuted past one that does not satisfy -- the predicate, it goes in the "left" list. partitionRL :: Commute p => (forall wU wV . p wU wV -> Bool) -- ^predicate; if true we would like the patch in the "right" list -> RL p wX wY -- ^input 'RL' -> (RL p :> RL p) wX wY -- ^"left" and "right" results -- optimise by using an accumulating parameter to track all the "left" patches that we've found so far partitionRL' :: Commute p => (forall wU wV . p wU wV -> Bool) -> RL p wX wZ -> FL p wZ wY -- the "left" patches found so far -> (RL p :> RL p) wX wY partitionRL keepright ps = partitionRL' keepright ps NilFL partitionRL' _ NilRL qs = reverseFL qs :> NilRL partitionRL' keepright (ps :<: p) qs | keepright p, Right (qs' :> p') <- commuteFLorComplain (p :> qs) = case partitionRL' keepright ps qs' of a :> b -> a :> b :<: p' | otherwise = partitionRL' keepright ps (p :>: qs) commuteWhatWeCanFL :: Commute p => (p :> FL p) wX wY -> (FL p :> p :> FL p) wX wY commuteWhatWeCanFL = genCommuteWhatWeCanFL commute genCommuteWhatWeCanFL :: Commute q => (forall wA wB . ((p:>q) wA wB -> Maybe ((q:>p)wA wB))) -> (p :> FL q) wX wY -> (FL q :> p :> FL q) wX wY genCommuteWhatWeCanFL com (p :> x :>: xs) = case com (p :> x) of Nothing -> case commuteWhatWeCanFL (x :> xs) of xs1 :> x' :> xs2 -> case genCommuteWhatWeCanFL com (p :> xs1) of xs1' :> p' :> xs2' -> xs1' :> p' :> xs2' +>+ x' :>: xs2 Just (x' :> p') -> case genCommuteWhatWeCanFL com (p' :> xs) of a :> p'' :> c -> x' :>: a :> p'' :> c genCommuteWhatWeCanFL _ (y :> NilFL) = NilFL :> y :> NilFL commuteWhatWeCanRL :: Commute p => (RL p :> p) wX wY -> (RL p :> p :> RL p) wX wY commuteWhatWeCanRL = genCommuteWhatWeCanRL commute genCommuteWhatWeCanRL :: Commute p => (forall wA wB . ((p :> q) wA wB -> Maybe ((q :> p) wA wB))) -> (RL p :> q) wX wY -> (RL p :> q :> RL p) wX wY genCommuteWhatWeCanRL com (xs :<: x :> p) = case com (x :> p) of Nothing -> case commuteWhatWeCanRL (xs :> x) of xs1 :> x' :> xs2 -> case genCommuteWhatWeCanRL com (xs2 :> p) of xs1' :> p' :> xs2' -> xs1 :<: x' +<+ xs1' :> p' :> xs2' Just (p' :> x') -> case genCommuteWhatWeCanRL com (xs :> p') of xs1 :> p'' :> xs2 -> xs1 :> p'' :> xs2 :<: x' genCommuteWhatWeCanRL _ (NilRL :> y) = NilRL :> y :> NilRL removeCommon :: (Eq2 p, Commute p) => (FL p :\/: FL p) wX wY -> (FL p :\/: FL p) wX wY removeCommon (xs :\/: NilFL) = xs :\/: NilFL removeCommon (NilFL :\/: xs) = NilFL :\/: xs removeCommon (xs :\/: ys) = rc xs (headPermutationsFL ys) where rc :: (Eq2 p, Commute p) => FL p wX wY -> [(p:>FL p) wX wZ] -> (FL p :\/: FL p) wY wZ rc nms ((n:>ns):_) | Just ms <- removeFL n nms = removeCommon (ms :\/: ns) rc ms [n:>ns] = ms :\/: n:>:ns rc ms (_:nss) = rc ms nss rc _ [] = impossible -- because we already checked for NilFL case -- | 'removeFL' @x xs@ removes @x@ from @xs@ if @x@ can be commuted to its head. -- Otherwise it returns 'Nothing' removeFL :: (Eq2 p, Commute p) => p wX wY -> FL p wX wZ -> Maybe (FL p wY wZ) removeFL x xs = r x $ headPermutationsFL xs where r :: (Eq2 p, Commute p) => p wX wY -> [(p:>FL p) wX wZ] -> Maybe (FL p wY wZ) r _ [] = Nothing r z ((z':>zs):zss) | IsEq <- z =\/= z' = Just zs | otherwise = r z zss -- | 'removeRL' is like 'removeFL' except with 'RL' removeRL :: (Eq2 p, Commute p) => p wY wZ -> RL p wX wZ -> Maybe (RL p wX wY) removeRL x xs = r x $ headPermutationsRL xs where r :: (Eq2 p, Commute p) => p wY wZ -> [RL p wX wZ] -> Maybe (RL p wX wY) r z ((zs:<:z'):zss) | IsEq <- z =/\= z' = Just zs | otherwise = r z zss r _ _ = Nothing -- | 'removeSubsequenceFL' @ab abc@ returns @Just c'@ where all the patches in -- @ab@ have been commuted out of it, if possible. If this is not possible -- for any reason (the set of patches @ab@ is not actually a subset of @abc@, -- or they can't be commuted out) we return 'Nothing'. removeSubsequenceFL :: (Eq2 p, Commute p) => FL p wA wB -> FL p wA wC -> Maybe (FL p wB wC) removeSubsequenceFL a b | lengthFL a > lengthFL b = Nothing | otherwise = rsFL a b where rsFL :: (Eq2 p, Commute p) => FL p wA wB -> FL p wA wC -> Maybe (FL p wB wC) rsFL NilFL ys = Just ys rsFL (x:>:xs) yys = removeFL x yys >>= removeSubsequenceFL xs -- | 'removeSubsequenceRL' is like @removeSubsequenceFL@ except that it works -- on 'RL' removeSubsequenceRL :: (Eq2 p, Commute p) => RL p wAb wAbc -> RL p wA wAbc -> Maybe (RL p wA wAb) removeSubsequenceRL a b | lengthRL a > lengthRL b = Nothing | otherwise = rsRL a b where rsRL :: (Eq2 p, Commute p) => RL p wAb wAbc -> RL p wA wAbc -> Maybe (RL p wA wAb) rsRL NilRL ys = Just ys rsRL (xs:<:x) yys = removeRL x yys >>= removeSubsequenceRL xs -- | This is a minor variant of 'headPermutationsFL' with each permutation -- is simply returned as a 'FL' simpleHeadPermutationsFL :: Commute p => FL p wX wY -> [FL p wX wY] simpleHeadPermutationsFL ps = map (\ (x:>xs) -> x:>:xs) $ headPermutationsFL ps -- | 'headPermutationsFL' @p:>:ps@ returns all the permutations of the list -- in which one element of @ps@ is commuted past @p@ -- -- Suppose we have a sequence of patches -- -- > X h a y s-t-c k -- -- Suppose furthermore that the patch @c@ depends on @t@, which in turn -- depends on @s@. This function will return -- -- > X :> h a y s t c k -- > h :> X a y s t c k -- > a :> X h y s t c k -- > y :> X h a s t c k -- > s :> X h a y t c k -- > k :> X h a y s t c headPermutationsFL :: Commute p => FL p wX wY -> [(p :> FL p) wX wY] headPermutationsFL NilFL = [] headPermutationsFL (p:>:ps) = (p:>ps) : mapMaybe (swapfirstFL.(p:>)) (headPermutationsFL ps) where swapfirstFL (p1:>p2:>xs) = do p2':>p1' <- commute (p1:>p2) Just $ p2':>p1':>:xs -- | 'headPermutationsRL' is like 'headPermutationsFL', except that we -- operate on an 'RL' (in other words, we are pushing things to the end of a -- patch sequence instead of to the beginning). headPermutationsRL :: Commute p => RL p wX wY -> [RL p wX wY] headPermutationsRL NilRL = [] headPermutationsRL (ps:<:p) = (ps:<:p) : mapMaybe (swapfirstRL.(:<:p)) (headPermutationsRL ps) where swapfirstRL (xs:<:p2:<:p1) = do p1':>p2' <- commute (p2:>p1) Just $ xs:<:p1':<:p2' swapfirstRL _ = Nothing instance (Eq2 p, Commute p) => Eq2 (FL p) where a =\/= b | lengthFL a /= lengthFL b = NotEq | otherwise = cmpSameLength a b where cmpSameLength :: FL p wX wY -> FL p wX wZ -> EqCheck wY wZ cmpSameLength (x:>:xs) xys | Just ys <- removeFL x xys = cmpSameLength xs ys cmpSameLength NilFL NilFL = IsEq cmpSameLength _ _ = NotEq xs =/\= ys = reverseFL xs =/\= reverseFL ys instance (Eq2 p, Commute p) => Eq2 (RL p) where unsafeCompare = bug "Buggy use of unsafeCompare on RL" a =/\= b | lengthRL a /= lengthRL b = NotEq | otherwise = cmpSameLength a b where cmpSameLength :: RL p wX wY -> RL p wW wY -> EqCheck wX wW cmpSameLength (xs:<:x) xys | Just ys <- removeRL x xys = cmpSameLength xs ys cmpSameLength NilRL NilRL = IsEq cmpSameLength _ _ = NotEq xs =\/= ys = reverseRL xs =\/= reverseRL ys -- |Partition a list into the patches that merge with the given patch and those that don't (including dependencies) partitionConflictingFL :: (Commute p1, Invert p1) => CommuteFn p1 p2 -> FL p1 wX wY -> p2 wX wZ -> (FL p1 :> FL p1) wX wY partitionConflictingFL _ NilFL _ = NilFL :> NilFL partitionConflictingFL commuter (x :>: xs) y = case commuter (invert x :> y) of Nothing -> case commuteWhatWeCanFL (x :> xs) of xs_ok :> x' :> xs_deps -> case partitionConflictingFL commuter xs_ok y of xs_clean :> xs_conflicts -> xs_clean :> (xs_conflicts +>+ (x' :>: xs_deps)) Just (y' :> _) -> case partitionConflictingFL commuter xs y' of xs_clean :> xs_conflicts -> (x :>: xs_clean) :> xs_conflicts inverseCommuter :: (Invert p, Invert q) => CommuteFn p q -> CommuteFn q p inverseCommuter commuter (p :> q) = do invp' :> invq' <- commuter (invert q :> invert p) return (invert invq' :> invert invp') darcs-2.14.5/src/Darcs/Patch/Prim.hs0000644000000000000000000000124507346545000015217 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim ( primIsAddfile, primIsHunk, primIsBinary, primIsSetpref , primIsAdddir, is_filepatch , summarizePrim , applyPrimFL , PrimRead(..) , PrimShow(..) , FromPrim(..), FromPrims(..), ToFromPrim(..) , PrimPatch, PrimPatchBase(..) , PrimConstruct(..) , PrimCanonize(..) , PrimPatchCommon ) where import Darcs.Patch.Prim.Class ( PrimConstruct(..), PrimCanonize(..) , PrimClassify(..), PrimDetails(..) , PrimShow(..), PrimRead(..) , PrimApply(..) , FromPrim(..), FromPrims(..), ToFromPrim(..) , PrimPatchBase(..), PrimPatch , PrimPatchCommon ) darcs-2.14.5/src/Darcs/Patch/Prim/0000755000000000000000000000000007346545000014661 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/Prim/Class.hs0000644000000000000000000001372107346545000016266 0ustar0000000000000000module Darcs.Patch.Prim.Class ( PrimConstruct(..), PrimCanonize(..) , PrimClassify(..), PrimDetails(..) , PrimShow(..), PrimRead(..) , PrimApply(..) , PrimPatch, PrimPatchBase(..) , FromPrim(..), FromPrims(..), ToFromPrim(..) , PrimPatchCommon ) where import Prelude () import Darcs.Prelude import Darcs.Patch.ApplyMonad ( ApplyMonad ) import Darcs.Patch.FileHunk ( FileHunk, IsHunk ) import Darcs.Util.Path ( FileName ) import Darcs.Patch.Format ( FileNameFormat, PatchListFormat ) import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Read ( ReadPatch ) import Darcs.Patch.ReadMonads ( ParserM ) import Darcs.Patch.Repair ( RepairToFL ) import Darcs.Patch.Show ( ShowPatch, ShowContextPatch ) import Darcs.Patch.SummaryData ( SummDetail ) import Darcs.Patch.Witnesses.Eq ( Eq2(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL, (:>), mapFL_FL, reverseFL ) import Darcs.Patch.Witnesses.Show ( Show2 ) import Darcs.Patch.Witnesses.Sealed ( Sealed ) import Darcs.Util.Printer ( Doc ) import qualified Darcs.Util.Diff as D ( DiffAlgorithm ) import qualified Data.ByteString as B ( ByteString ) -- | This class describes the abstract interface to primitive patches -- that is indepenent of the on-disk format. class ( Apply prim , Commute prim , Invert prim , Eq2 prim , IsHunk prim , PatchInspect prim , RepairToFL prim , Show2 prim , PrimConstruct prim , PrimCanonize prim , PrimClassify prim , PrimDetails prim , PrimApply prim ) => PrimPatchCommon prim class ( PrimPatchCommon prim , ReadPatch prim , ShowPatch prim , ShowContextPatch prim , PatchListFormat prim ) => PrimPatch prim class PrimPatch (PrimOf p) => PrimPatchBase p where type PrimOf (p :: (* -> * -> *)) :: (* -> * -> *) instance PrimPatchBase p => PrimPatchBase (FL p) where type PrimOf (FL p) = PrimOf p instance PrimPatchBase p => PrimPatchBase (RL p) where type PrimOf (RL p) = PrimOf p class FromPrim p where fromPrim :: PrimOf p wX wY -> p wX wY class FromPrim p => ToFromPrim p where toPrim :: p wX wY -> Maybe (PrimOf p wX wY) class FromPrims p where fromPrims :: FL (PrimOf p) wX wY -> p wX wY instance FromPrim p => FromPrim (FL p) where fromPrim p = fromPrim p :>: NilFL instance FromPrim p => FromPrims (FL p) where fromPrims = mapFL_FL fromPrim instance FromPrim p => FromPrims (RL p) where fromPrims = reverseFL . mapFL_FL fromPrim class PrimClassify prim where primIsAddfile :: prim wX wY -> Bool primIsRmfile :: prim wX wY -> Bool primIsAdddir :: prim wX wY -> Bool primIsRmdir :: prim wX wY -> Bool primIsMove :: prim wX wY -> Bool primIsHunk :: prim wX wY -> Bool primIsTokReplace :: prim wX wY -> Bool primIsBinary :: prim wX wY -> Bool primIsSetpref :: prim wX wY -> Bool is_filepatch :: prim wX wY -> Maybe FileName class PrimConstruct prim where addfile :: FilePath -> prim wX wY rmfile :: FilePath -> prim wX wY adddir :: FilePath -> prim wX wY rmdir :: FilePath -> prim wX wY move :: FilePath -> FilePath -> prim wX wY changepref :: String -> String -> String -> prim wX wY hunk :: FilePath -> Int -> [B.ByteString] -> [B.ByteString] -> prim wX wY tokreplace :: FilePath -> String -> String -> String -> prim wX wY binary :: FilePath -> B.ByteString -> B.ByteString -> prim wX wY primFromHunk :: FileHunk wX wY -> prim wX wY anIdentity :: prim wX wX class PrimCanonize prim where -- | @tryToShrink ps@ simplifies @ps@ by getting rid of self-cancellations -- or coalescing patches -- -- Question (Eric Kow): what properties should this have? For example, -- the prim1 implementation only gets rid of the first self-cancellation -- it finds (as far as I can tell). Is that OK? Can we try harder? tryToShrink :: FL prim wX wY -> FL prim wX wY -- | @tryShrinkingInverse ps@ deletes the first subsequence of -- primitive patches that is followed by the inverse subsequence, -- if one exists. If not, it returns @Nothing@ tryShrinkingInverse :: FL prim wX wY -> Maybe (FL prim wX wY) -- | 'sortCoalesceFL' @ps@ coalesces as many patches in @ps@ as -- possible, sorting the results in some standard order. sortCoalesceFL :: FL prim wX wY -> FL prim wX wY -- | It can sometimes be handy to have a canonical representation of a given -- patch. We achieve this by defining a canonical form for each patch type, -- and a function 'canonize' which takes a patch and puts it into -- canonical form. This routine is used by the diff function to create an -- optimal patch (based on an LCS algorithm) from a simple hunk describing the -- old and new version of a file. canonize :: D.DiffAlgorithm -> prim wX wY -> FL prim wX wY -- | 'canonizeFL' @ps@ puts a sequence of primitive patches into -- canonical form. Even if the patches are just hunk patches, -- this is not necessarily the same set of results as you would get -- if you applied the sequence to a specific tree and recalculated -- a diff. -- -- Note that this process does not preserve the commutation behaviour -- of the patches and is therefore not appropriate for use when -- working with already recorded patches (unless doing amend-record -- or the like). canonizeFL :: D.DiffAlgorithm -> FL prim wX wY -> FL prim wX wY coalesce :: (prim :> prim) wX wY -> Maybe (FL prim wX wY) class PrimDetails prim where summarizePrim :: prim wX wY -> [SummDetail] class PrimShow prim where showPrim :: FileNameFormat -> prim wA wB -> Doc showPrimCtx :: ApplyMonad (ApplyState prim) m => FileNameFormat -> prim wA wB -> m Doc class PrimRead prim where readPrim :: ParserM m => FileNameFormat -> m (Sealed (prim wX)) class PrimApply prim where applyPrimFL :: ApplyMonad (ApplyState prim) m => FL prim wX wY -> m () darcs-2.14.5/src/Darcs/Patch/Prim/FileUUID.hs0000644000000000000000000000121007346545000016555 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.FileUUID ( Prim ) where import Darcs.Patch.Prim.FileUUID.Apply () import Darcs.Patch.Prim.FileUUID.Coalesce () import Darcs.Patch.Prim.FileUUID.Commute () import Darcs.Patch.Prim.FileUUID.Core ( Prim ) import Darcs.Patch.Prim.FileUUID.Details () import Darcs.Patch.Prim.FileUUID.Read () import Darcs.Patch.Prim.FileUUID.Show () import Darcs.Patch.Prim.Class ( PrimPatchCommon, PrimPatch, PrimPatchBase(..), FromPrim(..) ) instance PrimPatchCommon Prim instance PrimPatch Prim instance PrimPatchBase Prim where type PrimOf Prim = Prim instance FromPrim Prim where fromPrim = id darcs-2.14.5/src/Darcs/Patch/Prim/FileUUID/0000755000000000000000000000000007346545000016227 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/Prim/FileUUID/Apply.hs0000644000000000000000000000703007346545000017650 0ustar0000000000000000{-# LANGUAGE MultiParamTypeClasses, OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans -fno-warn-missing-methods #-} module Darcs.Patch.Prim.FileUUID.Apply ( hunkEdit, ObjectMap(..) ) where import Prelude () import Darcs.Prelude import Control.Monad.State( StateT, runStateT, gets, lift, put ) import qualified Data.ByteString as B import qualified Data.Map as M import Debug.Trace ( trace ) -- import Text.Show.Pretty ( ppShow ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.ApplyMonad ( ApplyMonad(..), ApplyMonadTrans(..) , ToTree(..), ApplyMonadState(..) ) import Darcs.Patch.Prim.Class ( PrimApply(..) ) import Darcs.Patch.Prim.FileUUID.Core ( Prim(..), Hunk(..), HunkMove(..) ) import Darcs.Patch.Prim.FileUUID.Show import Darcs.Patch.Prim.FileUUID.ObjectMap import Darcs.Patch.Repair ( RepairToFL(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..) ) import Darcs.Util.Hash( Hash(..) ) import Darcs.Util.Printer( text, packedString, ($$), renderString ) instance Apply Prim where type ApplyState Prim = ObjectMap apply (Manifest i (L dirid name)) = editDirectory dirid (M.insert name i) apply (Demanifest _ (L dirid name)) = editDirectory dirid (M.delete name) apply (Hunk i hunk) = editFile i (hunkEdit hunk) apply (HunkMove (HM fs ls ft lt c)) = editFile fs (hunkEdit (H ls c B.empty)) >> editFile ft (hunkEdit (H lt B.empty c)) apply Identity = return () instance RepairToFL Prim where applyAndTryToFixFL p = apply p >> return Nothing instance PrimApply Prim where applyPrimFL NilFL = return () applyPrimFL (p :>: ps) = apply p >> applyPrimFL ps instance ToTree ObjectMap -- TODO hunkEdit :: Hunk wX wY -> FileContent -> FileContent hunkEdit h@(H off old new) c | old `B.isPrefixOf` (B.drop off c) = B.concat [B.take off c, new, B.drop (off + B.length old) c] | otherwise = error $ renderString $ text "##error applying hunk:" $$ displayHunk Nothing h $$ "##to" $$ packedString c -- $$ text "##old=" <> text (ppShow old) $$ -- text "##new=" <> text (ppShow new) $$ -- text "##c=" <> text (ppShow c) editObject :: Monad m => UUID -> (Maybe (Object m) -> Object m) -> (StateT (ObjectMap m) m) () editObject i edit = do load <- gets getObject store <- gets putObject obj <- lift $ load i new <- lift $ store i $ edit obj put new -- a semantic, ObjectMap-based interface for patch application class ApplyMonadObjectMap m where editFile :: UUID -> (FileContent -> FileContent) -> m () editDirectory :: UUID -> (DirContent -> DirContent) -> m () instance ApplyMonadState ObjectMap where type ApplyMonadStateOperations ObjectMap = ApplyMonadObjectMap instance (Monad m) => ApplyMonad ObjectMap (StateT (ObjectMap m) m) where type ApplyMonadBase (StateT (ObjectMap m) m) = m instance (Monad m) => ApplyMonadObjectMap (StateT (ObjectMap m) m) where editFile i edit = editObject i edit' where edit' (Just (Blob x _)) = Blob (edit `fmap` x) NoHash edit' Nothing = Blob (return $ edit "") NoHash edit' (Just d@(Directory m)) = trace ("\neditFile called with Directory object: " ++ show (i,m) ++ "\n") d editDirectory i edit = editObject i edit' where edit' (Just (Directory x)) = Directory $ edit x edit' Nothing = Directory $ edit M.empty edit' (Just b@(Blob _ h)) = trace ("\neditDirectory called with File object: " ++ show (i,h) ++ "\n") b instance (Monad m) => ApplyMonadTrans ObjectMap m where type ApplyMonadOver ObjectMap m = StateT (ObjectMap m) m runApplyMonad = runStateT darcs-2.14.5/src/Darcs/Patch/Prim/FileUUID/Coalesce.hs0000644000000000000000000000077407346545000020311 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.FileUUID.Coalesce () where import Prelude () import Darcs.Prelude import Darcs.Patch.Prim.Class ( PrimCanonize(..) ) import Darcs.Patch.Witnesses.Ordered( FL(..) ) import Darcs.Patch.Prim.FileUUID.Core( Prim ) -- TODO instance PrimCanonize Prim where tryToShrink = error "tryToShrink" tryShrinkingInverse _ = error "tryShrinkingInverse" sortCoalesceFL = id canonize _ = (:>: NilFL) canonizeFL _ = id coalesce = const Nothing darcs-2.14.5/src/Darcs/Patch/Prim/FileUUID/Commute.hs0000644000000000000000000000416707346545000020204 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.FileUUID.Commute () where import Prelude () import Darcs.Prelude import qualified Data.ByteString as B (length) import Darcs.Patch.Witnesses.Ordered ( (:>)(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Patch.Prim.FileUUID.Core ( Prim(..), Hunk(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Permutations () -- for Invert instance of FL -- For FileUUID it is easier to list the cases that do /not/ commute depends :: (Prim :> Prim) wX wY -> Bool depends (Manifest i1 l1 :> Demanifest i2 l2) -- cannot commute add with remove of same object, regardless of location | i1 == i2 = True -- cannot commute add with remove of any two things at the same location | l1 == l2 = True depends (Demanifest i1 l1 :> Manifest i2 l2) -- cannot commute remove with add of same object, regardless of location | i1 == i2 = True -- cannot commute remove with add of any two things at the same location | l1 == l2 = True depends (_ :> _) = False instance Commute Prim where commute pair | depends pair = Nothing commute (Hunk f1 h1 :> Hunk f2 h2) | f1 == f2 = case commuteHunk (h1 :> h2) of Just (h2' :> h1') -> Just (Hunk f2 h2' :> Hunk f1 h1') Nothing -> Nothing commute (a :> b) = Just (unsafeCoerceP b :> unsafeCoerceP a) commuteHunk :: (Hunk :> Hunk) wX wY -> Maybe ((Hunk :> Hunk) wX wY) commuteHunk (H off1 old1 new1 :> H off2 old2 new2) | off1 + len_new1 < off2 = yes (off2 - len_new1 + len_old1, off1) | off2 + len_old2 < off1 = yes (off2, off1 + len_new2 - len_old2) | len_old2 /= 0 , len_old1 /= 0 , len_new2 /= 0 , len_new1 /= 0 , off1 + len_new1 == off2 = yes (off2 - len_new1 + len_old1, off1) | len_old2 /= 0 , len_old1 /= 0 , len_new2 /= 0 , len_new1 /= 0 , off2 + len_old2 == off1 = yes (off2, off1 + len_new2 - len_old2) | otherwise = no where len_old1 = B.length old1 len_new1 = B.length new1 len_old2 = B.length old2 len_new2 = B.length new2 yes (off2', off1') = Just (H off2' old2 new2 :> H off1' old1 new1) no = Nothing darcs-2.14.5/src/Darcs/Patch/Prim/FileUUID/Core.hs0000644000000000000000000001167007346545000017460 0ustar0000000000000000{-# LANGUAGE OverloadedStrings, StandaloneDeriving #-} -- Copyright (C) 2011 Petr Rockai -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. module Darcs.Patch.Prim.FileUUID.Core ( Prim(..) , Hunk(..) , HunkMove(..) -- re-exports , Object(..) , UUID(..) , Location(..) , Name , FileContent ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Witnesses.Eq ( Eq2(..) ) import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..), ShowDict(ShowDictClass) ) import Darcs.Patch.Witnesses.Unsafe import Darcs.Patch.FileHunk( IsHunk(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Prim.Class ( PrimConstruct(..), PrimClassify(..) ) import Darcs.Patch.Prim.FileUUID.ObjectMap -- ----------------------------------------------------------------------------- -- Hunk data Hunk wX wY = H !Int !FileContent !FileContent deriving (Eq, Show) instance Show1 (Hunk wX) where showDict1 = ShowDictClass instance Show2 Hunk where showDict2 = ShowDictClass invertHunk :: Hunk wX wY -> Hunk wY wX invertHunk (H off old new) = H off new old instance Eq2 Hunk where unsafeCompare p q = unsafeCoerceP p == q -- ----------------------------------------------------------------------------- -- HunkMove data HunkMove wX wY = HM !UUID !Int !UUID !Int !FileContent deriving (Eq, Show) invertHunkMove :: HunkMove wX wY -> HunkMove wY wX invertHunkMove (HM sid soff tid toff content) = HM tid toff sid soff content instance Eq2 HunkMove where unsafeCompare (HM sid1 soff1 tid1 toff1 c1) (HM sid2 soff2 tid2 toff2 c2) = sid1 == sid2 && soff1 == soff2 && tid1 == tid2 && toff1 == toff2 && c1 == c2 -- ----------------------------------------------------------------------------- -- Prim data Prim wX wY where Hunk :: !UUID -> !(Hunk wX wY) -> Prim wX wY HunkMove :: !(HunkMove wX wY) -> Prim wX wY Manifest :: !UUID -> !Location -> Prim wX wY Demanifest :: !UUID -> !Location -> Prim wX wY Identity :: Prim wX wX deriving instance Eq (Prim wX wY) deriving instance Show (Prim wX wY) instance Show1 (Prim wX) where showDict1 = ShowDictClass instance Show2 Prim where showDict2 = ShowDictClass -- TODO: PrimClassify doesn't make sense for FileUUID prims instance PrimClassify Prim where primIsAddfile _ = False primIsRmfile _ = False primIsAdddir _ = False primIsRmdir _ = False primIsHunk _ = False primIsMove _ = False primIsBinary _ = False primIsTokReplace _ = False primIsSetpref _ = False is_filepatch _ = Nothing -- TODO: PrimConstruct makes no sense for FileUUID prims instance PrimConstruct Prim where addfile _ = error "PrimConstruct addfile" rmfile _ = error "PrimConstruct rmfile" adddir _ = error "PrimConstruct adddir" rmdir _ = error "PrimConstruct rmdir" move _ _ = error "PrimConstruct move" changepref _ _ _ = error "PrimConstruct changepref" hunk _ _ _ _ = error "PrimConstruct hunk" tokreplace _ _ _ _ = error "PrimConstruct tokreplace" binary _ _ _ = error "PrimConstruct binary" primFromHunk _ = error "PrimConstruct primFromHunk" anIdentity = Identity instance IsHunk Prim where isHunk _ = Nothing instance Invert Prim where invert (Hunk x h) = Hunk x $ invertHunk h invert (HunkMove hm) = HunkMove $ invertHunkMove hm invert (Manifest x y) = Demanifest x y invert (Demanifest x y) = Manifest x y invert Identity = Identity instance PatchInspect Prim where -- We don't need this for FileUUID. Slashes are not allowed in Manifest and -- Demanifest patches and nothing else uses working-copy paths. listTouchedFiles _ = [] -- TODO (used for --match 'hunk ...', presumably) hunkMatches _ _ = False instance Eq2 Prim where unsafeCompare (Hunk a b) (Hunk c d) = a == c && b `unsafeCompare` d unsafeCompare (Manifest a b) (Manifest c d) = a == c && b == d unsafeCompare (Demanifest a b) (Demanifest c d) = a == c && b == d unsafeCompare Identity Identity = True unsafeCompare _ _ = False darcs-2.14.5/src/Darcs/Patch/Prim/FileUUID/Details.hs0000644000000000000000000000040707346545000020151 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.FileUUID.Details () where import Darcs.Patch.Prim.Class ( PrimDetails(..) ) import Darcs.Patch.Prim.FileUUID.Core ( Prim(..) ) -- TODO instance PrimDetails Prim where summarizePrim _ = [] darcs-2.14.5/src/Darcs/Patch/Prim/FileUUID/ObjectMap.hs0000644000000000000000000000425007346545000020430 0ustar0000000000000000-- Copyright (C) 2011 Petr Rockai -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. module Darcs.Patch.Prim.FileUUID.ObjectMap ( UUID(..), Location(..), Object(..) , ObjectMap(..), DirContent, FileContent , isBlob, isDirectory , Name -- re-export ) where import Prelude () import Darcs.Prelude import Darcs.Util.Hash ( Hash ) import Darcs.Util.Path ( Name ) import qualified Data.ByteString as B (ByteString) import qualified Data.Map as M type FileContent = B.ByteString newtype UUID = UUID B.ByteString deriving (Eq, Ord, Show) -- | An object is located by giving the 'UUID' of the parent -- 'Directory' and a 'Name'. data Location = L !UUID !Name deriving (Eq, Show) -- TODO use HashMap instead? type DirContent = M.Map Name UUID data Object (m :: * -> *) = Directory DirContent | Blob (m FileContent) !Hash isBlob :: Object m -> Bool isBlob Blob{} = True isBlob Directory{} = False isDirectory :: Object m -> Bool isDirectory Directory{} = True isDirectory Blob{} = False data ObjectMap (m :: * -> *) = ObjectMap { getObject :: UUID -> m (Maybe (Object m)) , putObject :: UUID -> Object m -> m (ObjectMap m) , listObjects :: m [UUID] } darcs-2.14.5/src/Darcs/Patch/Prim/FileUUID/Read.hs0000644000000000000000000000373607346545000017447 0ustar0000000000000000{-# LANGUAGE CPP, ViewPatterns, OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.FileUUID.Read () where import Prelude () import Darcs.Prelude import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.ReadMonads import Darcs.Patch.Prim.Class( PrimRead(..) ) import Darcs.Patch.Prim.FileUUID.Core( Prim(..), Hunk(..) ) import Darcs.Patch.Prim.FileUUID.ObjectMap import Darcs.Patch.Witnesses.Sealed( seal ) import Darcs.Util.Path ( unsafeMakeName ) import Control.Monad ( liftM, liftM2 ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import Data.Char ( chr ) instance PrimRead Prim where readPrim _ = do skipSpace choice $ map (liftM seal) [ identity , hunk "hunk" Hunk , manifest "manifest" Manifest , manifest "demanifest" Demanifest ] where manifest kind ctor = liftM2 ctor (patch kind) location identity = lexString "identity" >> return Identity patch x = string x >> uuid uuid = UUID <$> myLex' filename = unsafeMakeName . decodeWhite <$> myLex' content = do lexString "content" len <- int _ <- char '\n' Darcs.Patch.ReadMonads.take len location = liftM2 L uuid filename hunk kind ctor = do uid <- patch kind offset <- int old <- content new <- content return $ ctor uid (H offset old new) instance ReadPatch Prim where readPatch' = readPrim undefined -- XXX a bytestring version of decodeWhite from Darcs.FileName decodeWhite :: B.ByteString -> B.ByteString decodeWhite (BC.uncons -> Just ('\\', cs)) = case BC.break (=='\\') cs of (theord, BC.uncons -> Just ('\\', rest)) -> chr (read $ BC.unpack theord) `BC.cons` decodeWhite rest _ -> error "malformed filename" decodeWhite (BC.uncons -> Just (c, cs)) = c `BC.cons` decodeWhite cs decodeWhite (BC.uncons -> Nothing) = BC.empty #if !MIN_VERSION_base(4,14,0) decodeWhite _ = impossible #endif darcs-2.14.5/src/Darcs/Patch/Prim/FileUUID/Show.hs0000644000000000000000000000712007346545000017503 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} {-# LANGUAGE OverloadedStrings #-} module Darcs.Patch.Prim.FileUUID.Show ( displayHunk ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString as B import Darcs.Patch.Format ( PatchListFormat, FileNameFormat(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..), ShowPatch(..) , ShowContextPatch(..), ShowPatchFor(..) ) import Darcs.Patch.Summary ( plainSummaryPrim ) import Darcs.Patch.Prim.Class ( PrimShow(..) ) import Darcs.Patch.Prim.FileUUID.Core ( Prim(..), Hunk(..), HunkMove(..), UUID(..), Location(..), FileContent ) import Darcs.Patch.Prim.FileUUID.Details () import Darcs.Util.ByteString ( linesPS ) import Darcs.Util.Path ( Name, encodeWhiteName ) import Darcs.Util.Printer ( text, packedString, blueText, prefix , (<+>), ($$), Doc, vcat ) -- TODO this instance shouldn't really be necessary, as Prims aren't used generically instance PatchListFormat Prim fileNameFormat :: ShowPatchFor -> FileNameFormat fileNameFormat ForDisplay = UserFormat fileNameFormat ForStorage = NewFormat instance ShowPatchBasic Prim where showPatch fmt = showPrim (fileNameFormat fmt) -- dummy instance, does not actually show any context instance ShowContextPatch Prim where -- showContextPatch f = showPrimCtx (fileNameFormat f) showContextPatch f p = return $ showPatch f p instance ShowPatch Prim where summary = plainSummaryPrim -- summaryFL = plainSummaryPrims False thing _ = "change" instance PrimShow Prim where showPrim UserFormat (Hunk u h) = displayHunk (Just u) h showPrim _ (Hunk u h) = storeHunk u h showPrim UserFormat (HunkMove hm) = displayHunkMove hm showPrim _ (HunkMove hm) = storeHunkMove hm showPrim _ (Manifest f (L d p)) = showManifest "manifest" d f p showPrim _ (Demanifest f (L d p)) = showManifest "demanifest" d f p showPrim _ Identity = blueText "identity" showPrimCtx _ _ = bug "show with context not implemented" showManifest :: String -> UUID -> UUID -> Name -> Doc showManifest txt dir file name = blueText txt <+> formatUUID file <+> formatUUID dir <+> packedString (encodeWhiteName name) displayHunk :: Maybe UUID -> Hunk wX wY -> Doc displayHunk uid (H off old new) = blueText "hunk" <+> maybe (text "") formatUUID uid <+> text (show off) $$ displayFileContent "-" old $$ displayFileContent "+" new storeHunk :: UUID -> Hunk wX wY -> Doc storeHunk uid (H off old new) = text "hunk" <+> formatUUID uid <+> text (show off) $$ storeFileContent old $$ storeFileContent new displayHunkMove :: HunkMove wX wY -> Doc displayHunkMove (HM sid soff tid toff c) = blueText "hunkmove" <+> formatUUID sid <+> text (show soff) <+> formatUUID tid <+> text (show toff) $$ displayFileContent "|" c storeHunkMove :: HunkMove wX wY -> Doc storeHunkMove (HM sid soff tid toff c) = text "hunkmove" <+> formatUUID sid <+> text (show soff) <+> formatUUID tid <+> text (show toff) $$ storeFileContent c -- TODO add some heuristics to recognize binary content displayFileContent :: String -> FileContent -> Doc displayFileContent pre = vcat . map (prefix pre) . showLines . linesPS where context = blueText "[...]" showLines [] = [] showLines [x] | B.null x = [] | otherwise = [context <> packedString x <> context] showLines (x:xs) = [context <> packedString x] ++ map packedString (init xs) ++ [packedString (last xs) <> context] storeFileContent :: FileContent -> Doc storeFileContent c = text "content" <+> text (show (B.length c)) $$ packedString c formatUUID :: UUID -> Doc formatUUID (UUID x) = packedString x darcs-2.14.5/src/Darcs/Patch/Prim/V1.hs0000644000000000000000000000065107346545000015505 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.V1 ( Prim ) where import Darcs.Patch.Prim.V1.Apply () import Darcs.Patch.Prim.V1.Coalesce () import Darcs.Patch.Prim.V1.Commute () import Darcs.Patch.Prim.V1.Core ( Prim ) import Darcs.Patch.Prim.V1.Details () import Darcs.Patch.Prim.V1.Read () import Darcs.Patch.Prim.V1.Show () import Darcs.Patch.Prim.Class ( PrimPatchCommon ) instance PrimPatchCommon Prim darcs-2.14.5/src/Darcs/Patch/Prim/V1/0000755000000000000000000000000007346545000015147 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/Prim/V1/Apply.hs0000644000000000000000000002247107346545000016576 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.V1.Apply () where import Prelude () import Darcs.Prelude import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Repair ( RepairToFL(..) ) import Darcs.Patch.Prim.Class ( PrimApply(..) ) import Darcs.Patch.Prim.V1.Core ( Prim(..), DirPatchType(..), FilePatchType(..) ) import Darcs.Patch.Prim.V1.Show ( showHunk ) import Darcs.Util.Path ( FileName, fn2fp ) import Darcs.Patch.Format ( FileNameFormat(UserFormat) ) import Darcs.Patch.TokenReplace ( tryTokReplace ) import Darcs.Patch.ApplyMonad ( ApplyMonadTree(..) ) import Darcs.Util.Tree( Tree ) import Darcs.Patch.Witnesses.Ordered ( FL(..), mapFL_FL, spanFL, (:>)(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoercePStart ) import Darcs.Util.ByteString ( unlinesPS ) import Darcs.Util.Printer( renderString ) import Control.Exception ( throw ) import qualified Data.ByteString as B import qualified Data.ByteString.Internal as BI import qualified Data.ByteString.Char8 as BC (pack, unpack, unlines) type FileContents = B.ByteString instance Apply Prim where type ApplyState Prim = Tree apply (FP f RmFile) = mRemoveFile f apply (FP f AddFile) = mCreateFile f apply (FP f (Hunk l o n)) = mModifyFilePS f $ applyHunk f (l, o, n) apply (FP f (TokReplace t o n)) = mModifyFilePS f doreplace where doreplace fc = case tryTokReplace t (BC.pack o) (BC.pack n) fc of Nothing -> throw $ userError $ "replace patch to " ++ fn2fp f ++ " couldn't apply." Just fc' -> return fc' apply (FP f (Binary o n)) = mModifyFilePS f doapply where doapply oldf = if o == oldf then return n else throw $ userError $ "binary patch to " ++ fn2fp f ++ " couldn't apply." apply (DP d AddDir) = mCreateDirectory d apply (DP d RmDir) = mRemoveDirectory d apply (Move f f') = mRename f f' apply (ChangePref p f t) = mChangePref p f t instance RepairToFL Prim where applyAndTryToFixFL (FP f RmFile) = do x <- mReadFilePS f mRemoveFile f return $ if B.null x then Nothing else Just ("WARNING: Fixing removal of non-empty file "++fn2fp f, -- No need to coerce because the content -- removal patch has freely decided contexts FP f (Binary x B.empty) :>: FP f RmFile :>: NilFL ) applyAndTryToFixFL (FP f AddFile) = do exists <- mDoesFileExist f if exists then return $ Just ("WARNING: Dropping add of existing file "++fn2fp f, -- the old context was wrong, so we have to coerce unsafeCoercePStart NilFL ) else do mCreateFile f return Nothing applyAndTryToFixFL (DP f AddDir) = do exists <- mDoesDirectoryExist f if exists then return $ Just ("WARNING: Dropping add of existing directory "++fn2fp f, -- the old context was wrong, so we have to coerce unsafeCoercePStart NilFL ) else do mCreateDirectory f return Nothing applyAndTryToFixFL p = do apply p; return Nothing instance PrimApply Prim where applyPrimFL NilFL = return () applyPrimFL (FP f h@(Hunk{}):>:the_ps) = case spanFL f_hunk the_ps of (xs :> ps') -> do let foo = h :>: mapFL_FL (\(FP _ h') -> h') xs mModifyFilePS f $ hunkmod foo applyPrimFL ps' where f_hunk (FP f' (Hunk{})) = f == f' f_hunk _ = False -- TODO there should be a HOF that abstracts -- over this recursion scheme hunkmod :: Monad m => FL FilePatchType wX wY -> B.ByteString -> m B.ByteString hunkmod NilFL content = return content hunkmod (Hunk line old new:>:hs) content = applyHunk f (line, old, new) content >>= hunkmod hs hunkmod _ _ = impossible applyPrimFL (p:>:ps) = apply p >> applyPrimFL ps applyHunk :: Monad m => FileName -> (Int, [B.ByteString], [B.ByteString]) -> FileContents -> m FileContents applyHunk f h fc = case applyHunkLines h fc of Right fc' -> return fc' Left msg -> throw $ userError $ "### Error applying:\n" ++ renderHunk h ++ "\n### to file " ++ fn2fp f ++ ":\n" ++ BC.unpack fc ++ "### Reason: " ++ msg where renderHunk (l, o, n) = renderString (showHunk UserFormat f l o n) {- The way darcs handles newlines is not easy to understand. Everything seems pretty logical and conventional as long as files end in a newline. In this case, the lines in a hunk can be regarded as newline terminated, too. However, this view breaks down if we consider files that are not newline terminated. Here is a different view that covers the general case and explains, conceptually, the algorithm below. * Ever line (in a hunk or file) is regarded as being /preceded/ by a newline character. * Every file starts out containing a single newline character, that is, a single empty line. A first empty line at the start of a file (if present) is /invisible/. * When lines are appended to a file by a hunk, they are inserted /before/ a final empty line, if there is one. This results in a file that remains being terminated by a newline. * In particular, when we start with an empty file and add a line, we push the invisible newline back, making it visible, and the newline that initiates our new content becomes invisible instead. This results in a newline terminated file, as above. * However, if there is a newline at the end of a file (remember that this includes the case of an empty file), a hunk can /remove/ it by removing an empty line before adding anything. This results in a file that is /not/ newline terminated. The invisible newline character at the front is, of course, not present anywhere in the representation of files, it is just a conceptual tool. The algorithm below is highly optimized to minimize allocation of intermediate ByteStrings. -} applyHunkLines :: (Int, [B.ByteString], [B.ByteString]) -> FileContents -> Either String FileContents applyHunkLines (line, old, new) content | line == 1 = {- This case is subtle because here we have to deal with any invisible newline at the front of a file without it actually being present. We first try to drop everything up to the (length old)'th newline. If this fails, we know that the content was not newline terminated. So we replace everything with the new content, interspersing but not terminating the lines with newline characters. If it succeeds, we insert the new content, interspersing /and/ terminating the lines with newline characters before appending the rest of the content. -} case breakAfterNthNewline (length old) content of Nothing -- old content is not newline terminated | content == unlinesPS old -> Right $ unlinesPS new | otherwise -> Left "Hunk wants to remove content that isn't there" Just (should_be_old, suffix) -- old content is newline terminated | should_be_old == BC.unlines old -> Right $ unlinesPS $ new ++ [suffix] | otherwise -> Left "Hunk wants to remove content that isn't there" | line >= 2 = do {- This is the simpler case. We can be sure that we have at least one newline character at the point where we modify the file. This means we can apply the conceptual view literally, i.e. replace old content with new content /before/ this newline, where the lines in the old and new content are /preceded/ by newline characters. -} (pre, start) <- breakBeforeNthNewline (line-2) content let hunkContent ls = unlinesPS (B.empty:ls) post <- dropPrefix (hunkContent old) start return $ B.concat [pre, hunkContent new, post] | otherwise = Left "Hunk has zero or negative line number" where dropPrefix x y | x `B.isPrefixOf` y = Right $ B.drop (B.length x) y | otherwise = Left $ "Hunk wants to remove content that isn't there" breakAfterNthNewline :: Int -> B.ByteString -> Maybe (B.ByteString, B.ByteString) breakAfterNthNewline 0 the_ps = Just (B.empty, the_ps) breakAfterNthNewline n _ | n < 0 = error "precondition of breakAfterNthNewline" breakAfterNthNewline n the_ps = go n (B.elemIndices (BI.c2w '\n') the_ps) where go _ [] = Nothing -- we have fewer than n newlines go 1 (i:_) = Just $ B.splitAt (i + 1) the_ps go !m (_:is) = go (m - 1) is breakBeforeNthNewline :: Int -> B.ByteString -> Either String (B.ByteString, B.ByteString) breakBeforeNthNewline n _ | n < 0 = error "precondition of breakBeforeNthNewline" breakBeforeNthNewline n the_ps = go n (B.elemIndices (BI.c2w '\n') the_ps) where go 0 [] = Right (the_ps, B.empty) go 0 (i:_) = Right $ B.splitAt i the_ps go !m (_:is) = go (m - 1) is go _ [] = Left "Line number does not exist" darcs-2.14.5/src/Darcs/Patch/Prim/V1/Coalesce.hs0000644000000000000000000002501007346545000017217 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.V1.Coalesce () where import Prelude () import Darcs.Prelude import Prelude hiding ( pi ) import Control.Arrow ( second ) import Data.Maybe ( fromMaybe ) import Data.Map ( elems, fromListWith, mapWithKey ) import qualified Data.ByteString as B (ByteString, empty) import System.FilePath ( () ) import Darcs.Patch.Prim.Class ( PrimCanonize(..) ) import Darcs.Patch.Prim.V1.Commute () import Darcs.Patch.Prim.V1.Core ( Prim(..), FilePatchType(..), DirPatchType(..) , comparePrim, isIdentity ) import Darcs.Patch.Prim.V1.Show () import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), (:>)(..) , reverseRL, mapFL, mapFL_FL , concatFL, lengthFL, (+>+) ) import Darcs.Patch.Witnesses.Sealed ( unseal, Sealed2(..), unsafeUnseal2 , Gap(..), unFreeLeft ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP, unsafeCoercePEnd ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Util.Diff ( getChanges ) import qualified Darcs.Util.Diff as D ( DiffAlgorithm ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Path ( FileName, fp2fn ) -- | 'coalesceFwd' @p1 :> p2@ tries to combine @p1@ and @p2@ into a single -- patch without intermediary changes. For example, two hunk patches -- modifying adjacent lines can be coalesced into a bigger hunk patch. -- Or a patch which moves file A to file B can be coalesced with a -- patch that moves file B into file C, yielding a patch that moves -- file A to file C. coalesceFwd :: (Prim :> Prim) wX wY -> Maybe (FL Prim wX wY) coalesceFwd (FP f1 _ :> FP f2 _) | f1 /= f2 = Nothing coalesceFwd (p1 :> p2) | IsEq <- invert p1 =\/= p2 = Just NilFL coalesceFwd (FP f1 p1 :> FP _ p2) = fmap (:>: NilFL) $ coalesceFilePrim f1 (p1 :> p2) -- f1 = f2 coalesceFwd (Move a b :> Move b' a') | b == b' = Just $ Move a a' :>: NilFL coalesceFwd (FP f AddFile :> Move a b) | f == a = Just $ FP b AddFile :>: NilFL coalesceFwd (DP f AddDir :> Move a b) | f == a = Just $ DP b AddDir :>: NilFL coalesceFwd (Move a b :> FP f RmFile) | b == f = Just $ FP a RmFile :>: NilFL coalesceFwd (Move a b :> DP f RmDir) | b == f = Just $ DP a RmDir :>: NilFL coalesceFwd (ChangePref p1 f1 t1 :> ChangePref p2 f2 t2) | p1 == p2 && t1 == f2 = Just $ ChangePref p1 f1 t2 :>: NilFL coalesceFwd _ = Nothing mapPrimFL :: (forall wX wY . FL Prim wX wY -> FL Prim wX wY) -> FL Prim wW wZ -> FL Prim wW wZ mapPrimFL f x = -- an optimisation; break the list up into independent sublists -- and apply f to each of them case mapM toSimpleSealed $ mapFL Sealed2 x of Just sx -> concatFL $ unsealList $ elems $ mapWithKey (\ k p -> Sealed2 (f (fromSimples k (unsealList (p []))))) $ fromListWith (flip (.)) $ map (\ (a,b) -> (a,(b:))) sx Nothing -> f x where unsealList :: [Sealed2 p] -> FL p wA wB unsealList = foldr ((:>:) . unsafeUnseal2) (unsafeCoerceP NilFL) toSimpleSealed :: Sealed2 Prim -> Maybe (FileName, Sealed2 Simple) toSimpleSealed (Sealed2 p) = fmap (second Sealed2) (toSimple p) data Simple wX wY = SFP !(FilePatchType wX wY) | SDP !(DirPatchType wX wY) | SCP String String String deriving ( Show ) toSimple :: Prim wX wY -> Maybe (FileName, Simple wX wY) toSimple (FP a b) = Just (a, SFP b) toSimple (DP a AddDir) = Just (a, SDP AddDir) toSimple (DP _ RmDir) = Nothing -- ordering is trickier with rmdir present toSimple (Move _ _) = Nothing toSimple (ChangePref a b c) = Just (fp2fn $ darcsdir "prefs" "prefs", SCP a b c) fromSimple :: FileName -> Simple wX wY -> Prim wX wY fromSimple a (SFP b) = FP a b fromSimple a (SDP b) = DP a b fromSimple _ (SCP a b c) = ChangePref a b c fromSimples :: FileName -> FL Simple wX wY -> FL Prim wX wY fromSimples a = mapFL_FL (fromSimple a) tryHarderToShrink :: FL Prim wX wY -> FL Prim wX wY tryHarderToShrink x = tryToShrink2 $ fromMaybe x (tryShrinkingInverse x) tryToShrink2 :: FL Prim wX wY -> FL Prim wX wY tryToShrink2 psold = let ps = sortCoalesceFL psold ps_shrunk = shrinkABit ps in if lengthFL ps_shrunk < lengthFL ps then tryToShrink2 ps_shrunk else ps_shrunk -- | @shrinkABit ps@ tries to simplify @ps@ by one patch, -- the first one we find that coalesces with its neighbour shrinkABit :: FL Prim wX wY -> FL Prim wX wY shrinkABit NilFL = NilFL shrinkABit (p:>:ps) = fromMaybe (p :>: shrinkABit ps) $ tryOne NilRL p ps -- | @tryOne acc p ps@ pushes @p@ as far down @ps@ as we can go -- until we can either coalesce it with something or it can't -- go any further. Returns @Just@ if we manage to get any -- coalescing out of this tryOne :: RL Prim wW wX -> Prim wX wY -> FL Prim wY wZ -> Maybe (FL Prim wW wZ) tryOne _ _ NilFL = Nothing tryOne sofar p (p1:>:ps) = case coalesceFwd (p :> p1) of Just p' -> Just (reverseRL sofar +>+ p' +>+ ps) Nothing -> case commute (p :> p1) of Nothing -> Nothing Just (p1' :> p') -> tryOne (sofar:<:p1') p' ps -- | The heart of "sortCoalesceFL" sortCoalesceFL2 :: FL Prim wX wY -> FL Prim wX wY sortCoalesceFL2 NilFL = NilFL sortCoalesceFL2 (x:>:xs) | IsEq <- isIdentity x = sortCoalesceFL2 xs sortCoalesceFL2 (x:>:xs) = either id id $ pushCoalescePatch x $ sortCoalesceFL2 xs -- | 'pushCoalescePatch' @new ps@ is almost like @new :>: ps@ except -- as an alternative to consing, we first try to coalesce @new@ with -- the head of @ps@. If this fails, we try again, using commutation -- to push @new@ down the list until we find a place where either -- (a) @new@ is @LT@ the next member of the list [see 'comparePrim'] -- (b) commutation fails or -- (c) coalescing succeeds. -- The basic principle is to coalesce if we can and cons otherwise. -- -- As an additional optimization, pushCoalescePatch outputs a Left -- value if it wasn't able to shrink the patch sequence at all, and -- a Right value if it was indeed able to shrink the patch sequence. -- This avoids the O(N) calls to lengthFL that were in the older -- code. -- -- Also note that pushCoalescePatch is only ever used (and should -- only ever be used) as an internal function in in -- sortCoalesceFL2. pushCoalescePatch :: Prim wX wY -> FL Prim wY wZ -> Either (FL Prim wX wZ) (FL Prim wX wZ) pushCoalescePatch new NilFL = Left (new:>:NilFL) pushCoalescePatch new ps@(p:>:ps') = case coalesceFwd (new :> p) of Just (new' :>: NilFL) -> Right $ either id id $ pushCoalescePatch new' ps' Just NilFL -> Right ps' Just _ -> impossible -- coalesce either returns a singleton or empty Nothing -> if comparePrim new p == LT then Left (new:>:ps) else case commute (new :> p) of Just (p' :> new') -> case pushCoalescePatch new' ps' of Right r -> Right $ either id id $ pushCoalescePatch p' r Left r -> Left (p' :>: r) Nothing -> Left (new:>:ps) coalesceFilePrim :: FileName -> (FilePatchType :> FilePatchType) wX wY -> Maybe (Prim wX wY) coalesceFilePrim f (Hunk line1 old1 new1 :> Hunk line2 old2 new2) = coalesceHunk f line2 old2 new2 line1 old1 new1 -- Token replace patches operating right after (or before) AddFile (RmFile) -- is an identity patch, as far as coalescing is concerned. coalesceFilePrim f (AddFile :> TokReplace{}) = Just $ FP f AddFile coalesceFilePrim f (TokReplace{} :> RmFile) = Just $ FP f RmFile coalesceFilePrim f (TokReplace t1 o1 n1 :> TokReplace t2 o2 n2) | t1 == t2 && n1 == o2 = Just $ FP f $ TokReplace t1 o1 n2 coalesceFilePrim f (Binary o m' :> Binary m n) | m == m' = Just $ FP f $ Binary o n coalesceFilePrim _ _ = Nothing coalesceHunk :: FileName -> Int -> [B.ByteString] -> [B.ByteString] -> Int -> [B.ByteString] -> [B.ByteString] -> Maybe (Prim wX wY) coalesceHunk f line1 old1 new1 line2 old2 new2 | line1 == line2 && lengthold1 < lengthnew2 = if take lengthold1 new2 /= old1 then Nothing else case drop lengthold1 new2 of extranew -> Just (FP f (Hunk line1 old2 (new1 ++ extranew))) | line1 == line2 && lengthold1 > lengthnew2 = if take lengthnew2 old1 /= new2 then Nothing else case drop lengthnew2 old1 of extraold -> Just (FP f (Hunk line1 (old2 ++ extraold) new1)) | line1 == line2 = if new2 == old1 then Just (FP f (Hunk line1 old2 new1)) else Nothing | line1 < line2 && lengthold1 >= line2 - line1 = case take (line2 - line1) old1 of extra-> coalesceHunk f line1 old1 new1 line1 (extra ++ old2) (extra ++ new2) | line1 > line2 && lengthnew2 >= line1 - line2 = case take (line1 - line2) new2 of extra-> coalesceHunk f line2 (extra ++ old1) (extra ++ new1) line2 old2 new2 | otherwise = Nothing where lengthold1 = length old1 lengthnew2 = length new2 canonizeHunk :: Gap w => D.DiffAlgorithm -> FileName -> Int -> [B.ByteString] -> [B.ByteString] -> w (FL Prim) canonizeHunk _ f line old new | null old || null new || old == [B.empty] || new == [B.empty] = freeGap (FP f (Hunk line old new) :>: NilFL) canonizeHunk da f line old new = makeHoley f line $ getChanges da old new makeHoley :: Gap w => FileName -> Int -> [(Int,[B.ByteString], [B.ByteString])] -> w (FL Prim) makeHoley f line = foldr (joinGap (:>:) . (\(l,o,n) -> freeGap (FP f (Hunk (l+line) o n)))) (emptyGap NilFL) instance PrimCanonize Prim where tryToShrink = mapPrimFL tryHarderToShrink tryShrinkingInverse (x:>:y:>:z) | IsEq <- invert x =\/= y = Just z | otherwise = case tryShrinkingInverse (y:>:z) of Nothing -> Nothing Just yz' -> Just $ fromMaybe (x :>: yz') $ tryShrinkingInverse (x:>:yz') tryShrinkingInverse _ = Nothing sortCoalesceFL = mapPrimFL sortCoalesceFL2 canonize _ p | IsEq <- isIdentity p = NilFL canonize da (FP f (Hunk line old new)) = unseal unsafeCoercePEnd $ unFreeLeft $ canonizeHunk da f line old new canonize _ p = p :>: NilFL -- Running canonize twice is apparently necessary to fix issue525; -- would be nice to understand why. canonizeFL da = concatFL . mapFL_FL (canonize da) . sortCoalesceFL . concatFL . mapFL_FL (canonize da) coalesce = coalesceFwd darcs-2.14.5/src/Darcs/Patch/Prim/V1/Commute.hs0000644000000000000000000001744707346545000017131 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.V1.Commute ( Perhaps(..) , toPerhaps , CommuteFunction , speedyCommute , cleverCommute , commuteFiledir , commuteFilepatches ) where import Prelude () import Darcs.Prelude import Prelude hiding ( pi, Applicative(..) ) import Control.Monad ( MonadPlus, msum, mzero, mplus ) import Control.Applicative ( Alternative(..) ) import qualified Data.ByteString as B ( ByteString ) import qualified Data.ByteString.Char8 as BC ( pack ) import Darcs.Util.Path ( FileName, fn2fp, movedirfilename ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Patch.Witnesses.Ordered ( (:>)(..) ) import Darcs.Patch.Prim.V1.Core ( Prim(..), FilePatchType(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Permutations () -- for Invert instance of FL import Darcs.Patch.TokenReplace ( tryTokReplace ) isInDirectory :: FileName -> FileName -> Bool isInDirectory d f = iid (fn2fp d) (fn2fp f) where iid (cd:cds) (cf:cfs) | cd /= cf = False | otherwise = iid cds cfs iid [] ('/':_) = True iid [] [] = True -- Count directory itself as being in directory... iid _ _ = False data Perhaps a = Unknown | Failed | Succeeded a instance Functor Perhaps where fmap _ Unknown = Unknown fmap _ Failed = Failed fmap f (Succeeded x) = Succeeded (f x) instance Applicative Perhaps where pure = Succeeded _ <*> Failed = Failed _ <*> Unknown = Unknown Failed <*> _ = Failed Unknown <*> _ = Unknown Succeeded f <*> Succeeded x = Succeeded (f x) instance Monad Perhaps where (Succeeded x) >>= k = k x Failed >>= _ = Failed Unknown >>= _ = Unknown return = Succeeded #if MIN_VERSION_base(4,13,0) instance MonadFail Perhaps where #endif fail _ = Unknown instance Alternative Perhaps where empty = Unknown Unknown <|> ys = ys Failed <|> _ = Failed (Succeeded x) <|> _ = Succeeded x instance MonadPlus Perhaps where mzero = Unknown mplus = (<|>) toMaybe :: Perhaps a -> Maybe a toMaybe (Succeeded x) = Just x toMaybe _ = Nothing toPerhaps :: Maybe a -> Perhaps a toPerhaps (Just x) = Succeeded x toPerhaps Nothing = Failed cleverCommute :: CommuteFunction -> CommuteFunction cleverCommute c (p1:>p2) = case c (p1 :> p2) of Succeeded x -> Succeeded x Failed -> Failed Unknown -> case c (invert p2 :> invert p1) of Succeeded (p1' :> p2') -> Succeeded (invert p2' :> invert p1') Failed -> Failed Unknown -> Unknown --cleverCommute c (p1,p2) = c (p1,p2) `mplus` -- (case c (invert p2,invert p1) of -- Succeeded (p1', p2') -> Succeeded (invert p2', invert p1') -- Failed -> Failed -- Unknown -> Unknown) speedyCommute :: CommuteFunction -- Deal with common cases quickly! -- Two file-patches modifying different files trivially commute. speedyCommute (p1@(FP f1 _) :> p2@(FP f2 _)) | f1 /= f2 = Succeeded (unsafeCoerceP p2 :> unsafeCoerceP p1) speedyCommute _other = Unknown everythingElseCommute :: CommuteFunction everythingElseCommute = eec where eec :: CommuteFunction eec (p1 :> ChangePref p f t) = Succeeded (ChangePref p f t :> unsafeCoerceP p1) eec (ChangePref p f t :> p2) = Succeeded (unsafeCoerceP p2 :> ChangePref p f t) eec xx = cleverCommute commuteFiledir xx {- Note that it must be true that commutex (A^-1 A, P) = Just (P, A'^-1 A') and if commutex (A, B) == Just (B', A') then commutex (B^-1, A^-1) == Just (A'^-1, B'^-1) -} instance Commute Prim where commute x = toMaybe $ msum [speedyCommute x, everythingElseCommute x ] isSuperdir :: FileName -> FileName -> Bool isSuperdir d1 d2 = isd (fn2fp d1) (fn2fp d2) where isd s1 s2 = length s2 >= length s1 + 1 && take (length s1 + 1) s2 == s1 ++ "/" commuteFiledir :: CommuteFunction commuteFiledir (FP f1 p1 :> FP f2 p2) = if f1 /= f2 then Succeeded ( FP f2 (unsafeCoerceP p2) :> FP f1 (unsafeCoerceP p1) ) else commuteFP f1 (p1 :> p2) commuteFiledir (DP d1 p1 :> DP d2 p2) = if not (isInDirectory d1 d2 || isInDirectory d2 d1) && d1 /= d2 then Succeeded ( DP d2 (unsafeCoerceP p2) :> DP d1 (unsafeCoerceP p1) ) else Failed commuteFiledir (FP f fp :> DP d dp) = if not $ isInDirectory d f then Succeeded (DP d (unsafeCoerceP dp) :> FP f (unsafeCoerceP fp)) else Failed commuteFiledir (FP f1 p1 :> Move d d') | f1 == d' = Failed | (p1 == AddFile || p1 == RmFile) && d == f1 = Failed | otherwise = Succeeded (Move d d' :> FP (movedirfilename d d' f1) (unsafeCoerceP p1)) commuteFiledir (DP d1 p1 :> Move d d') | isSuperdir d1 d' || isSuperdir d1 d = Failed | d == d1 = Failed -- The exact guard is p1 == AddDir && d == d1 -- but note d == d1 suffices because we know p1 != RmDir -- (and hence p1 == AddDir) since patches must be sequential. | d1 == d' = Failed | otherwise = Succeeded (Move d d' :> DP (movedirfilename d d' d1) (unsafeCoerceP p1)) commuteFiledir (Move f f' :> Move d d') | f == d' || f' == d = Failed | f == d || f' == d' = Failed | d `isSuperdir` f && f' `isSuperdir` d' = Failed | otherwise = Succeeded (Move (movedirfilename f' f d) (movedirfilename f' f d') :> Move (movedirfilename d d' f) (movedirfilename d d' f')) commuteFiledir _ = Unknown type CommuteFunction = forall wX wY . (Prim :> Prim) wX wY -> Perhaps ((Prim :> Prim) wX wY) commuteFilepatches :: CommuteFunction commuteFilepatches (FP f1 p1 :> FP f2 p2) | f1 == f2 = commuteFP f1 (p1 :> p2) commuteFilepatches _ = Unknown commuteFP :: FileName -> (FilePatchType :> FilePatchType) wX wY -> Perhaps ((Prim :> Prim) wX wY) commuteFP f (p1 :> Hunk line1 [] []) = Succeeded (FP f (Hunk line1 [] []) :> FP f (unsafeCoerceP p1)) commuteFP f (Hunk line1 [] [] :> p2) = Succeeded (FP f (unsafeCoerceP p2) :> FP f (Hunk line1 [] [])) commuteFP f (Hunk line1 old1 new1 :> Hunk line2 old2 new2) = case commuteHunkLines line1 (length old1) (length new1) line2 (length old2) (length new2) of Just (line2', line1') -> Succeeded (FP f (Hunk line2' old2 new2) :> FP f (Hunk line1' old1 new1)) Nothing -> Failed commuteFP f (Hunk line1 old1 new1 :> TokReplace t o n) = let po = BC.pack o; pn = BC.pack n in case tryTokReplaces t po pn old1 of Nothing -> Failed Just old1' -> case tryTokReplaces t po pn new1 of Nothing -> Failed Just new1' -> Succeeded (FP f (TokReplace t o n) :> FP f (Hunk line1 old1' new1')) commuteFP f (TokReplace t1 o1 n1 :> TokReplace t2 o2 n2) | t1 /= t2 = Failed | o1 == o2 = Failed | n1 == o2 = Failed | o1 == n2 = Failed | n1 == n2 = Failed | otherwise = Succeeded (FP f (TokReplace t2 o2 n2) :> FP f (TokReplace t1 o1 n1)) commuteFP _ _ = Unknown commuteHunkLines :: Int -> Int -> Int -> Int -> Int -> Int -> Maybe (Int, Int) commuteHunkLines line1 len_old1 len_new1 line2 len_old2 len_new2 | line1 + len_new1 < line2 = Just (line2 - len_new1 + len_old1, line1) | line2 + len_old2 < line1 = Just (line2, line1 + len_new2 - len_old2) | len_old2 /= 0 , len_old1 /= 0 , len_new2 /= 0 , len_new1 /= 0 , line1 + len_new1 == line2 = Just (line2 - len_new1 + len_old1, line1) | len_old2 /= 0 , len_old1 /= 0 , len_new2 /= 0 , len_new1 /= 0 , line2 + len_old2 == line1 = Just (line2, line1 + len_new2 - len_old2) | otherwise = Nothing tryTokReplaces :: String -> B.ByteString -> B.ByteString -> [B.ByteString] -> Maybe [B.ByteString] tryTokReplaces t o n = mapM (tryTokReplace t o n) darcs-2.14.5/src/Darcs/Patch/Prim/V1/Core.hs0000644000000000000000000001452107346545000016376 0ustar0000000000000000-- Copyright (C) 2002-2003,2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.Prim.V1.Core ( Prim(..), DirPatchType(..), FilePatchType(..), isIdentity, comparePrim, ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString as B (ByteString) import Darcs.Util.Path ( FileName, fn2fp, fp2fn, normPath ) import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Patch.Debug ( PatchDebug(..) ) import Darcs.Patch.FileHunk ( FileHunk(..), IsHunk(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Permutations () -- for Invert instance of FL import Darcs.Patch.Prim.Class ( PrimConstruct(..), PrimClassify(..) ) data Prim wX wY where Move :: !FileName -> !FileName -> Prim wX wY DP :: !FileName -> !(DirPatchType wX wY) -> Prim wX wY FP :: !FileName -> !(FilePatchType wX wY) -> Prim wX wY ChangePref :: !String -> !String -> !String -> Prim wX wY data FilePatchType wX wY = RmFile | AddFile | Hunk !Int [B.ByteString] [B.ByteString] | TokReplace !String !String !String | Binary B.ByteString B.ByteString deriving (Eq,Ord) data DirPatchType wX wY = RmDir | AddDir deriving (Eq,Ord) instance Eq2 FilePatchType where unsafeCompare a b = a == unsafeCoerceP b instance Eq2 DirPatchType where unsafeCompare a b = a == unsafeCoerceP b isIdentity :: Prim wX wY -> EqCheck wX wY isIdentity (FP _ (Binary old new)) | old == new = unsafeCoerceP IsEq isIdentity (FP _ (Hunk _ old new)) | old == new = unsafeCoerceP IsEq isIdentity (FP _ (TokReplace _ old new)) | old == new = unsafeCoerceP IsEq isIdentity (Move old new) | old == new = unsafeCoerceP IsEq isIdentity _ = NotEq instance PrimClassify Prim where primIsAddfile (FP _ AddFile) = True primIsAddfile _ = False primIsRmfile (FP _ RmFile) = True primIsRmfile _ = False primIsAdddir (DP _ AddDir) = True primIsAdddir _ = False primIsRmdir (DP _ RmDir) = True primIsRmdir _ = False primIsMove (Move _ _) = True primIsMove _ = False primIsHunk (FP _ (Hunk _ _ _)) = True primIsHunk _ = False primIsTokReplace (FP _ (TokReplace _ _ _)) = True primIsTokReplace _ = False primIsBinary (FP _ (Binary _ _)) = True primIsBinary _ = False primIsSetpref (ChangePref _ _ _) = True primIsSetpref _ = False is_filepatch (FP f _) = Just f is_filepatch _ = Nothing evalargs :: (a -> b -> c) -> a -> b -> c evalargs f x y = (f $! x) $! y instance PrimConstruct Prim where addfile f = FP (fp2fn $ nFn f) AddFile rmfile f = FP (fp2fn $ nFn f) RmFile adddir d = DP (fp2fn $ nFn d) AddDir rmdir d = DP (fp2fn $ nFn d) RmDir move f f' = Move (fp2fn $ nFn f) (fp2fn $ nFn f') changepref p f t = ChangePref p f t hunk f line old new = evalargs FP (fp2fn $ nFn f) (Hunk line old new) tokreplace f tokchars old new = evalargs FP (fp2fn $ nFn f) (TokReplace tokchars old new) binary f old new = FP (fp2fn $! nFn f) $ Binary old new primFromHunk (FileHunk fn line before after) = FP fn (Hunk line before after) anIdentity = let fp = "./dummy" in move fp fp nFn :: FilePath -> FilePath nFn f = "./"++(fn2fp $ normPath $ fp2fn f) instance IsHunk Prim where isHunk (FP fn (Hunk line before after)) = Just (FileHunk fn line before after) isHunk _ = Nothing instance Invert Prim where invert (FP f RmFile) = FP f AddFile invert (FP f AddFile) = FP f RmFile invert (FP f (Hunk line old new)) = FP f $ Hunk line new old invert (FP f (TokReplace t o n)) = FP f $ TokReplace t n o invert (FP f (Binary o n)) = FP f $ Binary n o invert (DP d RmDir) = DP d AddDir invert (DP d AddDir) = DP d RmDir invert (Move f f') = Move f' f invert (ChangePref p f t) = ChangePref p t f instance PatchInspect Prim where -- Recurse on everything, these are potentially spoofed patches listTouchedFiles (Move f1 f2) = map fn2fp [f1, f2] listTouchedFiles (FP f _) = [fn2fp f] listTouchedFiles (DP d _) = [fn2fp d] listTouchedFiles (ChangePref _ _ _) = [] hunkMatches f (FP _ (Hunk _ remove add)) = anyMatches remove || anyMatches add where anyMatches = foldr ((||) . f) False hunkMatches _ (FP _ _) = False hunkMatches _ (DP _ _) = False hunkMatches _ (ChangePref _ _ _) = False hunkMatches _ (Move _ _) = False instance PatchDebug Prim instance Eq2 Prim where unsafeCompare (Move a b) (Move c d) = a == c && b == d unsafeCompare (DP d1 p1) (DP d2 p2) = d1 == d2 && p1 `unsafeCompare` p2 unsafeCompare (FP f1 fp1) (FP f2 fp2) = f1 == f2 && fp1 `unsafeCompare` fp2 unsafeCompare (ChangePref a1 b1 c1) (ChangePref a2 b2 c2) = c1 == c2 && b1 == b2 && a1 == a2 unsafeCompare _ _ = False instance Eq (Prim wX wY) where (==) = unsafeCompare -- | 'comparePrim' @p1 p2@ is used to provide an arbitrary ordering between -- @p1@ and @p2@. Basically, identical patches are equal and -- @Move < DP < FP < ChangePref@. -- Everything else is compared in dictionary order of its arguments. comparePrim :: Prim wX wY -> Prim wW wZ -> Ordering comparePrim (Move a b) (Move c d) = compare (a, b) (c, d) comparePrim (Move _ _) _ = LT comparePrim _ (Move _ _) = GT comparePrim (DP d1 p1) (DP d2 p2) = compare (d1, p1) $ unsafeCoerceP (d2, p2) comparePrim (DP _ _) _ = LT comparePrim _ (DP _ _) = GT comparePrim (FP f1 fp1) (FP f2 fp2) = compare (f1, fp1) $ unsafeCoerceP (f2, fp2) comparePrim (FP _ _) _ = LT comparePrim _ (FP _ _) = GT comparePrim (ChangePref a1 b1 c1) (ChangePref a2 b2 c2) = compare (c1, b1, a1) (c2, b2, a2) darcs-2.14.5/src/Darcs/Patch/Prim/V1/Details.hs0000644000000000000000000000155607346545000017077 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.V1.Details () where import Prelude () import Darcs.Prelude import Darcs.Patch.Prim.Class ( PrimDetails(..) ) import Darcs.Patch.Prim.V1.Core ( Prim(..), FilePatchType(..), DirPatchType(..) ) import Darcs.Patch.SummaryData ( SummDetail(..), SummOp(..) ) instance PrimDetails Prim where summarizePrim (FP f (Hunk _ o n)) = [SummFile SummMod f (length o) (length n) 0] summarizePrim (FP f (Binary _ _)) = [SummFile SummMod f 0 0 0] summarizePrim (FP f AddFile) = [SummFile SummAdd f 0 0 0] summarizePrim (FP f RmFile) = [SummFile SummRm f 0 0 0] summarizePrim (FP f (TokReplace{})) = [SummFile SummMod f 0 0 1] summarizePrim (DP d AddDir) = [SummAddDir d] summarizePrim (DP d RmDir) = [SummRmDir d] summarizePrim (Move f1 f2) = [SummMv f1 f2] summarizePrim (ChangePref{}) = [SummNone] darcs-2.14.5/src/Darcs/Patch/Prim/V1/Read.hs0000644000000000000000000001015607346545000016361 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.Prim.V1.Read () where import Prelude () import Darcs.Prelude import Darcs.Patch.Prim.Class ( PrimRead(..), hunk, binary ) import Darcs.Patch.Prim.V1.Core ( Prim(..) , DirPatchType(..) , FilePatchType(..) ) import Darcs.Util.Path ( fn2fp ) import Darcs.Patch.Format ( FileNameFormat ) import Darcs.Patch.Read ( readFileName ) import Darcs.Patch.ReadMonads ( ParserM, takeTillChar, string, int , option, choice, anyChar, char, myLex' , skipSpace, skipWhile, linesStartingWith ) import Darcs.Patch.Witnesses.Sealed ( seal ) import Darcs.Util.ByteString ( fromHex2PS ) import Control.Monad ( liftM ) import qualified Data.ByteString as B ( ByteString, init, tail, concat ) import qualified Data.ByteString.Char8 as BC ( unpack, pack ) instance PrimRead Prim where readPrim fmt = skipSpace >> choice [ return' $ readHunk fmt , return' $ readAddFile fmt , return' $ readAddDir fmt , return' $ readMove fmt , return' $ readRmFile fmt , return' $ readRmDir fmt , return' $ readTok fmt , return' $ readBinary fmt , return' readChangePref ] where return' = liftM seal hunk' :: B.ByteString hunk' = BC.pack "hunk" replace :: B.ByteString replace = BC.pack "replace" binary' :: B.ByteString binary' = BC.pack "binary" addfile :: B.ByteString addfile = BC.pack "addfile" adddir :: B.ByteString adddir = BC.pack "adddir" rmfile :: B.ByteString rmfile = BC.pack "rmfile" rmdir :: B.ByteString rmdir = BC.pack "rmdir" move :: B.ByteString move = BC.pack "move" changepref :: B.ByteString changepref = BC.pack "changepref" readHunk :: ParserM m => FileNameFormat -> m (Prim wX wY) readHunk fmt = do string hunk' fi <- myLex' l <- int have_nl <- skipNewline if have_nl then do _ <- linesStartingWith ' ' -- skipping context old <- linesStartingWith '-' new <- linesStartingWith '+' _ <- linesStartingWith ' ' -- skipping context return $ hunk (fn2fp $ readFileName fmt fi) l old new else return $ hunk (fn2fp $ readFileName fmt fi) l [] [] skipNewline :: ParserM m => m Bool skipNewline = option False (char '\n' >> return True) readTok :: ParserM m => FileNameFormat -> m (Prim wX wY) readTok fmt = do string replace f <- myLex' regstr <- myLex' o <- myLex' n <- myLex' return $ FP (readFileName fmt f) $ TokReplace (BC.unpack (drop_brackets regstr)) (BC.unpack o) (BC.unpack n) where drop_brackets = B.init . B.tail -- * Binary file modification -- -- | Modify a binary file -- -- > binary FILENAME -- > oldhex -- > *HEXHEXHEX -- > ... -- > newhex -- > *HEXHEXHEX -- > ... readBinary :: ParserM m => FileNameFormat -> m (Prim wX wY) readBinary fmt = do string binary' fi <- myLex' _ <- myLex' skipSpace old <- linesStartingWith '*' _ <- myLex' skipSpace new <- linesStartingWith '*' return $ binary (fn2fp $ readFileName fmt fi) (fromHex2PS $ B.concat old) (fromHex2PS $ B.concat new) readAddFile :: ParserM m => FileNameFormat -> m (Prim wX wY) readAddFile fmt = do string addfile f <- myLex' return $ FP (readFileName fmt f) AddFile readRmFile :: ParserM m => FileNameFormat -> m (Prim wX wY) readRmFile fmt = do string rmfile f <- myLex' return $ FP (readFileName fmt f) RmFile readMove :: ParserM m => FileNameFormat -> m (Prim wX wY) readMove fmt = do string move d <- myLex' d' <- myLex' return $ Move (readFileName fmt d) (readFileName fmt d') readChangePref :: ParserM m => m (Prim wX wY) readChangePref = do string changepref p <- myLex' skipWhile (== ' ') _ <- anyChar -- skip newline f <- takeTillChar '\n' _ <- anyChar -- skip newline t <- takeTillChar '\n' return $ ChangePref (BC.unpack p) (BC.unpack f) (BC.unpack t) readAddDir :: ParserM m => FileNameFormat -> m (Prim wX wY) readAddDir fmt = do string adddir f <- myLex' return $ DP (readFileName fmt f) AddDir readRmDir :: ParserM m => FileNameFormat -> m (Prim wX wY) readRmDir fmt = do string rmdir f <- myLex' return $ DP (readFileName fmt f) RmDir darcs-2.14.5/src/Darcs/Patch/Prim/V1/Show.hs0000644000000000000000000001462507346545000016433 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} {-# LANGUAGE ViewPatterns #-} module Darcs.Patch.Prim.V1.Show ( showHunk ) where import Prelude () import Darcs.Prelude import Darcs.Util.ByteString ( fromPS2Hex ) import qualified Data.ByteString as B (ByteString, length, take, drop) import qualified Data.ByteString.Char8 as BC (head) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.FileHunk ( FileHunk(..), showFileHunk ) import Darcs.Patch.Format ( FileNameFormat ) import Darcs.Patch.Show ( formatFileName ) import Darcs.Patch.Permutations () -- for Invert instance of FL import Darcs.Patch.Prim.Class ( PrimShow(..) ) import Darcs.Patch.Prim.V1.Core ( Prim(..), FilePatchType(..), DirPatchType(..) ) import Darcs.Patch.Prim.V1.Details () import Darcs.Patch.Viewing ( showContextHunk ) import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..), ShowDict(..) ) import Darcs.Util.Path ( FileName ) import Darcs.Util.Printer ( Doc, vcat, text, userchunk, invisibleText, invisiblePS, blueText, ($$), (<+>) ) import Darcs.Util.Show ( appPrec, BSWrapper(..) ) import Darcs.Util.Tree ( Tree ) instance Show (Prim wX wY) where showsPrec d (Move fn1 fn2) = showParen (d > appPrec) $ showString "Move " . showsPrec (appPrec + 1) fn1 . showString " " . showsPrec (appPrec + 1) fn2 showsPrec d (DP fn dp) = showParen (d > appPrec) $ showString "DP " . showsPrec (appPrec + 1) fn . showString " " . showsPrec (appPrec + 1) dp showsPrec d (FP fn fp) = showParen (d > appPrec) $ showString "FP " . showsPrec (appPrec + 1) fn . showString " " . showsPrec (appPrec + 1) fp showsPrec d (ChangePref p f t) = showParen (d > appPrec) $ showString "ChangePref " . showsPrec (appPrec + 1) p . showString " " . showsPrec (appPrec + 1) f . showString " " . showsPrec (appPrec + 1) t instance Show2 Prim where showDict2 = ShowDictClass instance Show1 (Prim wX) where showDict1 = ShowDictClass instance Show (FilePatchType wX wY) where showsPrec _ RmFile = showString "RmFile" showsPrec _ AddFile = showString "AddFile" showsPrec d (Hunk line old new) | all ((==1) . B.length) old && all ((==1) . B.length) new = showParen (d > appPrec) $ showString "Hunk " . showsPrec (appPrec + 1) line . showString " " . showsPrecC old . showString " " . showsPrecC new where showsPrecC [] = showString "[]" showsPrecC ss = showParen True $ showString "packStringLetters " . showsPrec (appPrec + 1) (map BC.head ss) showsPrec d (Hunk line old new) = showParen (d > appPrec) $ showString "Hunk " . showsPrec (appPrec + 1) line . showString " " . showsPrec (appPrec + 1) (map BSWrapper old) . showString " " . showsPrec (appPrec + 1) (map BSWrapper new) showsPrec d (TokReplace t old new) = showParen (d > appPrec) $ showString "TokReplace " . showsPrec (appPrec + 1) t . showString " " . showsPrec (appPrec + 1) old . showString " " . showsPrec (appPrec + 1) new -- this case may not work usefully showsPrec d (Binary old new) = showParen (d > appPrec) $ showString "Binary " . showsPrec (appPrec + 1) (BSWrapper old) . showString " " . showsPrec (appPrec + 1) (BSWrapper new) instance Show (DirPatchType wX wY) where showsPrec _ RmDir = showString "RmDir" showsPrec _ AddDir = showString "AddDir" instance ApplyState Prim ~ Tree => PrimShow Prim where showPrim fmt (FP f AddFile) = showAddFile fmt f showPrim fmt (FP f RmFile) = showRmFile fmt f showPrim fmt (FP f (Hunk line old new)) = showHunk fmt f line old new showPrim fmt (FP f (TokReplace t old new)) = showTok fmt f t old new showPrim fmt (FP f (Binary old new)) = showBinary fmt f old new showPrim fmt (DP d AddDir) = showAddDir fmt d showPrim fmt (DP d RmDir) = showRmDir fmt d showPrim fmt (Move f f') = showMove fmt f f' showPrim _ (ChangePref p f t) = showChangePref p f t showPrimCtx fmt (FP f (Hunk line old new)) = showContextHunk fmt (FileHunk f line old new) showPrimCtx fmt p = return $ showPrim fmt p showAddFile :: FileNameFormat -> FileName -> Doc showAddFile fmt f = blueText "addfile" <+> formatFileName fmt f showRmFile :: FileNameFormat -> FileName -> Doc showRmFile fmt f = blueText "rmfile" <+> formatFileName fmt f showMove :: FileNameFormat -> FileName -> FileName -> Doc showMove fmt d d' = blueText "move" <+> formatFileName fmt d <+> formatFileName fmt d' showChangePref :: String -> String -> String -> Doc showChangePref p f t = blueText "changepref" <+> text p $$ userchunk f $$ userchunk t showAddDir :: FileNameFormat -> FileName -> Doc showAddDir fmt d = blueText "adddir" <+> formatFileName fmt d showRmDir :: FileNameFormat -> FileName -> Doc showRmDir fmt d = blueText "rmdir" <+> formatFileName fmt d showHunk :: FileNameFormat -> FileName -> Int -> [B.ByteString] -> [B.ByteString] -> Doc showHunk fmt f line old new = showFileHunk fmt (FileHunk f line old new) showTok :: FileNameFormat -> FileName -> String -> String -> String -> Doc showTok fmt f t o n = blueText "replace" <+> formatFileName fmt f <+> text "[" <> userchunk t <> text "]" <+> userchunk o <+> userchunk n showBinary :: FileNameFormat -> FileName -> B.ByteString -> B.ByteString -> Doc showBinary fmt f o n = blueText "binary" <+> formatFileName fmt f $$ invisibleText "oldhex" $$ vcat (map makeprintable $ breakEvery 78 $ fromPS2Hex o) $$ invisibleText "newhex" $$ vcat (map makeprintable $ breakEvery 78 $ fromPS2Hex n) where makeprintable ps = invisibleText "*" <> invisiblePS ps breakEvery :: Int -> B.ByteString -> [B.ByteString] breakEvery n ps | B.length ps < n = [ps] | otherwise = B.take n ps : breakEvery n (B.drop n ps) darcs-2.14.5/src/Darcs/Patch/Progress.hs0000644000000000000000000000507107346545000016115 0ustar0000000000000000module Darcs.Patch.Progress ( progressRL , progressFL , progressRLShowTags ) where import Prelude () import Darcs.Prelude import System.IO.Unsafe ( unsafePerformIO ) import Darcs.Patch.Info ( justName, isTag ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), lengthRL, lengthFL ) import Darcs.Util.Progress ( minlist, beginTedious, endTedious, progress, progressKeepLatest, tediousSize, finishedOne ) startProgress :: a -> String -> Int -> a startProgress x k len = unsafePerformIO $ do beginTedious k tediousSize k len return x -- | Evaluate an 'FL' list and report progress. progressFL :: String -> FL a wX wY -> FL a wX wY progressFL _ NilFL = NilFL progressFL k xxs@(x :>: xs) = if xxsLen < minlist then xxs else startProgress x k xxsLen :>: pl xs where xxsLen = lengthFL xxs pl :: FL a wX wY -> FL a wX wY pl NilFL = NilFL pl (y :>: NilFL) = unsafePerformIO $ do endTedious k return (y :>: NilFL) pl (y :>: ys) = progress k y :>: pl ys -- | Evaluate an 'RL' list and report progress. progressRL :: String -> RL a wX wY -> RL a wX wY progressRL _ NilRL = NilRL progressRL k xxs@(xs :<: x) = if xxsLen < minlist then xxs else pl xs :<: startProgress x k xxsLen where xxsLen = lengthRL xxs pl :: RL a wX wY -> RL a wX wY pl NilRL = NilRL pl (NilRL:<:y) = unsafePerformIO $ do endTedious k return (NilRL:<:y) pl (ys:<:y) = pl ys :<: progress k y -- | Evaluate an 'RL' list and report progress. In addition to printing -- the number of patches we got, show the name of the last tag we got. progressRLShowTags :: String -> RL (PatchInfoAnd rt p) wX wY -> RL (PatchInfoAnd rt p) wX wY progressRLShowTags _ NilRL = NilRL progressRLShowTags k xxs@(xs :<: x) = if xxsLen < minlist then xxs else pl xs :<: startProgress x k xxsLen where xxsLen = lengthRL xxs pl :: RL (PatchInfoAnd rt p) wX wY -> RL (PatchInfoAnd rt p) wX wY pl NilRL = NilRL pl (NilRL :<: y) = unsafePerformIO $ do endTedious k return (NilRL :<: y) pl (ys :<: y) = if isTag iy then pl ys :<: finishedOne k ("back to "++ justName iy) y else pl ys :<: progressKeepLatest k y where iy = info y darcs-2.14.5/src/Darcs/Patch/Read.hs0000644000000000000000000001236707346545000015172 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.Read ( ReadPatch(..), readPatch, readPatchPartial, bracketedFL, peekfor, readFileName ) where import Prelude () import Darcs.Prelude import Darcs.Util.ByteString ( dropSpace, unpackPSFromUTF8, decodeLocale ) import qualified Data.ByteString as B (ByteString, null) import Darcs.Patch.Bracketed ( Bracketed(..), unBracketedFL ) import Darcs.Util.Path ( FileName, fp2fn, decodeWhite ) import Darcs.Patch.Format ( PatchListFormat(..), ListFormat(..), FileNameFormat(..) ) import Darcs.Patch.ReadMonads (ParserM, parseStrictly, choice, lexChar, lexString, checkConsumes ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL, reverseFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), mapSeal ) import Control.Applicative ( (<|>) ) import Control.Monad ( mzero ) import qualified Data.ByteString.Char8 as BC ( ByteString, pack ) -- | This class is used to decode patches from their binary representation. class ReadPatch p where readPatch' :: ParserM m => m (Sealed (p wX)) readPatchPartial :: ReadPatch p => B.ByteString -> Maybe (Sealed (p wX), B.ByteString) readPatchPartial ps = case parseStrictly readPatch' ps of Just (p, ps') -> Just (p, ps') _ -> Nothing readPatch :: ReadPatch p => B.ByteString -> Maybe (Sealed (p wX)) readPatch ps = case readPatchPartial ps of Just (p, ps') | B.null (dropSpace ps') -> Just p _ -> Nothing instance ReadPatch p => ReadPatch (Bracketed p) where readPatch' = mapSeal Braced <$> bracketedFL readPatch' '{' '}' <|> mapSeal Parens <$> bracketedFL readPatch' '(' ')' <|> mapSeal Singleton <$> readPatch' instance (ReadPatch p, PatchListFormat p) => ReadPatch (FL p) where readPatch' | ListFormatV1 <- patchListFormat :: ListFormat p = mapSeal unBracketedFL <$> readPatch' -- in the V2 format case, we only need to support () on reading, not {} -- for simplicity we just go through the same code path. | ListFormatV2 <- patchListFormat :: ListFormat p = mapSeal unBracketedFL <$> readPatch' | otherwise = read_patches where read_patches :: ParserM m => m (Sealed (FL p wX)) read_patches = do --tracePeek "starting FL read" -- checkConsumes is needed to make sure that something is read, -- to avoid stack overflow when parsing FL (FL p) mp <- (Just <$> checkConsumes readPatch') <|> return Nothing case mp of Just (Sealed p) -> do --tracePeek "found one patch" Sealed ps <- read_patches return $ Sealed (p:>:ps) Nothing -> return $ Sealed NilFL -- tracePeek x = do y <- peekInput -- traceDoc (greenText x $$ greenText (show $ sal_to_string y)) return () instance (ReadPatch p, PatchListFormat p) => ReadPatch (RL p) where readPatch' = mapSeal reverseFL <$> readPatch' {-# INLINE bracketedFL #-} bracketedFL :: forall p m wX . (ParserM m) => (forall wY . m (Sealed (p wY))) -> Char -> Char -> m (Sealed (FL p wX)) bracketedFL parser pre post = peekforc pre bfl mzero where bfl :: forall wZ . m (Sealed (FL p wZ)) bfl = peekforc post (return $ Sealed NilFL) (do Sealed p <- parser Sealed ps <- bfl return $ Sealed (p:>:ps)) {-# INLINE peekforc #-} peekforc :: ParserM m => Char -> m a -> m a -> m a peekforc c ifstr ifnot = choice [ lexChar c >> ifstr , ifnot ] peekfor :: ParserM m => BC.ByteString -> m a -> m a -> m a peekfor ps ifstr ifnot = choice [ do lexString ps ifstr , ifnot ] {-# INLINE peekfor #-} -- See also Darcs.Patch.Show.formatFileName. readFileName :: FileNameFormat -> B.ByteString -> FileName readFileName OldFormat = fp2fn . decodeWhite . decodeLocale . BC.pack . unpackPSFromUTF8 readFileName NewFormat = fp2fn . decodeWhite . decodeLocale readFileName UserFormat = error "readFileName called with UserFormat" darcs-2.14.5/src/Darcs/Patch/ReadMonads.hs0000644000000000000000000002441407346545000016330 0ustar0000000000000000-- | This module defines our parsing monad. In the past there have been lazy -- and strict parsers in this module. Currently we have only the strict -- variant and it is used for parsing patch files. module Darcs.Patch.ReadMonads (ParserM, Darcs.Patch.ReadMonads.take, parse, parseStrictly, char, int, option, choice, skipSpace, skipWhile, string, lexChar, lexString, lexEof, takeTillChar, myLex', anyChar, endOfInput, takeTill, checkConsumes, linesStartingWith, linesStartingWithEndingWith) where import Prelude () import Darcs.Prelude import Darcs.Util.ByteString ( dropSpace, breakSpace, breakFirstPS, readIntPS, breakLastPS ) import qualified Data.ByteString as B (null, drop, length, tail, empty, ByteString) import qualified Data.ByteString.Char8 as BC ( uncons, dropWhile, break , splitAt, length, head ) import Control.Applicative ( Alternative(..) ) import Data.Foldable ( asum ) import Control.Monad ( MonadPlus(..) ) -- | 'lexChar' checks if the next space delimited token from -- the input stream matches a specific 'Char'. -- Uses 'Maybe' inside 'ParserM' to handle failed matches, so -- that it always returns () on success. lexChar :: ParserM m => Char -> m () lexChar c = do skipSpace char c return () -- | 'lexString' fetches the next whitespace delimited token from -- from the input and checks if it matches the 'ByteString' input. -- Uses 'Maybe' inside 'ParserM' to handle failed matches, so -- that it always returns () on success. lexString :: ParserM m => B.ByteString -> m () lexString str = work $ \s -> case myLex s of Just (xs :*: ys) | xs == str -> Just (() :*: ys) _ -> Nothing -- | Only succeeds if the characters in the input exactly match @str@. string :: ParserM m => B.ByteString -> m () string str = work $ \s -> case BC.splitAt (BC.length str) s of (h, t) | h == str -> Just (() :*: t) _ -> Nothing -- | 'lexEof' looks for optional spaces followed by the end of input. -- Uses 'Maybe' inside 'ParserM' to handle failed matches, so -- that it always returns () on success. lexEof :: ParserM m => m () lexEof = work $ \s -> if B.null (dropSpace s) then Just (() :*: B.empty) else Nothing -- | 'myLex' drops leading spaces and then breaks the string at the -- next space. Returns 'Nothing' when the string is empty after -- dropping leading spaces, otherwise it returns the first sequence -- of non-spaces and the remainder of the input. myLex :: B.ByteString -> Maybe (ParserState B.ByteString) myLex s = let s' = dropSpace s in if B.null s' then Nothing else Just $ stuple $ breakSpace s' -- | Like 'myLex' except that it is in ParserM myLex' :: ParserM m => m B.ByteString myLex' = work myLex -- | Accepts the next character and returns it. Only fails at end of -- input. anyChar :: ParserM m => m Char anyChar = work $ \s -> stuple <$> BC.uncons s -- | Only succeeds at end of input, consumes no characters. endOfInput :: ParserM m => m () endOfInput = work $ \s -> if B.null s then Just (() :*: s) else Nothing -- | Accepts only the specified character. Consumes a character, if -- available. char :: ParserM m => Char -> m () char c = work $ \s -> case BC.uncons s of Just (c', s') | c == c' -> Just (() :*: s') _ -> Nothing -- | Parse an integer and return it. Skips leading whitespaces and -- | uses the efficient ByteString readInt. int :: ParserM m => m Int int = work $ \s -> stuple <$> readIntPS s -- | Discards spaces until a non-space character is encountered. -- Always succeeds. skipSpace :: ParserM m => m () skipSpace = alterInput dropSpace -- | Discards any characters as long as @p@ returns True. Always -- | succeeds. skipWhile :: ParserM m => (Char -> Bool) -> m () skipWhile p = alterInput (BC.dropWhile p) -- | Takes characters while @p@ returns True. Always succeeds. takeTill :: ParserM m => (Char -> Bool) -> m B.ByteString takeTill p = work $ \s -> Just $ stuple (BC.break p s) -- | Equivalent to @takeTill (==c)@, except that it is optimized for -- | the equality case. takeTillChar :: ParserM m => Char -> m B.ByteString takeTillChar c = work $ \s -> Just $ stuple (BC.break (==c) s) -- | Takes exactly @n@ bytes, or fails. take :: ParserM m => Int -> m B.ByteString take n = work $ \s -> if B.length s >= n then Just $ stuple $ BC.splitAt n s else Nothing -- | This is a highly optimized way to read lines that start with a -- particular character. To implement this efficiently we need access -- to the parser's internal state. If this is implemented in terms of -- the other primitives for the parser it requires us to consume one -- character at a time. That leads to @(>>=)@ wasting significant -- time. linesStartingWith :: ParserM m => Char -> m [B.ByteString] linesStartingWith c = work $ linesStartingWith' c -- | Helper function for 'linesStartingWith'. linesStartingWith' :: Char -> B.ByteString -> Maybe (ParserState [B.ByteString]) linesStartingWith' c thes = Just (lsw [] thes) where lsw acc s | B.null s || BC.head s /= c = reverse acc :*: s lsw acc s = let s' = B.tail s in case breakFirstPS '\n' s' of Just (l, r) -> lsw (l:acc) r Nothing -> reverse (s':acc) :*: B.empty -- | This is a highly optimized way to read lines that start with a -- particular character, and stops when it reaches a particular | -- character. See 'linesStartingWith' for details on why this | -- defined here as a primitive. linesStartingWithEndingWith :: ParserM m => Char -> Char -> m [B.ByteString] linesStartingWithEndingWith st en = work $ linesStartingWithEndingWith' st en -- | Helper function for 'linesStartingWithEndingWith'. linesStartingWithEndingWith' :: Char -> Char -> B.ByteString -> Maybe (ParserState [B.ByteString]) linesStartingWithEndingWith' st en = lswew where lswew x | B.null x = Nothing | BC.head x == en = Just $ [] :*: B.tail x | BC.head x /= st = Nothing | otherwise = case BC.break ('\n' ==) $ B.tail x of (l,r) -> case lswew $ B.tail r of Just (ls :*: r') -> Just ((l:ls) :*: r') Nothing -> case breakLastPS en l of Just (l2,_) -> Just ([l2] :*: B.drop (B.length l2+2) x) Nothing -> Nothing -- | Applies a function to the input stream and discards the -- result of the function. alterInput :: ParserM m => (B.ByteString -> B.ByteString) -> m () alterInput f = work (\s -> Just (() :*: f s)) -- | If @p@ fails it returns @x@, otherwise it returns the result of @p@. option :: Alternative f => a -> f a -> f a option x p = p <|> pure x -- | Attempts each option until one succeeds. choice :: Alternative f => [f a] -> f a choice = asum -- |Ensure that a parser consumes input when producing a result -- Causes the initial state of the input stream to be held on to while the -- parser runs, so use with caution. checkConsumes :: ParserM m => m a -> m a checkConsumes parser = do x <- B.length <$> peekInput res <- parser x' <- B.length <$> peekInput if x' < x then return res else mzero class (Functor m, Applicative m, Alternative m, Monad m, MonadPlus m) => ParserM m where -- | Applies a parsing function inside the 'ParserM' monad. work :: (B.ByteString -> Maybe (ParserState a)) -> m a -- | Allows for the inspection of the input that is yet to be parsed. peekInput :: m B.ByteString -- | Run the parser parse :: m a -> B.ByteString -> Maybe (a, B.ByteString) ----- Strict Monad ----- -- | 'parseStrictly' applies the parser functions to a string -- and checks that each parser produced a result as it goes. -- The strictness is in the 'ParserM' instance for 'SM'. parseStrictly :: SM a -> B.ByteString -> Maybe (a, B.ByteString) parseStrictly (SM f) s = case f s of Just (a :*: r) -> Just (a, r) _ -> Nothing -- | ParserState represents the internal state of the parser. We make it -- strict and specialize it on ByteString. This is purely to help GHC -- optimize. If performance were not a concern, it could be replaced -- with @(a, ByteString)@. data ParserState a = !a :*: !B.ByteString -- | Convert from a lazy tuple to a strict tuple. stuple :: (a, B.ByteString) -> ParserState a stuple (a, b) = a :*: b -- | 'SM' is the Strict Monad for parsing. newtype SM a = SM (B.ByteString -> Maybe (ParserState a)) bindSM :: SM a -> (a -> SM b) -> SM b bindSM (SM m) k = SM $ \s -> case m s of Nothing -> Nothing Just (x :*: s') -> case k x of SM y -> y s' {-# INLINE bindSM #-} returnSM :: a -> SM a returnSM x = SM (\s -> Just (x :*: s)) {-# INLINE returnSM #-} failSM :: String -> SM a failSM _ = SM (\_ -> Nothing) {-# INLINE failSM #-} instance Monad SM where (>>=) = bindSM return = returnSM instance ParserM SM where work = SM peekInput = SM $ \s -> Just (s :*: s) parse = parseStrictly -- The following instances allow us to use more conventional -- interfaces provided by other parser libraries. The instances are -- defined using bindSM, returnSM, and failSM to avoid any infinite, -- or even unneccessary, recursion of instances between between -- ParserM and Monad. Other recursive uses will be fine, such as -- (<|>) = mplus. instance MonadPlus SM where mzero = failSM "" -- | Over using mplus can lead to space leaks. It's best to push -- the use of mplus as far down as possible, because until the the -- first parameter completes, we must hold on to the input. mplus (SM a) (SM b) = SM $ \s -> case a s of Nothing -> b s r -> r instance Functor SM where fmap f m = m `bindSM` (returnSM . f) instance Applicative SM where pure = returnSM a <*> b = a `bindSM` \c -> b `bindSM` \d -> returnSM (c d) instance Alternative SM where empty = failSM "" (<|>) = mplus darcs-2.14.5/src/Darcs/Patch/Rebase.hs0000644000000000000000000001461507346545000015516 0ustar0000000000000000-- Copyright (C) 2009 Ganesh Sittampalam -- -- BSD3 module Darcs.Patch.Rebase ( takeHeadRebase , takeHeadRebaseFL , takeAnyRebase , takeAnyRebaseAndTrailingPatches , dropAnyRebase ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Named.Wrapped ( WrappedNamed(RebaseP) ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, hopefully ) import Darcs.Patch.Rebase.Container ( Suspended(..) ) import Darcs.Patch.RepoType ( RepoType(..) , RebaseType(..) , IsRepoType(..) , SRepoType(..) , SRebaseType(..) ) import Darcs.Patch.Set ( PatchSet(..) ) import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Sealed {- Notes Note [Rebase representation] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The entire rebase state is stored in a single Suspended patch (see Darcs.Patch.Rebase.Container). This is both unnatural and inefficient: - Unnatural because the rebase state is not really a patch and treating it as one requires various hacks: - It has to be given a fake name: see mkRebase - Since 'Named p' actually contains 'FL p', we have to assume/assert that the FL either contains a sequence of Normals or a single Suspended - When 'Named ps' commutes past 'Named (Suspended items :> NilFL)', we need to inject the name from 'Named ps' into 'items', which is a layering violation: see Darcs.Patch.Rebase.NameHack - We need to hide the patch in the UI: see Darcs.Patch.MaybeInternal - We need a conditional hook so that amend-record can change the Suspended patch itself: see Darcs.Patch.Rebase.Recontext (something like this might be necessary no matter what the representation) - Inefficient because we need to write the entire rebase state out each time, even though most operations will only affect a small portion near the beginning. - This also means that we need to commute the rebase patch back to the head of the repo lazily: we only do so when a rebase operation requires it. Otherwise, pulling in 100 patches would entail writing out the entire rebase patch to disk 100 times. The obvious alternative is to store the rebase state at the repository level, using inventories in some appropriate way. The main reason this wasn't done is that the repository handling code is quite fragile and hard to modify safely. Also, rebase relies heavily on witnesses to check correctness, and the witnesses on the Repository type are not as reliable as those on patch types, partly because of the cruft in the repository code, and partly because it's inherently harder to track witnesses when the objects being manipulated are stored on disk and being changed imperatively. If and when the repository code becomes easier to work with, rebase should be changed accordingly. -} -- | Given the repository contents, get the rebase container patch, and its -- contents. The rebase patch can be anywhere in the repository and is returned -- without being commuted to the end. takeAnyRebase :: PatchSet ('RepoType 'IsRebase) p wA wB -> (Sealed2 (PatchInfoAnd ('RepoType 'IsRebase) p), Sealed2 (Suspended p)) takeAnyRebase (PatchSet _ NilRL) = -- it should never be behind a tag so we can stop now bug "internal error: no suspended patch found" takeAnyRebase (PatchSet pss (ps :<: p)) | RebaseP _ rs <- hopefully p = (Sealed2 p, Sealed2 rs) | otherwise = takeAnyRebase (PatchSet pss ps) -- | Given the repository contents, get the rebase container patch, its -- contents, and the rest of the repository contents. The rebase patch can be -- anywhere in the repository and is returned without being commuted to the end. takeAnyRebaseAndTrailingPatches :: PatchSet ('RepoType 'IsRebase) p wA wB -> FlippedSeal (PatchInfoAnd ('RepoType 'IsRebase) p :> RL (PatchInfoAnd ('RepoType 'IsRebase) p)) wB takeAnyRebaseAndTrailingPatches (PatchSet _ NilRL) = -- it should never be behind a tag so we can stop now bug "internal error: no suspended patch found" takeAnyRebaseAndTrailingPatches (PatchSet pss (ps :<: p)) | RebaseP _ _ <- hopefully p = FlippedSeal (p :> NilRL) | otherwise = case takeAnyRebaseAndTrailingPatches (PatchSet pss ps) of FlippedSeal (r :> ps') -> FlippedSeal (r :> (ps' :<: p)) -- | Remove the rebase patch from a 'PatchSet'. dropAnyRebase :: forall rt p wA wB. IsRepoType rt => PatchSet rt p wA wB -> PatchSet rt p wA wB dropAnyRebase ps@(PatchSet tags patches) = case singletonRepoType::SRepoType rt of SRepoType SNoRebase -> ps SRepoType SIsRebase -> PatchSet tags (dropRebaseRL patches) -- | Remove the rebase patch from an 'RL' of patches. dropRebaseRL :: RL (PatchInfoAnd ('RepoType 'IsRebase) p) wA wB -> RL (PatchInfoAnd ('RepoType 'IsRebase) p) wA wB dropRebaseRL NilRL = bug "internal error: no suspended patch found" dropRebaseRL (ps :<: p) | RebaseP _ _ <- hopefully p = ps | otherwise = dropRebaseRL ps :<: p -- | Given the repository contents, get the rebase container patch, its -- contents, and the rest of the repository contents. The rebase patch must be -- at the head of the repository. takeHeadRebase :: PatchSet ('RepoType 'IsRebase) p wA wB -> (PatchInfoAnd ('RepoType 'IsRebase) p wB wB, Suspended p wB wB, PatchSet ('RepoType 'IsRebase) p wA wB) takeHeadRebase (PatchSet pss (ps :<: p)) | RebaseP _ rs <- hopefully p = (p, rs, PatchSet pss ps) takeHeadRebase _ = bug "internal error: must have a rebase container patch at end of repository" -- | Same as 'takeHeadRebase' but for an 'RL' of patches. takeHeadRebaseRL :: RL (PatchInfoAnd ('RepoType 'IsRebase) p) wA wB -> (PatchInfoAnd ('RepoType 'IsRebase) p wB wB, Suspended p wB wB, RL (PatchInfoAnd ('RepoType 'IsRebase) p) wA wB) takeHeadRebaseRL (ps :<: p) | RebaseP _ rs <- hopefully p = (p, rs, ps) takeHeadRebaseRL _ = bug "internal error: must have a suspended patch at end of repository" -- | Same as 'takeHeadRebase' but for an 'FL' of patches. takeHeadRebaseFL :: FL (PatchInfoAnd ('RepoType 'IsRebase) p) wA wB -> (PatchInfoAnd ('RepoType 'IsRebase) p wB wB, Suspended p wB wB, FL (PatchInfoAnd ('RepoType 'IsRebase) p) wA wB) takeHeadRebaseFL ps = let (a, b, c) = takeHeadRebaseRL (reverseFL ps) in (a, b, reverseRL c) darcs-2.14.5/src/Darcs/Patch/Rebase/0000755000000000000000000000000007346545000015153 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/Rebase/Container.hs0000644000000000000000000001743507346545000017443 0ustar0000000000000000{-# LANGUAGE UndecidableInstances, StandaloneDeriving #-} module Darcs.Patch.Rebase.Container ( Suspended(..) , countToEdit, simplifyPush, simplifyPushes , addFixupsToSuspended, removeFixupsFromSuspended ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Conflict ( Conflict(..), CommuteNoConflicts(..) ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.FileHunk ( IsHunk(..) ) import Darcs.Patch.Format ( PatchListFormat(..) ) import Darcs.Patch.Invert ( invert ) import Darcs.Patch.Named ( Named ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.Show ( ShowPatch(..) ) import Darcs.Patch.Prim ( PrimPatchBase(..), FromPrim(..), FromPrim(..) ) import Darcs.Patch.Read ( bracketedFL ) import Darcs.Patch.Rebase.Fixup ( RebaseFixup(..), namedToFixups ) import Darcs.Patch.Rebase.Item ( RebaseItem(..) ) import qualified Darcs.Patch.Rebase.Item as Item ( countToEdit, simplifyPush, simplifyPushes ) import Darcs.Patch.Repair ( Check(..), Repair(..), RepairToFL(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..) ) import Darcs.Patch.ReadMonads ( lexString, myLex' ) import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..) , ShowDict(ShowDictClass) ) import Darcs.Util.Printer ( vcat, text, blueText, ($$), (<+>) ) import qualified Darcs.Util.Diff as D ( DiffAlgorithm(MyersDiff) ) import Control.Applicative ( (<|>) ) import Control.Arrow ( (***), second ) import Control.Monad ( when ) import Data.Maybe ( catMaybes ) import qualified Data.ByteString.Char8 as BC ( pack ) -- TODO: move some of the docs of types to individual constructors -- once http://trac.haskell.org/haddock/ticket/43 is fixed. -- |A patch that lives in a repository where a rebase is in -- progress. Such a repository will consist of @Normal@ patches -- along with exactly one @Suspended@ patch. -- -- Most rebase operations will require the @Suspended@ patch -- to be at the end of the repository. -- -- @Normal@ represents a normal patch within a respository where a -- rebase is in progress. @Normal p@ is given the same on-disk -- representation as @p@, so a repository can be switched into -- and out of rebasing mode simply by adding or removing a -- @Suspended@ patch and setting the appropriate format flag. -- -- The single @Suspended@ patch contains the entire rebase -- state, in the form of 'RebaseItem's. -- -- Note that the witnesses are such that the @Suspended@ -- patch has no effect on the context of the rest of the -- repository; in a sense the patches within it are -- dangling off to one side from the main repository. -- -- See Note [Rebase representation] in the 'Darcs.Patch.Rebase' for -- a discussion of the design choice to embed the rebase state in a -- single patch. data Suspended p wX wY where Items :: FL (RebaseItem p) wX wY -> Suspended p wX wX deriving instance (Show2 p, Show2 (PrimOf p)) => Show (Suspended p wX wY) instance (Show2 p, Show2 (PrimOf p)) => Show1 (Suspended p wX) where showDict1 = ShowDictClass instance (Show2 p, Show2 (PrimOf p)) => Show2 (Suspended p) where showDict2 = ShowDictClass instance (PrimPatchBase p, PatchInspect p) => PatchInspect (Suspended p) where listTouchedFiles (Items ps) = listTouchedFiles ps hunkMatches f (Items ps) = hunkMatches f ps instance Effect (Suspended p) where effect (Items _) = NilFL instance Conflict p => Conflict (Suspended p) where resolveConflicts _ = [] conflictedEffect _ = [] instance Apply (Suspended p) where type ApplyState (Suspended p) = ApplyState p apply _ = return () instance (PrimPatchBase p, PatchListFormat p, ShowPatchBasic p) => ShowPatchBasic (Suspended p) where showPatch f (Items ps) = blueText "rebase" <+> text "0.0" <+> blueText "{" $$ vcat (mapFL (showPatch f) ps) $$ blueText "}" instance (PrimPatchBase p, PatchListFormat p, Apply p, CommuteNoConflicts p, Conflict p, IsHunk p, ShowPatch p) => ShowPatch (Suspended p) where summary (Items ps) = summaryFL ps summaryFL ps = vcat (mapFL summary ps) instance PrimPatchBase p => PrimPatchBase (Suspended p) where type PrimOf (Suspended p) = PrimOf p instance (PrimPatchBase p, PatchListFormat p, ReadPatch p) => ReadPatch (Suspended p) where readPatch' = do lexString (BC.pack "rebase") version <- myLex' when (version /= BC.pack "0.0") $ error $ "can't handle rebase version " ++ show version (lexString (BC.pack "{}") >> return (seal (Items NilFL))) <|> (unseal (Sealed . Items) <$> bracketedFL readPatch' '{' '}') instance Check p => Check (Suspended p) where isInconsistent (Items ps) = case catMaybes (mapFL isInconsistent ps) of [] -> Nothing xs -> Just (vcat xs) instance Repair (Suspended p) where applyAndTryToFix (Items ps) = -- TODO: ideally we would apply ps in a sandbox to check the individual patches -- are consistent with each other. return . fmap (unlines *** Items) $ repairInternal ps instance RepairToFL (Suspended p) where applyAndTryToFixFL s = fmap (second $ (:>: NilFL)) <$> applyAndTryToFix s -- Just repair the internals of the patch, without applying it to anything -- or checking against an external context. -- Included for the internal implementation of applyAndTryToFixFL for Rebasing, -- consider either generalising it for use everywhere, or removing once -- the implementation works in a sandbox and thus can use the "full" Repair on the -- contained patches. class RepairInternalFL p where repairInternalFL :: p wX wY -> Maybe ([String], FL p wX wY) class RepairInternal p where repairInternal :: p wX wY -> Maybe ([String], p wX wY) instance RepairInternalFL p => RepairInternal (FL p) where repairInternal NilFL = Nothing repairInternal (x :>: ys) = case (repairInternalFL x, repairInternal ys) of (Nothing , Nothing) -> Nothing (Just (e, rxs), Nothing) -> Just (e , rxs +>+ ys ) (Nothing , Just (e', rys)) -> Just (e' , x :>: rys) (Just (e, rxs), Just (e', rys)) -> Just (e ++ e', rxs +>+ rys) instance RepairInternalFL (RebaseItem p) where repairInternalFL (ToEdit _) = Nothing repairInternalFL (Fixup p) = fmap (second $ mapFL_FL Fixup) $ repairInternalFL p instance RepairInternalFL (RebaseFixup p) where repairInternalFL (PrimFixup _) = Nothing repairInternalFL (NameFixup _) = Nothing countToEdit :: Suspended p wX wY -> Int countToEdit (Items ps) = Item.countToEdit ps onSuspended :: (forall wZ . FL (RebaseItem p) wY wZ -> Sealed (FL (RebaseItem p) wX)) -> Suspended p wY wY -> Suspended p wX wX onSuspended f (Items ps) = unseal Items (f ps) -- |add fixups for the name and effect of a patch to a 'Suspended' addFixupsToSuspended :: (PrimPatchBase p, Commute p, FromPrim p, Effect p) => Named p wX wY -> Suspended p wY wY -> Suspended p wX wX addFixupsToSuspended p = simplifyPushes D.MyersDiff (namedToFixups p) -- |remove fixups (actually, add their inverse) for the name and effect of a patch to a 'Suspended' removeFixupsFromSuspended :: (PrimPatchBase p, Commute p, FromPrim p, Effect p) => Named p wX wY -> Suspended p wX wX -> Suspended p wY wY removeFixupsFromSuspended p = simplifyPushes D.MyersDiff (invert (namedToFixups p)) simplifyPush :: (PrimPatchBase p, Commute p, FromPrim p, Effect p) => D.DiffAlgorithm -> RebaseFixup p wX wY -> Suspended p wY wY -> Suspended p wX wX simplifyPush da fixups = onSuspended (Item.simplifyPush da fixups) simplifyPushes :: (PrimPatchBase p, Commute p, FromPrim p, Effect p) => D.DiffAlgorithm -> FL (RebaseFixup p) wX wY -> Suspended p wY wY -> Suspended p wX wX simplifyPushes da fixups = onSuspended (Item.simplifyPushes da fixups) darcs-2.14.5/src/Darcs/Patch/Rebase/Fixup.hs0000644000000000000000000001467407346545000016616 0ustar0000000000000000-- Copyright (C) 2011-2 Ganesh Sittampalam -- -- BSD3 {-# LANGUAGE UndecidableInstances #-} module Darcs.Patch.Rebase.Fixup ( RebaseFixup(..) , commuteNamedFixup, commuteFixupNamed, commuteNamedFixups , flToNamesPrims, namedToFixups ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute(..), selfCommuter ) import Darcs.Patch.CommuteFn ( totalCommuterIdFL ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.Prim ( FromPrim(..) ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Named ( Named(..), commuterNamedId, commuterIdNamed ) import Darcs.Patch.Prim ( PrimPatchBase(..), PrimPatch ) import Darcs.Patch.Rebase.Name ( RebaseName(..) , commuteNamedName, commuteNameNamed , commutePrimName, commuteNamePrim ) import Darcs.Patch.Witnesses.Eq ( Eq2(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), mapFL_FL, (:>)(..), (+>+) ) import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..), showsPrec2 , ShowDict(ShowDictClass), appPrec ) -- |A single rebase fixup, needed to ensure that the actual patches -- being stored in the rebase state have the correct context. data RebaseFixup p wX wY where PrimFixup :: PrimPatch (PrimOf p) => PrimOf p wX wY -> RebaseFixup p wX wY NameFixup :: RebaseName p wX wY -> RebaseFixup p wX wY namedToFixups :: (PrimPatch (PrimOf p), Effect p) => Named p wX wY -> FL (RebaseFixup p) wX wY namedToFixups (NamedP p _ contents) = NameFixup (AddName p) :>: mapFL_FL PrimFixup (effect contents) instance Show2 (PrimOf p) => Show (RebaseFixup p wX wY) where showsPrec d (PrimFixup p) = showParen (d > appPrec) $ showString "PrimFixup " . showsPrec2 (appPrec + 1) p showsPrec d (NameFixup p) = showParen (d > appPrec) $ showString "NameFixup " . showsPrec2 (appPrec + 1) p instance Show2 (PrimOf p) => Show1 (RebaseFixup p wX) where showDict1 = ShowDictClass instance Show2 (PrimOf p) => Show2 (RebaseFixup p) where showDict2 = ShowDictClass instance PrimPatchBase p => PrimPatchBase (RebaseFixup p) where type PrimOf (RebaseFixup p) = PrimOf p instance (PrimPatchBase p, ApplyState p ~ ApplyState (PrimOf p)) => Apply (RebaseFixup p) where type ApplyState (RebaseFixup p) = ApplyState p apply (PrimFixup p) = apply p apply (NameFixup p) = apply p instance Effect (RebaseFixup p) where effect (PrimFixup p) = p :>: NilFL effect (NameFixup p) = effect p instance Eq2 (PrimOf p) => Eq2 (RebaseFixup p) where PrimFixup p1 `unsafeCompare` PrimFixup p2 = p1 `unsafeCompare` p2 PrimFixup _ `unsafeCompare` _ = False _ `unsafeCompare` PrimFixup _ = False NameFixup n1 `unsafeCompare` NameFixup n2 = n1 `unsafeCompare` n2 -- NameFixup _ `unsafeCompare` _ = False -- _ `unsafeCompare` NameFixup _ = False instance Invert (PrimOf p) => Invert (RebaseFixup p) where invert (PrimFixup p) = PrimFixup (invert p) invert (NameFixup n) = NameFixup (invert n) instance PatchInspect (PrimOf p) => PatchInspect (RebaseFixup p) where listTouchedFiles (PrimFixup p) = listTouchedFiles p listTouchedFiles (NameFixup n) = listTouchedFiles n hunkMatches f (PrimFixup p) = hunkMatches f p hunkMatches f (NameFixup n) = hunkMatches f n instance PrimPatchBase p => Commute (RebaseFixup p) where commute (PrimFixup p :> PrimFixup q) = do q' :> p' <- commute (p :> q) return (PrimFixup q' :> PrimFixup p') commute (NameFixup p :> NameFixup q) = do q' :> p' <- commute (p :> q) return (NameFixup q' :> NameFixup p') commute (PrimFixup p :> NameFixup q) = do q' :> p' <- return $ commutePrimName (p :> q) return (NameFixup q' :> PrimFixup p') commute (NameFixup p :> PrimFixup q) = do q' :> p' <- return $ commuteNamePrim (p :> q) return (PrimFixup q' :> NameFixup p') -- |Split a sequence of fixups into names and prims flToNamesPrims :: PrimPatchBase p => FL (RebaseFixup p) wX wY -> (FL (RebaseName p) :> FL (PrimOf p)) wX wY flToNamesPrims NilFL = NilFL :> NilFL flToNamesPrims (NameFixup n :>: fs) = case flToNamesPrims fs of names :> prims -> (n :>: names) :> prims flToNamesPrims (PrimFixup p :>: fs) = case flToNamesPrims fs of names :> prims -> case totalCommuterIdFL commutePrimName (p :> names) of names' :> p' -> names' :> (p' :>: prims) -- Note that this produces a list result because of the need to use effect to -- extract the result. -- Some general infrastructure for commuting p with PrimOf p would be helpful here, commuteNamedPrim :: (FromPrim p, Effect p, Commute p) => (Named p :> PrimOf p) wX wY -> Maybe ((FL (PrimOf p) :> Named p) wX wY) commuteNamedPrim (p :> q) = do q' :> p' <- commuterNamedId selfCommuter (p :> fromPrim q) return (effect q' :> p') commutePrimNamed :: (FromPrim p, Effect p, Commute p) => (PrimOf p :> Named p) wX wY -> Maybe ((Named p :> FL (PrimOf p)) wX wY) commutePrimNamed (p :> q) = do q' :> p' <- commuterIdNamed selfCommuter (fromPrim p :> q) return (q' :> effect p') commuteNamedFixup :: (FromPrim p, Effect p, Commute p, Invert p) => (Named p :> RebaseFixup p) wX wY -> Maybe ((FL (RebaseFixup p) :> Named p) wX wY) commuteNamedFixup (p :> PrimFixup q) = do qs' :> p' <- commuteNamedPrim (p :> q) return (mapFL_FL PrimFixup qs' :> p') commuteNamedFixup (p :> NameFixup n) = do n' :> p' <- commuteNamedName (p :> n) return ((NameFixup n' :>: NilFL) :> p') commuteNamedFixups :: (FromPrim p, Effect p, Commute p, Invert p) => (Named p :> FL (RebaseFixup p)) wX wY -> Maybe ((FL (RebaseFixup p) :> Named p) wX wY) commuteNamedFixups (p :> NilFL) = return (NilFL :> p) commuteNamedFixups (p :> (q :>: rs)) = do qs' :> p' <- commuteNamedFixup (p :> q) rs' :> p'' <- commuteNamedFixups (p' :> rs) return ((qs' +>+ rs') :> p'') commuteFixupNamed :: (FromPrim p, Effect p, Commute p, Invert p) => (RebaseFixup p :> Named p) wX wY -> Maybe ((Named p :> FL (RebaseFixup p)) wX wY) commuteFixupNamed (PrimFixup p :> q) = do q' :> ps' <- commutePrimNamed (p :> q) return (q' :> mapFL_FL PrimFixup ps') commuteFixupNamed (NameFixup n :> q) = do q' :> n' <- commuteNameNamed (n :> q) return (q' :> (NameFixup n' :>: NilFL)) darcs-2.14.5/src/Darcs/Patch/Rebase/Item.hs0000644000000000000000000002103607346545000016407 0ustar0000000000000000{-# LANGUAGE UndecidableInstances #-} module Darcs.Patch.Rebase.Item ( RebaseItem(..) , simplifyPush, simplifyPushes , countToEdit ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Commute ( selfCommuter ) import Darcs.Patch.Conflict ( Conflict(..), CommuteNoConflicts(..) ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.FileHunk ( IsHunk(..) ) import Darcs.Patch.Format ( PatchListFormat(..) ) import Darcs.Patch.Named ( Named(..), commuterIdNamed ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.Show ( ShowPatch(..) ) import Darcs.Patch.Prim ( PrimPatchBase, PrimOf, FromPrim(..), FromPrim(..), canonizeFL ) import Darcs.Patch.Rebase.Fixup ( RebaseFixup(..) ) import Darcs.Patch.Rebase.Name ( RebaseName(..) , commutePrimName, commuteNamePrim , canonizeNamePair ) import Darcs.Patch.Repair ( Check(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..) ) import Darcs.Patch.Summary ( plainSummaryPrim ) import Darcs.Patch.ReadMonads ( ParserM, lexString ) import Darcs.Patch.Witnesses.Eq import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..), showsPrec2 , ShowDict(ShowDictClass), appPrec ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import qualified Darcs.Util.Diff as D ( DiffAlgorithm ) import Darcs.Util.Printer ( vcat, blueText, ($$), (<+>) ) import Control.Applicative ( (<|>) ) import qualified Data.ByteString as B ( ByteString ) import qualified Data.ByteString.Char8 as BC ( pack ) -- |A single item in the rebase state consists of either -- a patch that is being edited, or a fixup that adjusts -- the context so that a subsequent patch that is being edited -- \"makes sense\". -- -- @ToEdit@ holds a patch that is being edited. The name ('PatchInfo') of -- the patch will typically be the name the patch had before -- it was added to the rebase state; if it is moved back -- into the repository it must be given a fresh name to account -- for the fact that it will not necessarily have the same -- dependencies as the original patch. This is typically -- done by changing the @Ignore-This@ junk. -- -- @Fixup@ adjusts the context so that a subsequent @ToEdit@ patch -- is correct. Where possible, @Fixup@ changes are commuted -- as far as possible into the rebase state, so any remaining -- ones will typically cause a conflict when the @ToEdit@ patch -- is moved back into the repository. data RebaseItem p wX wY where ToEdit :: Named p wX wY -> RebaseItem p wX wY Fixup :: RebaseFixup p wX wY -> RebaseItem p wX wY instance (Show2 p, Show2 (PrimOf p)) => Show (RebaseItem p wX wY) where showsPrec d (ToEdit p) = showParen (d > appPrec) $ showString "ToEdit " . showsPrec2 (appPrec + 1) p showsPrec d (Fixup p) = showParen (d > appPrec) $ showString "Fixup " . showsPrec2 (appPrec + 1) p instance (Show2 p, Show2 (PrimOf p)) => Show1 (RebaseItem p wX) where showDict1 = ShowDictClass instance (Show2 p, Show2 (PrimOf p)) => Show2 (RebaseItem p) where showDict2 = ShowDictClass countToEdit :: FL (RebaseItem p) wX wY -> Int countToEdit NilFL = 0 countToEdit (ToEdit _ :>: ps) = 1 + countToEdit ps countToEdit (_ :>: ps) = countToEdit ps -- |Given a list of rebase items, try to push a new fixup as far as possible into -- the list as possible, using both commutation and coalescing. If the fixup -- commutes past all the 'ToEdit' patches then it is dropped entirely. simplifyPush :: (PrimPatchBase p, Commute p, FromPrim p, Effect p) => D.DiffAlgorithm -> RebaseFixup p wX wY -> FL (RebaseItem p) wY wZ -> Sealed (FL (RebaseItem p) wX) simplifyPush _ _f NilFL = Sealed NilFL simplifyPush da (PrimFixup f1) (Fixup (PrimFixup f2) :>: ps) | IsEq <- isInverse = Sealed ps | otherwise = case commute (f1 :> f2) of Nothing -> Sealed (mapFL_FL (Fixup . PrimFixup) (canonizeFL da (f1 :>: f2 :>: NilFL)) +>+ ps) Just (f2' :> f1') -> mapSeal (Fixup (PrimFixup f2') :>:) (simplifyPush da (PrimFixup f1') ps) where isInverse = invert f1 =\/= f2 simplifyPush da (PrimFixup f) (Fixup (NameFixup n) :>: ps) = case commutePrimName (f :> n) of n' :> f' -> mapSeal (Fixup (NameFixup n') :>:) (simplifyPush da (PrimFixup f') ps) simplifyPush da (PrimFixup f) (ToEdit e :>: ps) = case commuterIdNamed selfCommuter (fromPrim f :> e) of Nothing -> Sealed (Fixup (PrimFixup f) :>: ToEdit e :>: ps) Just (e' :> f') -> mapSeal (ToEdit e' :>:) (simplifyPushes da (mapFL_FL PrimFixup (effect f')) ps) simplifyPush da (NameFixup n1) (Fixup (NameFixup n2) :>: ps) | IsEq <- isInverse = Sealed ps | otherwise = case commute (n1 :> n2) of Nothing -> Sealed (mapFL_FL (Fixup . NameFixup) (canonizeNamePair (n1 :> n2)) +>+ ps) Just (n2' :> n1') -> mapSeal (Fixup (NameFixup n2') :>:) (simplifyPush da (NameFixup n1') ps) where isInverse = invert n1 =\/= n2 simplifyPush da (NameFixup n) (Fixup (PrimFixup f) :>: ps) = case commuteNamePrim (n :> f) of f' :> n' -> mapSeal (Fixup (PrimFixup f') :>:) (simplifyPush da (NameFixup n') ps) simplifyPush da (NameFixup (AddName an)) (p@(ToEdit (NamedP pn deps _)) :>: ps) | an == pn = impossible | an `elem` deps = Sealed (Fixup (NameFixup (AddName an)) :>: p :>: ps) | otherwise = mapSeal (unsafeCoerceP p :>:) (simplifyPush da (NameFixup (AddName an)) ps) simplifyPush da (NameFixup (DelName dn)) (p@(ToEdit (NamedP pn deps _)) :>: ps) -- this case can arise if a patch is suspended then a fresh copy is pulled from another repo | dn == pn = Sealed (Fixup (NameFixup (DelName dn)) :>: p :>: ps) | dn `elem` deps = impossible | otherwise = mapSeal (unsafeCoerceP p :>:) (simplifyPush da (NameFixup (DelName dn)) ps) simplifyPush da (NameFixup (Rename old new)) (p@(ToEdit (NamedP pn deps body)) :>: ps) | old == pn = impossible | new == pn = impossible | old `elem` deps = impossible | new `elem` deps = let newdeps = map (\dep -> if new == dep then old else dep) deps in mapSeal (ToEdit (NamedP pn newdeps (unsafeCoerceP body)) :>:) (simplifyPush da (NameFixup (Rename old new)) ps) | otherwise = mapSeal (unsafeCoerceP p :>:) (simplifyPush da (NameFixup (Rename old new)) ps) -- |Like 'simplifyPush' but for a list of fixups. simplifyPushes :: (PrimPatchBase p, Commute p, FromPrim p, Effect p) => D.DiffAlgorithm -> FL (RebaseFixup p) wX wY -> FL (RebaseItem p) wY wZ -> Sealed (FL (RebaseItem p) wX) simplifyPushes _ NilFL ps = Sealed ps simplifyPushes da (f :>: fs) ps = unseal (simplifyPush da f) (simplifyPushes da fs ps) instance (PrimPatchBase p, PatchListFormat p, ShowPatchBasic p) => ShowPatchBasic (RebaseItem p) where showPatch f (ToEdit p) = blueText "rebase-toedit" <+> blueText "(" $$ showPatch f p $$ blueText ")" showPatch f (Fixup (PrimFixup p)) = blueText "rebase-fixup" <+> blueText "(" $$ showPatch f p $$ blueText ")" where showPatch f (Fixup (NameFixup p)) = blueText "rebase-name" <+> blueText "(" $$ showPatch f p $$ blueText ")" instance (PrimPatchBase p, PatchListFormat p, Apply p, CommuteNoConflicts p, Conflict p, IsHunk p, ShowPatch p) => ShowPatch (RebaseItem p) where summary (ToEdit p) = summary p summary (Fixup (PrimFixup p)) = plainSummaryPrim p summary (Fixup (NameFixup n)) = summary n summaryFL ps = vcat (mapFL summary ps) -- TODO sort out summaries properly, considering expected conflicts instance (PrimPatchBase p, PatchListFormat p, ReadPatch p) => ReadPatch (RebaseItem p) where readPatch' = mapSeal ToEdit <$> readWith (BC.pack "rebase-toedit") <|> mapSeal (Fixup . PrimFixup) <$> readWith (BC.pack "rebase-fixup" ) <|> mapSeal (Fixup . NameFixup) <$> readWith (BC.pack "rebase-name" ) where readWith :: forall m q wX . (ParserM m, ReadPatch q) => B.ByteString -> m (Sealed (q wX)) readWith str = do lexString str lexString (BC.pack "(") res <- readPatch' lexString (BC.pack ")") return res instance Check p => Check (RebaseItem p) where isInconsistent (Fixup _) = Nothing isInconsistent (ToEdit p) = isInconsistent p instance (PrimPatchBase p, PatchInspect p) => PatchInspect (RebaseItem p) where listTouchedFiles (ToEdit p) = listTouchedFiles p listTouchedFiles (Fixup p) = listTouchedFiles p hunkMatches f (ToEdit p) = hunkMatches f p hunkMatches f (Fixup p) = hunkMatches f p darcs-2.14.5/src/Darcs/Patch/Rebase/Name.hs0000644000000000000000000002067607346545000016402 0ustar0000000000000000-- Copyright (C) 2011-2 Ganesh Sittampalam -- -- BSD3 module Darcs.Patch.Rebase.Name ( RebaseName(..) , commuteNamePrim, commutePrimName , commuteNameNamed, commuteNamedName , canonizeNamePair ) where import Prelude () import Darcs.Prelude import Darcs.Patch.CommuteFn ( CommuteFn ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.Info ( PatchInfo, isInverted, showPatchInfo, readPatchInfo ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Named ( Named(..) ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.Show ( ShowPatch(..) ) import Darcs.Patch.Permutations ( inverseCommuter ) import Darcs.Patch.Prim ( PrimPatchBase(..) ) import Darcs.Patch.ReadMonads ( lexString ) import Darcs.Patch.Show ( ShowPatchBasic(..) ) import Darcs.Patch.Witnesses.Eq ( Eq2(..) ) import Darcs.Patch.Witnesses.Ordered ( (:>)(..), FL(..) ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..) ) import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..) , ShowDict(ShowDictClass) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Util.Printer ( empty, blueText, ($$) ) import Control.Applicative ( (<|>) ) import qualified Data.ByteString.Char8 as BC ( pack ) -- Note: in principle this is a general concept not limited to -- rebase, and we might be able to generalise this type and -- refactor named patches to use it too. -- | A 'RebaseName' encapsulates the concept of the name of a patch, -- without any contents. This allows us to track explicit dependencies -- in the rebase state, changing them to follow uses of amend-record -- or unsuspend on a depended-on patch, and warning the user if any -- are lost entirely. data RebaseName (p :: * -> * -> *) wX wY where AddName :: PatchInfo -> RebaseName p wX wY DelName :: PatchInfo -> RebaseName p wX wY Rename :: PatchInfo -> PatchInfo -> RebaseName p wX wY deriving Show instance Show1 (RebaseName p wX) where showDict1 = ShowDictClass instance Show2 (RebaseName p) where showDict2 = ShowDictClass instance ShowPatchBasic (RebaseName p) where showPatch f (AddName n) = blueText "addname" $$ showPatchInfo f n showPatch f (DelName n) = blueText "delname" $$ showPatchInfo f n showPatch f (Rename old new) = blueText "rename" $$ showPatchInfo f old $$ showPatchInfo f new instance ShowPatch (RebaseName p) where summary _ = empty -- TODO improve this? summaryFL _ = empty instance ReadPatch (RebaseName p) where readPatch' = readAddName <|> readDelName <|> readRename where readAddName = do lexString (BC.pack "addname") n <- readPatchInfo return (Sealed (AddName n)) readDelName = do lexString (BC.pack "delname") n <- readPatchInfo return (Sealed (DelName n)) readRename = do lexString (BC.pack "rename") old <- readPatchInfo new <- readPatchInfo return (Sealed (Rename old new)) instance Commute (RebaseName p) where commute (AddName n1 :> AddName n2) | n1 == n2 = impossible | otherwise = Just (AddName n2 :> AddName n1) commute (DelName n1 :> DelName n2) | n1 == n2 = impossible | otherwise = Just (DelName n2 :> DelName n1) commute (AddName n1 :> DelName n2) | n1 /= n2 = Just (DelName n2 :> AddName n1) | otherwise = Nothing commute (DelName n1 :> AddName n2) | n1 /= n2 = Just (AddName n2 :> DelName n1) | otherwise = Nothing commute (Rename old new :> AddName n) | n == old = Nothing | n == new = impossible -- precondition of Add is that n doesn't exist | otherwise = Just (AddName n :> Rename old new) commute (AddName n :> Rename old new) | n == old = Nothing | n == new = impossible -- precondition of Rename is that new doesn't exist | otherwise = Just (Rename old new :> AddName n) commute (Rename old new :> DelName n) | n == old = impossible -- precondition of Del is that n does exist | n == new = Nothing | otherwise = Just (DelName n :> Rename old new) commute (DelName n :> Rename old new) | n == old = impossible -- precondition of Rename is that old does exist | n == new = Nothing | otherwise = Just (Rename old new :> DelName n) commute (Rename old1 new1 :> Rename old2 new2) | old1 == old2 = impossible | new1 == new2 = impossible | old1 == new2 = Nothing | new1 == old2 = Nothing | otherwise = Just (Rename old2 new2 :> Rename old1 new1) instance Invert (RebaseName p) where invert (AddName n) = DelName n invert (DelName n) = AddName n invert (Rename old new) = Rename new old instance PatchInspect (RebaseName p) where listTouchedFiles _ = [] hunkMatches _ _ = False instance Apply (RebaseName p) where type ApplyState (RebaseName p) = ApplyState p apply _ = return () instance PrimPatchBase p => PrimPatchBase (RebaseName p) where type PrimOf (RebaseName p) = PrimOf p instance Effect (RebaseName p) where effect _ = unsafeCoerceP NilFL instance Eq2 (RebaseName p) where AddName n1 `unsafeCompare` AddName n2 = n1 == n2 AddName _ `unsafeCompare` _ = False _ `unsafeCompare` AddName _ = False DelName n1 `unsafeCompare` DelName n2 = n1 == n2 DelName _ `unsafeCompare` _ = False _ `unsafeCompare` DelName _ = False Rename old1 new1 `unsafeCompare` Rename old2 new2 = old1 == old2 && new1 == new2 -- Rename _ _ `unsafeCompare` _ = False -- _ `unsafeCompare` Rename _ _ = False -- |Commute a name patch and a primitive patch. They trivially -- commute so this just involves changing the witnesses. commuteNamePrim :: (RebaseName p :> PrimOf p) wX wY -> (PrimOf p :> RebaseName p) wX wY commuteNamePrim (n :> f) = unsafeCoerceP f :> unsafeCoerceP n -- |Commute a primitive patch and a name patch. They trivially -- commute so this just involves changing the witnesses. commutePrimName :: (PrimOf p :> RebaseName p) wX wY -> (RebaseName p :> PrimOf p) wX wY commutePrimName (f :> n) = unsafeCoerceP n :> unsafeCoerceP f -- |Commute a name patch and a named patch. In most cases this is -- trivial but we do need to check explicit dependencies. commuteNameNamed :: Invert p => CommuteFn (RebaseName p) (Named p) commuteNameNamed pair@(_ :> NamedP pn _ _) | isInverted pn = inverseCommuter commuteNamedName pair commuteNameNamed (AddName an :> p@(NamedP pn deps _)) | an == pn = impossible | an `elem` deps = Nothing | otherwise = Just (unsafeCoerceP p :> AddName an) commuteNameNamed (DelName dn :> p@(NamedP pn deps _)) | dn == pn = impossible | dn `elem` deps = impossible | otherwise = Just (unsafeCoerceP p :> DelName dn) commuteNameNamed (Rename old new :> NamedP pn deps body) | old == pn = impossible | new == pn = impossible | old `elem` deps = impossible | otherwise = let newdeps = map (\dep -> if new == dep then old else dep) deps in Just (NamedP pn newdeps (unsafeCoerceP body) :> Rename old new) -- |Commute a named patch and a name patch. In most cases this is -- trivial but we do need to check explicit dependencies. commuteNamedName :: Invert p => CommuteFn (Named p) (RebaseName p) commuteNamedName pair@(NamedP pn _ _ :> _) | isInverted pn = inverseCommuter commuteNameNamed pair commuteNamedName (p@(NamedP pn deps _) :> AddName an) | an == pn = impossible -- the NamedP introduces pn, then AddName introduces it again | an `elem` deps = impossible -- the NamedP depends on an before it is introduced | otherwise = Just (AddName an :> unsafeCoerceP p) commuteNamedName (p@(NamedP pn deps _) :> DelName dn) | dn == pn = Nothing | dn `elem` deps = Nothing | otherwise = Just (DelName dn :> unsafeCoerceP p) commuteNamedName (NamedP pn deps body :> Rename old new) | old == pn = Nothing | new == pn = impossible | new `elem` deps = impossible | otherwise = let newdeps = map (\dep -> if old == dep then new else dep) deps in Just (Rename old new :> NamedP pn newdeps (unsafeCoerceP body)) canonizeNamePair :: (RebaseName p :> RebaseName p) wX wY -> FL (RebaseName p) wX wY canonizeNamePair (AddName n :> Rename old new) | n == old = AddName new :>: NilFL canonizeNamePair (Rename old new :> DelName n) | n == new = DelName old :>: NilFL canonizeNamePair (Rename old1 new1 :> Rename old2 new2) | new1 == old2 = Rename old1 new2 :>: NilFL canonizeNamePair (n1 :> n2) = n1 :>: n2 :>: NilFL darcs-2.14.5/src/Darcs/Patch/Rebase/Viewing.hs0000644000000000000000000005740307346545000017130 0ustar0000000000000000-- Copyright (C) 2009 Ganesh Sittampalam -- -- BSD3 {-# LANGUAGE UndecidableInstances #-} module Darcs.Patch.Rebase.Viewing ( RebaseSelect(..) , toRebaseSelect, fromRebaseSelect, extractRebaseSelect, reifyRebaseSelect , partitionUnconflicted , rsToPia , WithDroppedDeps(..), WDDNamed, commuterIdWDD , RebaseChange(..), toRebaseChanges ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Commute ( selfCommuter ) import Darcs.Patch.CommuteFn ( CommuteFn, commuterIdFL, commuterRLId, MergeFn , totalCommuterIdFL ) import Darcs.Patch.Conflict ( Conflict(..), CommuteNoConflicts(..) , IsConflictedPrim ) import Darcs.Patch.Debug ( PatchDebug(..) ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.FileHunk ( IsHunk(..) ) import Darcs.Patch.Format ( PatchListFormat(..) ) import Darcs.Patch.Info ( PatchInfo ) import Darcs.Patch.Invert ( invertFL, invertRL ) import Darcs.Patch.Matchable ( Matchable ) import Darcs.Patch.Merge ( Merge(..), selfMerger ) import Darcs.Patch.Named ( Named(..), namepatch, infopatch , mergerIdNamed , getdeps , patch2patchinfo, patchcontents ) import Darcs.Patch.Named.Wrapped ( WrappedNamed(..) ) import qualified Darcs.Patch.Named.Wrapped as Wrapped ( infopatch, adddeps ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, n2pia ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.Show ( ShowPatch(..) ) import Darcs.Patch.Prim ( PrimPatch, PrimPatchBase(..), FromPrim(..), FromPrims(..) ) import Darcs.Patch.Rebase.Container ( Suspended(..) ) import Darcs.Patch.Rebase.Fixup ( RebaseFixup(..) , commuteFixupNamed, commuteNamedFixups , flToNamesPrims ) import Darcs.Patch.Rebase.Item ( RebaseItem(..) ) import Darcs.Patch.Rebase.Name ( RebaseName(..) ) import Darcs.Patch.RepoType ( RepoType(..), RebaseType(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..), ShowPatchFor(..), ShowContextPatch(..) ) import Darcs.Patch.Summary ( plainSummary ) import Darcs.Patch.Witnesses.Eq import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..), ShowDict(ShowDictClass) , showsPrec2 ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP, unsafeCoercePEnd ) import Darcs.Util.IsoDate ( getIsoDateTime ) import Darcs.Util.Printer ( ($$), redText, empty, vcat ) import Darcs.Util.Show ( appPrec ) import Data.List ( nub, (\\) ) import Data.Maybe ( fromMaybe ) -- |Encapsulate a single patch in the rebase state together with its fixups. -- Used during interactive selection to make sure that each item presented -- to the user corresponds to a patch. data RebaseSelect p wX wY where -- The normal case for a RebaseSelect - a patch that points forwards. RSFwd :: FL (RebaseFixup p) wX wY -> Named p wY wZ -> RebaseSelect p wX wZ -- We need an 'Invert' instance. We just represent inverses -- with a different constructor instead of trying to come up with some logical -- inversion of the individual components. Typically they get uninverted -- before anything significant is done with them, so a lot of code that -- processes 'RebaseSelect' patches just uses 'impossible' for 'RSRev'. RSRev :: FL (RebaseFixup p) wX wY -> Named p wY wZ -> RebaseSelect p wZ wX instance (Show2 p, Show2 (PrimOf p)) => Show (RebaseSelect p wX wY) where showsPrec d (RSFwd fixups toedit) = showParen (d > appPrec) $ showString "RSFwd " . showsPrec2 (appPrec + 1) fixups . showString " " . showsPrec2 (appPrec + 1) toedit showsPrec d (RSRev fixups toedit) = showParen (d > appPrec) $ showString "RSRev " . showsPrec2 (appPrec + 1) fixups . showString " " . showsPrec2 (appPrec + 1) toedit instance (Show2 p, Show2 (PrimOf p)) => Show1 (RebaseSelect p wX) where showDict1 = ShowDictClass instance (Show2 p, Show2 (PrimOf p)) => Show2 (RebaseSelect p) where showDict2 = ShowDictClass -- TODO: merge with RebaseSelect. -- |Used for displaying during 'rebase changes'. -- 'Named (RebaseChange p)' is very similar to 'RebaseSelect p' but slight -- mismatches ('Named' embeds an 'FL') makes it not completely trivial to merge -- them. data RebaseChange p wX wY where RCFwd :: FL (RebaseFixup p) wX wY -> FL p wY wZ -> RebaseChange p wX wZ RCRev :: FL (RebaseFixup p) wX wY -> FL p wY wZ -> RebaseChange p wZ wX instance (Show2 p, Show2 (PrimOf p)) => Show1 (RebaseChange p wX) where showDict1 = ShowDictClass instance (Show2 p, Show2 (PrimOf p)) => Show2 (RebaseChange p) where showDict2 = ShowDictClass instance (Show2 p, Show2 (PrimOf p)) => Show (RebaseChange p wX wY) where showsPrec d (RCFwd fixups changes) = showParen (d > appPrec) $ showString "RCFwd " . showsPrec2 (appPrec + 1) fixups . showString " " . showsPrec2 (appPrec + 1) changes showsPrec d (RCRev fixups changes) = showParen (d > appPrec) $ showString "RCRev " . showsPrec2 (appPrec + 1) fixups . showString " " . showsPrec2 (appPrec + 1) changes -- |Get hold of the 'PatchInfoAnd' patch inside a 'RebaseSelect'. rsToPia :: RebaseSelect p wX wY -> Sealed2 (PatchInfoAnd ('RepoType 'NoRebase) p) rsToPia (RSFwd _ toEdit) = Sealed2 (n2pia (NormalP toEdit)) rsToPia (RSRev _ toEdit) = Sealed2 (n2pia (NormalP toEdit)) instance PrimPatchBase p => PrimPatchBase (RebaseSelect p) where type PrimOf (RebaseSelect p) = PrimOf p instance PatchDebug p => PatchDebug (RebaseSelect p) instance PatchDebug p => PatchDebug (RebaseChange p) instance (PrimPatchBase p, Invert p, Apply p, ApplyState p ~ ApplyState (PrimOf p)) => Apply (RebaseSelect p) where type ApplyState (RebaseSelect p) = ApplyState p apply (RSFwd fixups toedit) = apply fixups >> apply toedit apply (RSRev fixups toedit) = apply (invert toedit) >> apply (invertFL fixups) instance ( PrimPatchBase p, Invert p, Apply p , ApplyState p ~ ApplyState (PrimOf p) ) => Apply (RebaseChange p) where type ApplyState (RebaseChange p) = ApplyState p apply (RCFwd fixups contents) = apply fixups >> apply contents apply (RCRev fixups contents) = apply (invert contents) >> apply (invertFL fixups) instance (PrimPatchBase p, Conflict p, CommuteNoConflicts p, Invert p) => Conflict (RebaseSelect p) where resolveConflicts (RSFwd _ toedit) = resolveConflicts toedit resolveConflicts (RSRev{}) = impossible conflictedEffect (RSFwd _ toedit) = conflictedEffect toedit conflictedEffect (RSRev{}) = impossible -- newtypes to help the type-checker with the 'changeAsMerge' abstraction newtype ResolveConflictsResult p wY = ResolveConflictsResult { getResolveConflictsResult :: [[Sealed (FL (PrimOf p) wY)]] } newtype ConflictedEffectResult p wY = ConflictedEffectResult { getConflictedEffectResult :: [IsConflictedPrim (PrimOf p)] } changeAsMerge :: (PrimPatchBase p, Invert p, FromPrim p, Merge p) => (forall wX' . FL p wX' wY -> result p wY) -> RebaseChange p wX wY -> result p wY changeAsMerge f (RCFwd fixups changes) = case flToNamesPrims fixups of _names :> prims -> case merge (invert (fromPrims prims) :\/: changes) of changes' :/\: _ifixups' -> -- it might make sense to pass -- (changes' +>+ invert _ifixups') to resolveConflicts, -- but this isn't actually treated as a conflict by -- either V1 or V2 patches (not quite sure why) f (unsafeCoercePEnd changes') changeAsMerge _ (RCRev _ _) = impossible instance ( PrimPatchBase p, Invert p, Effect p , FromPrim p, Merge p, Conflict p, CommuteNoConflicts p ) => Conflict (RebaseChange p) where resolveConflicts = getResolveConflictsResult . changeAsMerge (ResolveConflictsResult . resolveConflicts) conflictedEffect = getConflictedEffectResult . changeAsMerge (ConflictedEffectResult . conflictedEffect) instance (PrimPatchBase p, Invert p, Effect p) => Effect (RebaseSelect p) where effect (RSFwd fixups toedit) = concatFL (mapFL_FL effect fixups) +>+ effect toedit effect (RSRev fixups toedit) = invertRL . reverseFL . effect $ RSFwd fixups toedit instance (PrimPatchBase p, Invert p, Effect p) => Effect (RebaseChange p) where effect (RCFwd fixups changes) = concatFL (mapFL_FL effect fixups) +>+ effect changes effect (RCRev fixups changes) = invertRL . reverseFL . effect $ RCFwd fixups changes instance (PrimPatchBase p, PatchListFormat p, ShowPatchBasic p) => ShowPatchBasic (RebaseSelect p) where showPatch f (RSFwd fixups toedit) = showPatch f (Items (mapFL_FL Fixup fixups +>+ ToEdit toedit :>: NilFL)) showPatch _ (RSRev {}) = impossible -- TODO this is a dummy instance that does not actually show context instance (PrimPatchBase p, PatchListFormat p, ShowPatchBasic p) => ShowContextPatch (RebaseSelect p) where showContextPatch f p = return $ showPatch f p instance (PrimPatchBase p, ShowPatchBasic p) => ShowPatchBasic (RebaseChange p) where showPatch ForStorage _ = impossible showPatch ForDisplay (RCFwd fixups contents) = vcat (mapFL (showPatch ForDisplay) contents) $$ (if nullFL fixups then empty else redText "" $$ redText "conflicts:" $$ redText "" $$ vcat (mapRL showFixup (invertFL fixups)) ) where showFixup (PrimFixup p) = showPatch ForDisplay p showFixup (NameFixup n) = showPatch ForDisplay n showPatch _ (RCRev {}) = impossible instance (PrimPatchBase p, PatchListFormat p, Apply p, CommuteNoConflicts p, Conflict p, IsHunk p, ShowPatch p) => ShowPatch (RebaseSelect p) where description (RSFwd _ toedit) = description toedit description (RSRev _ _toedit) = impossible summary = summaryFL . fromRebaseSelect . (:>: NilFL) summaryFL = summaryFL . fromRebaseSelect instance ( PrimPatchBase p, PatchListFormat p, ShowPatchBasic p , Invert p, Effect p, Merge p, FromPrim p , Conflict p, CommuteNoConflicts p ) => ShowPatch (RebaseChange p) where summary = plainSummary summaryFL = plainSummary -- TODO this is a dummy instance that does not actually show context instance ( PrimPatchBase p, ShowPatchBasic p) => ShowContextPatch (RebaseChange p) where showContextPatch f p = return $ showPatch f p instance ReadPatch (RebaseSelect p) where readPatch' = error "can't read RebaseSelect patches" instance ReadPatch (RebaseChange p) where readPatch' = error "can't read RebaseChange patches" -- |Turn a list of rebase items being rebased into a list suitable for use -- by interactive selection. Each actual patch being rebased is grouped -- together with any fixups needed. toRebaseSelect :: PrimPatchBase p => FL (RebaseItem p) wX wY -> FL (RebaseSelect p) wX wY -- |Turn a list of items back from the format used for interactive selection -- into a normal list fromRebaseSelect :: FL (RebaseSelect p) wX wY -> FL (RebaseItem p) wX wY fromRebaseSelect NilFL = NilFL fromRebaseSelect (RSFwd fixups toedit :>: ps) = mapFL_FL Fixup fixups +>+ ToEdit toedit :>: fromRebaseSelect ps fromRebaseSelect (RSRev {} :>: _) = impossible toRebaseSelect NilFL = NilFL toRebaseSelect (Fixup f :>: ps) = case toRebaseSelect ps of RSFwd fixups toedit :>: rest -> RSFwd (f :>: fixups) toedit :>: rest NilFL -> bug "rebase chain with Fixup at end" _ -> impossible toRebaseSelect (ToEdit te :>: ps) = RSFwd NilFL te :>: toRebaseSelect ps toRebaseChanges :: PrimPatchBase p => FL (RebaseItem p) wX wY -> FL (PatchInfoAnd ('RepoType 'IsRebase) (RebaseChange p)) wX wY toRebaseChanges = mapFL_FL toChange . toRebaseSelect toChange :: RebaseSelect p wX wY -> PatchInfoAnd rt (RebaseChange p) wX wY toChange (RSFwd fixups named) = n2pia $ flip Wrapped.adddeps (getdeps named) $ Wrapped.infopatch (patch2patchinfo named) $ (:>: NilFL) $ RCFwd fixups (patchcontents named) toChange (RSRev fixups named) = n2pia $ flip Wrapped.adddeps (getdeps named) $ Wrapped.infopatch (patch2patchinfo named) $ (:>: NilFL) $ RCRev fixups (patchcontents named) instance PrimPatch (PrimOf p) => PrimPatchBase (RebaseChange p) where type PrimOf (RebaseChange p) = PrimOf p instance Invert (RebaseSelect p) where invert (RSFwd fixups edit) = RSRev fixups edit invert (RSRev fixups edit) = RSFwd fixups edit instance Invert (RebaseChange p) where invert (RCFwd fixups contents) = RCRev fixups contents invert (RCRev fixups contents) = RCFwd fixups contents instance (PrimPatchBase p, Commute p, Eq2 p) => Eq2 (RebaseSelect p) where RSFwd fixups1 edit1 =\/= RSFwd fixups2 edit2 | IsEq <- fixups1 =\/= fixups2, IsEq <- edit1 =\/= edit2 = IsEq RSRev fixups1 edit1 =\/= RSRev fixups2 edit2 | IsEq <- edit1 =/\= edit2, IsEq <- fixups1 =/\= fixups2 = IsEq _ =\/= _ = impossible instance (PrimPatchBase p, FromPrim p, Effect p, Commute p, Invert p) => Commute (RebaseSelect p) where commute (RSFwd {} :> RSRev {}) = impossible commute (RSRev {} :> RSFwd {}) = impossible commute (RSRev fixups1 edit1 :> RSRev fixups2 edit2) = do RSFwd fixups1' edit1' :> RSFwd fixups2' edit2' <- commute (RSFwd fixups2 edit2 :> RSFwd fixups1 edit1) return (RSRev fixups2' edit2' :> RSRev fixups1' edit1') commute (RSFwd fixups1 edit1 :> RSFwd fixups2 edit2) = do fixups2' :> edit1' <- commuteNamedFixups (edit1 :> fixups2) edit2' :> edit1'' <- commute (edit1' :> edit2) fixupsS :> (fixups2'' :> edit2'') :> fixups1' <- return $ pushThrough (fixups1 :> (fixups2' :> edit2')) return (RSFwd (fixupsS +>+ fixups2'') edit2'' :> RSFwd fixups1' edit1'') instance Commute (RebaseChange p) where commute _ = impossible instance (PrimPatchBase p, PatchInspect p) => PatchInspect (RebaseSelect p) where listTouchedFiles (RSFwd fixup toedit) = nub (listTouchedFiles fixup ++ listTouchedFiles toedit) listTouchedFiles (RSRev fixup toedit) = nub (listTouchedFiles fixup ++ listTouchedFiles toedit) hunkMatches f (RSFwd fixup toedit) = hunkMatches f fixup || hunkMatches f toedit hunkMatches f (RSRev fixup toedit) = hunkMatches f fixup || hunkMatches f toedit instance (PrimPatchBase p, PatchInspect p) => PatchInspect (RebaseChange p) where listTouchedFiles (RCFwd fixup contents) = nub (listTouchedFiles fixup ++ listTouchedFiles contents) listTouchedFiles (RCRev fixup contents) = nub (listTouchedFiles fixup ++ listTouchedFiles contents) hunkMatches f (RCFwd fixup contents) = hunkMatches f fixup || hunkMatches f contents hunkMatches f (RCRev fixup contents) = hunkMatches f fixup || hunkMatches f contents -- |Split a list of rebase patches into those that will -- have conflicts if unsuspended and those that won't. partitionUnconflicted :: (PrimPatchBase p, FromPrim p, Effect p, Commute p, Invert p) => FL (RebaseSelect p) wX wY -> (FL (RebaseSelect p) :> RL (RebaseSelect p)) wX wY partitionUnconflicted = partitionUnconflictedAcc NilRL partitionUnconflictedAcc :: (PrimPatchBase p, FromPrim p, Effect p, Commute p, Invert p) => RL (RebaseSelect p) wX wY -> FL (RebaseSelect p) wY wZ -> (FL (RebaseSelect p) :> RL (RebaseSelect p)) wX wZ partitionUnconflictedAcc right NilFL = NilFL :> right partitionUnconflictedAcc right (p :>: ps) = case commuterRLId selfCommuter (right :> p) of Just (p'@(RSFwd NilFL _) :> right') -> case partitionUnconflictedAcc right' ps of left' :> right'' -> (p' :>: left') :> right'' _ -> partitionUnconflictedAcc (right :<: p) ps -- | A patch, together with a list of patch names that it used to depend on, -- but were lost during the rebasing process. The UI can use this information -- to report them to the user. data WithDroppedDeps p wX wY = WithDroppedDeps { wddPatch :: p wX wY, wddDependedOn :: [PatchInfo] } noDroppedDeps :: p wX wY -> WithDroppedDeps p wX wY noDroppedDeps p = WithDroppedDeps p [] instance PrimPatchBase p => PrimPatchBase (WithDroppedDeps p) where type PrimOf (WithDroppedDeps p) = PrimOf p instance Effect p => Effect (WithDroppedDeps p) where effect = effect . wddPatch -- Note, this could probably be rewritten using a generalised commuteWhatWeCanFL from -- Darcs.Patch.Permutations. -- |@pushThrough (ps :> (qs :> te))@ tries to commute as much of @ps@ as possible through -- both @qs@ and @te@, giving @psStuck :> (qs' :> te') :> psCommuted@. -- Anything that can be commuted ends up in @psCommuted@ and anything that can't goes in -- @psStuck@. pushThrough :: (PrimPatchBase p, FromPrim p, Effect p, Commute p, Invert p) => (FL (RebaseFixup p) :> (FL (RebaseFixup p) :> Named p)) wX wY -> (FL (RebaseFixup p) :> (FL (RebaseFixup p) :> Named p) :> FL (RebaseFixup p)) wX wY pushThrough (NilFL :> v) = NilFL :> v :> NilFL pushThrough ((p :>: ps) :> v) = case pushThrough (ps :> v) of psS :> v'@(qs:>te) :> ps' -> fromMaybe ((p :>: psS) :> v' :> ps') $ do psS' :> p' <- commuterIdFL selfCommuter (p :> psS) qs' :> p'' <- commuterIdFL selfCommuter (p' :> qs) te' :> p''' <- commuteFixupNamed (p'' :> te) return (psS' :> (qs' :> te') :> (p''' +>+ ps')) type WDDNamed p = WithDroppedDeps (Named p) mergerIdWDD :: MergeFn p1 p2 -> MergeFn p1 (WithDroppedDeps p2) mergerIdWDD merger (p1 :\/: WithDroppedDeps p2 deps) = case merger (p1 :\/: p2) of p2' :/\: p1' -> WithDroppedDeps p2' deps :/\: p1' commuterIdWDD :: CommuteFn p q -> CommuteFn p (WithDroppedDeps q) commuterIdWDD commuter (p :> WithDroppedDeps q deps) = do -- no need to worry about names, because by definition a dropped dep -- is a name we no longer have -- TODO consistency checking? -- TODO consider inverse commutes, e.g. what happens if we wanted to -- commute (WithDroppedDeps ... [n] :> AddName n)? q' :> p' <- commuter (p :> q) return (WithDroppedDeps q' deps :> p') -- |Forcibly commute a 'RebaseName' with a patch, dropping any dependencies -- if necessary and recording them in the patch forceCommuteName :: (RebaseName p :> WDDNamed p) wX wY -> (WDDNamed p :> RebaseName p) wX wY forceCommuteName (AddName an :> WithDroppedDeps (NamedP pn deps body) ddeps) | an == pn = impossible | otherwise = WithDroppedDeps (NamedP pn (deps \\ [an]) (unsafeCoerceP body)) (if an `elem` deps then an:ddeps else ddeps) :> AddName an forceCommuteName (DelName dn :> p@(WithDroppedDeps (NamedP pn deps _body) _ddeps)) | dn == pn = impossible | dn `elem` deps = impossible | otherwise = unsafeCoerceP p :> DelName dn forceCommuteName (Rename old new :> WithDroppedDeps (NamedP pn deps body) ddeps) | old == pn = impossible | new == pn = impossible | old `elem` deps = impossible | otherwise = let newdeps = map (\dep -> if new == dep then old else dep) deps in WithDroppedDeps (NamedP pn newdeps (unsafeCoerceP body)) ddeps :> Rename old new forceCommutePrim :: (Merge p, Invert p, Effect p, FromPrim p) => (PrimOf p :> WDDNamed p) wX wY -> (WDDNamed p :> FL (PrimOf p)) wX wY forceCommutePrim (p :> q) = case mergerIdWDD (mergerIdNamed selfMerger) (invert (fromPrim p) :\/: q) of q' :/\: invp' -> q' :> effect (invert invp') forceCommutesPrim :: (Merge p, Invert p, Effect p, FromPrim p) => (PrimOf p :> FL (WDDNamed p)) wX wY -> (FL (WDDNamed p) :> FL (PrimOf p)) wX wY forceCommutesPrim (p :> NilFL) = NilFL :> (p :>: NilFL) forceCommutesPrim (p :> (q :>: qs)) = case forceCommutePrim (p :> q) of q' :> p' -> case forceCommutessPrim ( p' :> qs) of qs' :> p'' -> (q' :>: qs') :> p'' forceCommutessPrim :: (Merge p, Invert p, Effect p, FromPrim p) => (FL (PrimOf p) :> FL (WDDNamed p)) wX wY -> (FL (WDDNamed p) :> FL (PrimOf p)) wX wY forceCommutessPrim (NilFL :> qs) = qs :> NilFL forceCommutessPrim ((p :>: ps) :> qs) = case forceCommutessPrim (ps :> qs) of qs' :> ps' -> case forceCommutesPrim (p :> qs') of qs'' :> p' -> qs'' :> (p' +>+ ps') forceCommutess :: (Merge p, Invert p, Effect p, FromPrim p) => (FL (RebaseFixup p) :> FL (WDDNamed p)) wX wY -> (FL (WDDNamed p) :> FL (RebaseFixup p)) wX wY forceCommutess (NilFL :> qs) = qs :> NilFL forceCommutess ((NameFixup n :>: ps) :> qs) = case forceCommutess (ps :> qs) of qs' :> ps' -> case totalCommuterIdFL forceCommuteName (n :> qs') of qs'' :> n' -> qs'' :> (NameFixup n' :>: ps') forceCommutess ((PrimFixup p :>: ps) :> qs) = case forceCommutess (ps :> qs) of qs' :> ps' -> case forceCommutesPrim (p :> qs') of qs'' :> p' -> qs'' :> (mapFL_FL PrimFixup p' +>+ ps') -- |Turn a selected rebase patch back into a patch we can apply to -- the main repository, together with residual fixups that need -- to go back into the rebase state (unless the rebase is now finished). -- Any fixups associated with the patch will turn into conflicts. extractRebaseSelect :: (Merge p, Invert p, Effect p, FromPrim p, PrimPatchBase p) => FL (RebaseSelect p) wX wY -> (FL (WDDNamed p) :> FL (RebaseFixup p)) wX wY extractRebaseSelect NilFL = NilFL :> NilFL extractRebaseSelect (RSFwd fixups toedit :>: rest) = case extractRebaseSelect rest of toedits2 :> fixups2 -> case forceCommutess (fixups :> (WithDroppedDeps toedit [] :>: toedits2)) of toedits' :> fixups' -> toedits' :> (fixups' +>+ fixups2) extractRebaseSelect (RSRev{} :>: _) = impossible -- signature to be compatible with extractRebaseSelect -- | Like 'extractRebaseSelect', but any fixups are "reified" into a separate patch. reifyRebaseSelect :: forall p wX wY . (PrimPatchBase p, FromPrim p) => FL (RebaseSelect p) wX wY -> IO ((FL (WDDNamed p) :> FL (RebaseFixup p)) wX wY) reifyRebaseSelect rs = do res <- concatFL <$> mapFL_FL_M reifyOne rs return (res :> NilFL) where reifyOne :: RebaseSelect p wA wB -> IO (FL (WDDNamed p) wA wB) reifyOne (RSFwd fixups toedit) = case flToNamesPrims fixups of names :> NilFL -> return (mapFL_FL (noDroppedDeps . mkDummy) names +>+ noDroppedDeps toedit :>: NilFL) names :> prims -> do n <- mkReified prims return (mapFL_FL (noDroppedDeps . mkDummy) names +>+ noDroppedDeps n :>: noDroppedDeps toedit :>: NilFL) reifyOne (RSRev{}) = impossible mkReified :: FromPrim p => FL (PrimOf p) wX wY -> IO (Named p wX wY) mkReified ps = do let name = "Reified fixup patch" let desc = [] date <- getIsoDateTime let author = "Invalid " namepatch date name author desc (mapFL_FL fromPrim ps) mkDummy :: RebaseName p wX wY -> Named p wX wY mkDummy (AddName pi) = infopatch pi (unsafeCoerceP NilFL) mkDummy (DelName _) = error "internal error: can't make a dummy patch from a delete" mkDummy (Rename _ _) = error "internal error: can't make a dummy patch from a rename" instance CommuteNoConflicts (RebaseChange p) where commuteNoConflicts _ = impossible instance IsHunk (RebaseChange p) where -- RebaseChange is a compound patch, so it doesn't really make sense to -- ask whether it's a hunk. TODO: get rid of the need for this. isHunk _ = Nothing instance PatchListFormat (RebaseChange p) instance ( PrimPatchBase p, Apply p, Invert p , PatchInspect p , ApplyState p ~ ApplyState (PrimOf p) ) => Matchable (RebaseChange p) darcs-2.14.5/src/Darcs/Patch/RegChars.hs0000644000000000000000000000611007346545000016002 0ustar0000000000000000-- Copyright (C) 2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.RegChars ( regChars, ) where import Prelude () import Darcs.Prelude (&&&) :: (a -> Bool) -> (a -> Bool) -> a -> Bool (&&&) a b c = a c && b c (|||) :: (a -> Bool) -> (a -> Bool) -> a -> Bool (|||) a b c = a c || b c {-# INLINE regChars #-} -- | 'regChars' returns a filter function that tells if a char is a member -- of the regChar expression or not. The regChar expression is basically a -- set of chars, but it can contain ranges with use of the '-' (dash), and -- it can also be specified as a complement set by prefixing with '^' -- (caret). The dash and caret, as well as the backslash, can all be -- escaped with a backslash to suppress their special meaning. -- -- NOTE: The '.' (dot) is allowed to be escaped. It has no special meaning -- if it is not escaped, but the default 'filename_toks' in -- Darcs.Commands.Replace uses an escaped dot (WHY?). regChars :: String -> Char -> Bool regChars ('^':cs) = not . normalRegChars (unescapeChars cs) regChars ('\\':'^':cs) = normalRegChars $ unescapeChars $ '^':cs regChars cs = normalRegChars $ unescapeChars cs {-# INLINE unescapeChars #-} -- | 'unescapeChars' unescapes whitespace, which is escaped in the replace -- patch file format. It will also unescape escaped carets, which is useful -- for escaping a leading caret that should not invert the regChars. All -- other escapes are left for the unescaping in 'normalRegChars'. unescapeChars :: String -> String unescapeChars ('\\':'n':cs) = '\n' : unescapeChars cs unescapeChars ('\\':'t':cs) = '\t' : unescapeChars cs unescapeChars ('\\':'^':cs) = '^' : unescapeChars cs unescapeChars (c:cs) = c : unescapeChars cs unescapeChars [] = [] {-# INLINE normalRegChars #-} -- | 'normalRegChars' assembles the filter function. It handles special -- chars, and also unescaping of escaped special chars. If a non-special -- char is still escaped by now we get a failure. normalRegChars :: String -> Char -> Bool normalRegChars ('\\':'.':cs) = (=='.') ||| normalRegChars cs normalRegChars ('\\':'-':cs) = (=='-') ||| normalRegChars cs normalRegChars ('\\':'\\':cs) = (=='\\') ||| normalRegChars cs normalRegChars ('\\':c:_) = error $ "'\\"++[c]++"' not supported." normalRegChars (c1:'-':c2:cs) = ((>= c1) &&& (<= c2)) ||| normalRegChars cs normalRegChars (c:cs) = (== c) ||| normalRegChars cs normalRegChars [] = \_ -> False darcs-2.14.5/src/Darcs/Patch/Repair.hs0000644000000000000000000000433607346545000015536 0ustar0000000000000000module Darcs.Patch.Repair ( Repair(..), RepairToFL(..), mapMaybeSnd, Check(..) ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.ApplyMonad ( ApplyMonad ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), mapFL, mapRL, (+>+) ) import Darcs.Util.Printer ( Doc ) import Data.Maybe ( catMaybes, listToMaybe ) class Check p where isInconsistent :: p wX wY -> Maybe Doc isInconsistent _ = Nothing -- |'Repair' and 'RepairToFL' deal with repairing old patches that were -- were written out due to bugs or that we no longer wish to support. -- 'Repair' is implemented by collections of patches (FL, Named, PatchInfoAnd) that -- might need repairing. class Repair p where applyAndTryToFix :: ApplyMonad (ApplyState p) m => p wX wY -> m (Maybe (String, p wX wY)) -- |'RepairToFL' is implemented by single patches that can be repaired (Prim, Patch, RepoPatchV2) -- There is a default so that patch types with no current legacy problems don't need to -- have an implementation. class Apply p => RepairToFL p where applyAndTryToFixFL :: ApplyMonad (ApplyState p) m => p wX wY -> m (Maybe (String, FL p wX wY)) applyAndTryToFixFL p = do apply p; return Nothing mapMaybeSnd :: (a -> b) -> Maybe (c, a) -> Maybe (c, b) mapMaybeSnd f (Just (a,b)) = Just (a,f b) mapMaybeSnd _ Nothing = Nothing instance Check p => Check (FL p) where isInconsistent = listToMaybe . catMaybes . mapFL isInconsistent instance Check p => Check (RL p) where isInconsistent = listToMaybe . catMaybes . mapRL isInconsistent instance RepairToFL p => Repair (FL p) where applyAndTryToFix NilFL = return Nothing applyAndTryToFix (p:>:ps) = do mp <- applyAndTryToFixFL p mps <- applyAndTryToFix ps return $ case (mp,mps) of (Nothing, Nothing) -> Nothing (Just (e,p'),Nothing) -> Just (e,p'+>+ps) (Nothing, Just (e,ps')) -> Just (e,p:>:ps') (Just (e,p'), Just (es,ps')) -> Just (unlines [e,es], p'+>+ps') darcs-2.14.5/src/Darcs/Patch/RepoPatch.hs0000644000000000000000000000211607346545000016173 0ustar0000000000000000module Darcs.Patch.RepoPatch ( RepoPatch ) where import Darcs.Patch.Annotate ( Annotate ) import Darcs.Patch.Apply ( Apply, ApplyState ) import Darcs.Patch.Commute ( Commute ) import Darcs.Patch.Conflict ( Conflict, CommuteNoConflicts ) import Darcs.Patch.Effect ( Effect ) import Darcs.Patch.FileHunk ( IsHunk ) import Darcs.Patch.Format ( PatchListFormat ) import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Patch.Invert ( Invert ) import Darcs.Patch.Matchable ( Matchable ) import Darcs.Patch.Merge ( Merge ) import Darcs.Patch.Prim ( PrimPatchBase, PrimOf, FromPrim ) import Darcs.Patch.Read ( ReadPatch ) import Darcs.Patch.Repair ( RepairToFL, Check ) import Darcs.Patch.Show ( ShowPatch, ShowContextPatch ) class (Apply p, Commute p, Invert p, Merge p, Effect p, IsHunk p, PatchInspect p, ReadPatch p, ShowPatch p, ShowContextPatch p, FromPrim p, Conflict p, CommuteNoConflicts p, Check p, RepairToFL p, PatchListFormat p, PrimPatchBase p, IsHunk (PrimOf p), Matchable p, Annotate p, ApplyState p ~ ApplyState (PrimOf p) ) => RepoPatch p darcs-2.14.5/src/Darcs/Patch/RepoType.hs0000644000000000000000000000346007346545000016060 0ustar0000000000000000module Darcs.Patch.RepoType ( RepoType(..), IsRepoType(..), SRepoType(..) , RebaseType(..), IsRebaseType, RebaseTypeOf, SRebaseType(..) ) where -- |This type is intended to be used as a phantom type via -- the 'DataKinds' extension, normally as part of 'RepoType'. -- Indicates whether or not a rebase is in progress. data RebaseType = IsRebase | NoRebase -- |A reflection of 'RebaseType' at the value level so that -- code can explicitly switch on it. data SRebaseType (rebaseType :: RebaseType) where SIsRebase :: SRebaseType 'IsRebase SNoRebase :: SRebaseType 'NoRebase class IsRebaseType (rebaseType :: RebaseType) where -- |Reflect 'RebaseType' to the value level so that -- code can explicitly switch on it. singletonRebaseType :: SRebaseType rebaseType instance IsRebaseType 'IsRebase where singletonRebaseType = SIsRebase instance IsRebaseType 'NoRebase where singletonRebaseType = SNoRebase -- |This type is intended to be used as a phantom type via the 'DataKinds' -- extension. It tracks different types of repositories, e.g. to -- indicate when a rebase is in progress. data RepoType = RepoType { rebaseType :: RebaseType } -- |Extract the 'RebaseType' from a 'RepoType' type family RebaseTypeOf (rt :: RepoType) :: RebaseType type instance RebaseTypeOf ('RepoType rebaseType) = rebaseType class IsRepoType (rt :: RepoType) where -- |Reflect 'RepoType' to the value level so that -- code can explicitly switch on it. singletonRepoType :: SRepoType rt -- |A reflection of 'RepoType' at the value level so that -- code can explicitly switch on it. data SRepoType (repoType :: RepoType) where SRepoType :: SRebaseType rebaseType -> SRepoType ('RepoType rebaseType) instance IsRebaseType rebaseType => IsRepoType ('RepoType rebaseType) where singletonRepoType = SRepoType singletonRebaseType darcs-2.14.5/src/Darcs/Patch/Set.hs0000644000000000000000000001143707346545000015047 0ustar0000000000000000-- Copyright (C) 2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE EmptyDataDecls, StandaloneDeriving #-} module Darcs.Patch.Set ( PatchSet(..) , Tagged(..) , SealedPatchSet , Origin , progressPatchSet , tags , emptyPatchSet , appendPSFL , patchSet2RL , patchSet2FL , patchSetfMap ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Info ( PatchInfo ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info ) import Darcs.Patch.Witnesses.Sealed ( Sealed ) import Darcs.Patch.Witnesses.Ordered ( FL, RL(..), (+<+), reverseFL, reverseRL, mapRL_RL, concatRL, mapRL ) import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..), ShowDict(ShowDictClass) ) import Darcs.Util.Progress ( progress ) -- |'Origin' is a type used to represent the initial context of a repo. data Origin type SealedPatchSet rt p wStart = Sealed ((PatchSet rt p) wStart) -- |The patches in a repository are stored in chunks broken up at \"clean\" -- tags. A tag is clean if the only patches before it in the current -- repository ordering are ones that the tag depends on (either directly -- or indirectly). Each chunk is stored in a separate inventory file on disk. -- -- A 'PatchSet' represents a repo's history as the list of patches since the -- last clean tag, and then a list of patch lists each delimited by clean tags. data PatchSet rt p wStart wY where PatchSet :: RL (Tagged rt p) wStart wX -> RL (PatchInfoAnd rt p) wX wY -> PatchSet rt p wStart wY deriving instance Show2 p => Show (PatchSet rt p wStart wY) instance Show2 p => Show1 (PatchSet rt p wStart) where showDict1 = ShowDictClass instance Show2 p => Show2 (PatchSet rt p) where showDict2 = ShowDictClass emptyPatchSet :: PatchSet rt p wX wX emptyPatchSet = PatchSet NilRL NilRL -- |A 'Tagged' is a single chunk of a 'PatchSet'. -- It has a 'PatchInfo' representing a clean tag, -- the hash of the previous inventory (if it exists), -- and the list of patches since that previous inventory. data Tagged rt p wX wZ where Tagged :: PatchInfoAnd rt p wY wZ -> Maybe String -> RL (PatchInfoAnd rt p) wX wY -> Tagged rt p wX wZ deriving instance Show2 p => Show (Tagged rt p wX wZ) instance Show2 p => Show1 (Tagged rt p wX) where showDict1 = ShowDictClass instance Show2 p => Show2 (Tagged rt p) where showDict2 = ShowDictClass -- |'patchSet2RL' takes a 'PatchSet' and returns an equivalent, linear 'RL' of -- patches. patchSet2RL :: PatchSet rt p wStart wX -> RL (PatchInfoAnd rt p) wStart wX patchSet2RL (PatchSet ts ps) = concatRL (mapRL_RL ts2rl ts) +<+ ps where ts2rl :: Tagged rt p wY wZ -> RL (PatchInfoAnd rt p) wY wZ ts2rl (Tagged t _ ps2) = ps2 :<: t -- |'patchSet2FL' takes a 'PatchSet' and returns an equivalent, linear 'FL' of -- patches. patchSet2FL :: PatchSet rt p wStart wX -> FL (PatchInfoAnd rt p) wStart wX patchSet2FL = reverseRL . patchSet2RL -- |'appendPSFL' takes a 'PatchSet' and a 'FL' of patches that "follow" the -- PatchSet, and concatenates the patches into the PatchSet. appendPSFL :: PatchSet rt p wStart wX -> FL (PatchInfoAnd rt p) wX wY -> PatchSet rt p wStart wY appendPSFL (PatchSet ts ps) newps = PatchSet ts (ps +<+ reverseFL newps) -- |Runs a progress action for each tag and patch in a given PatchSet, using -- the passed progress message. Does not alter the PatchSet. progressPatchSet :: String -> PatchSet rt p wStart wX -> PatchSet rt p wStart wX progressPatchSet k (PatchSet ts ps) = PatchSet (mapRL_RL progressTagged ts) (mapRL_RL prog ps) where prog = progress k progressTagged :: Tagged rt p wY wZ -> Tagged rt p wY wZ progressTagged (Tagged t h tps) = Tagged (prog t) h (mapRL_RL prog tps) -- |'tags' returns the PatchInfos corresponding to the tags of a given -- 'PatchSet'. tags :: PatchSet rt p wStart wX -> [PatchInfo] tags (PatchSet ts _) = mapRL taggedTagInfo ts where taggedTagInfo :: Tagged rt p wY wZ -> PatchInfo taggedTagInfo (Tagged t _ _) = info t patchSetfMap:: (forall wW wZ . PatchInfoAnd rt p wW wZ -> IO a) -> PatchSet rt p wW' wZ' -> IO [a] patchSetfMap f = sequence . mapRL f . patchSet2RL darcs-2.14.5/src/Darcs/Patch/Show.hs0000644000000000000000000000667007346545000015237 0ustar0000000000000000-- Copyright (C) 2002-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.Show ( ShowPatchBasic(..) , displayPatch , ShowPatchFor(..) , ShowPatch(..) , ShowContextPatch(..) , formatFileName ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString.Char8 as BC ( unpack ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.ApplyMonad ( ApplyMonad ) import Darcs.Patch.Format ( FileNameFormat(..) ) import Darcs.Patch.Witnesses.Ordered ( FL, mapFL ) import Darcs.Util.ByteString ( packStringToUTF8, encodeLocale ) import Darcs.Util.English ( plural, Noun(Noun) ) import Darcs.Util.Path ( FileName, encodeWhite, fn2fp ) import Darcs.Util.Printer ( Doc, vcat, text, packedString ) data ShowPatchFor = ForDisplay | ForStorage displayPatch :: ShowPatchBasic p => p wX wY -> Doc displayPatch p = showPatch ForDisplay p class ShowPatchBasic p where showPatch :: ShowPatchFor -> p wX wY -> Doc class ShowPatchBasic p => ShowContextPatch p where -- | showContextPatch is used to add context to a patch, as diff -- -u does. Thus, it differs from showPatch only for hunks. It is -- used for instance before putting it into a bundle. As this -- unified context is not included in patch representation, this -- requires access to the tree. showContextPatch :: (ApplyMonad (ApplyState p) m) => ShowPatchFor -> p wX wY -> m Doc -- This class is used only for user interaction, not for storage class ShowPatchBasic p => ShowPatch p where showNicely :: p wX wY -> Doc showNicely = showPatch ForDisplay description :: p wX wY -> Doc description = showPatch ForDisplay summary :: p wX wY -> Doc summaryFL :: FL p wX wY -> Doc summaryFL = vcat . mapFL summary thing :: p wX wY -> String thing _ = "patch" things :: p wX wY -> String things x = plural (Noun $ thing x) "" -- | Format a 'FileName' to a 'Doc' according to the given 'FileNameFormat'. -- -- NOTE: This is not only used for display but also to format patch files. This is -- why we have to do the white space encoding here. -- See 'Darcs.Repository.Hashed.writePatchIfNecessary'. -- -- Besides white space encoding, for 'NewFormat' we just pack it into a 'Doc'. For -- 'OldFormat' we must emulate the non-standard darcs-1 encoding of file paths: it -- is an UTF8 encoding of the raw byte stream, interpreted as code points. -- -- See also 'Darcs.Patch.Show.readFileName'. formatFileName :: FileNameFormat -> FileName -> Doc formatFileName OldFormat = packedString . packStringToUTF8 . BC.unpack . encodeLocale . encodeWhite . fn2fp formatFileName NewFormat = text . encodeWhite . fn2fp formatFileName UserFormat = text . fn2fp darcs-2.14.5/src/Darcs/Patch/Split.hs0000644000000000000000000002122507346545000015403 0ustar0000000000000000{-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-} -- Copyright (C) 2009 Ganesh Sittampalam -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. module Darcs.Patch.Split ( Splitter(..) , rawSplitter , noSplitter , primSplitter , reversePrimSplitter ) where import Prelude () import Darcs.Prelude import Data.List ( intersperse ) import Darcs.Patch.Witnesses.Ordered import Darcs.Patch.Witnesses.Sealed import Darcs.Patch.FileHunk ( FileHunk(..), IsHunk(..) ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.Show ( showPatch, ShowPatch(..) ) import Darcs.Patch.Invert( Invert(..), invertFL ) import Darcs.Patch.Prim ( PrimPatch, canonize, canonizeFL, primFromHunk ) import Darcs.Patch.ReadMonads ( parseStrictly ) import Darcs.Patch.Read () import Darcs.Patch.Show ( ShowPatchFor(ForDisplay) ) import Darcs.Patch.Viewing () import Darcs.Util.Printer ( renderPS ) import qualified Darcs.Util.Diff as D ( DiffAlgorithm ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC -- |A splitter is something that can take a patch and (possibly) render it -- as text in some format of its own choosing. -- This text can then be presented to the user for editing, and the result -- given to the splitter for parsing. -- If the parse succeeds, the result is a list of patches that could replace -- the original patch in any context. -- Typically this list will contain the changed version of the patch, along -- with fixup pieces to ensure that the overall effect of the list is the same -- as the original patch. -- The individual elements of the list can then be offered separately to the -- user, allowing them to accept some and reject others. -- -- There's no immediate application for a splitter for anything other than -- Prim (you shouldn't go editing named patches, you'll break them!) -- However you might want to compose splitters for FilePatchType to make -- splitters for Prim etc, and the generality doesn't cost anything. data Splitter p = Splitter { applySplitter :: forall wX wY. p wX wY -> Maybe (B.ByteString, B.ByteString -> Maybe (FL p wX wY)) -- canonization is needed to undo the effects of splitting -- Typically, the list returned by applySplitter will not -- be in the simplest possible form (since the user will have -- deliberately added extra stuff). Once the user has selected -- the pieces they want, we need to make sure that we eliminate -- any remaining redundancy in the selected pieces, otherwise -- we might record (or whatever) a rather strange looking patch. -- This hook allows the splitter to provide an appropriate -- function for doing this. , canonizeSplit :: forall wX wY. FL p wX wY -> FL p wX wY } {- Some facts that probably ought to be true about splitters: should make some QC properties applySplitter p = Just (bs, f) ==> f bs == Just (p :>: NilFL) applySplitter p = Just (bs, f) ; f bs' = Just ps ==> canonizeSplit ps = p :>: NilFL -} -- Does not canonize as there is no generic operation to do this. withEditedHead :: Invert p => p wX wY -> p wX wZ -> FL p wX wY withEditedHead p res = res :>: invert res :>: p :>: NilFL -- |This generic splitter just lets the user edit the printed representation of the -- patch. Should not be used expect for testing and experimentation. rawSplitter :: (ShowPatch p, ReadPatch p, Invert p) => Splitter p rawSplitter = Splitter { applySplitter = \p -> Just (renderPS . showPatch ForDisplay $ p ,\str -> case parseStrictly readPatch' str of Just (Sealed res, _) -> Just (withEditedHead p res) _ -> Nothing) , canonizeSplit = id } -- |Never splits. In other code we normally pass around Maybe Splitter instead -- of using this as the default, because it saves clients that don't care about -- splitting from having to import this module just to get noSplitter. noSplitter :: Splitter p noSplitter = Splitter { applySplitter = const Nothing, canonizeSplit = id } doPrimSplit :: PrimPatch prim => D.DiffAlgorithm -> prim wX wY -> Maybe (B.ByteString, B.ByteString -> Maybe (FL prim wX wY)) doPrimSplit da = doPrimSplit_ da True explanation where explanation = map BC.pack [ "Interactive hunk edit:" , " - Edit the section marked 'AFTER'" , " - Arbitrary editing is supported" , " - This will only affect the patch, not your working tree" , " - Hints:" , " - To split added text, delete the part you want to postpone" , " - To split removed text, copy back the part you want to retain" , "" ] doPrimSplit_ :: (PrimPatch prim, IsHunk p) => D.DiffAlgorithm -> Bool -> [B.ByteString] -> p wX wY -> Maybe (B.ByteString, B.ByteString -> Maybe (FL prim wX wY)) doPrimSplit_ da edit_before_part helptext (isHunk -> Just (FileHunk fn n before after)) = Just (B.concat $ intersperse (BC.pack "\n") $ concat [ helptext , [mkSep " BEFORE (reference) =========================="] , before , [mkSep "=== AFTER (edit) ============================="] , after , [mkSep "=== (edit above) ============================="] ], \bs -> do let ls = BC.split '\n' bs (_, ls2) <- breakSep ls -- before (before', ls3) <- breakSep ls2 -- after 1 (after', _) <- breakSep ls3 -- after return $ if edit_before_part then hunk before before' +>+ hunk before' after' +>+ hunk after' after else hunk before after' +>+ hunk after' after) where sep = BC.pack "==========================" hunk :: PrimPatch prim => [B.ByteString] -> [B.ByteString] -> FL prim wA wB hunk b a = canonize da (primFromHunk (FileHunk fn n b a)) mkSep s = BC.append sep (BC.pack s) breakSep xs = case break (sep `BC.isPrefixOf`) xs of (_, []) -> Nothing (ys, _:zs) -> Just (ys, zs) doPrimSplit_ _ _ _ _ = Nothing -- |Split a primitive hunk patch up by allowing the user to edit both the -- before and after lines, then insert fixup patches to clean up the mess. primSplitter :: PrimPatch p => D.DiffAlgorithm -> Splitter p primSplitter da = Splitter { applySplitter = doPrimSplit da , canonizeSplit = canonizeFL da } doReversePrimSplit :: PrimPatch prim => D.DiffAlgorithm -> prim wX wY -> Maybe (B.ByteString, B.ByteString -> Maybe (FL prim wX wY)) doReversePrimSplit da prim = do (text, parser) <- doPrimSplit_ da False reverseExplanation (invert prim) let parser' p = do patch <- parser p return . reverseRL $ invertFL patch return (text, parser') where reverseExplanation = map BC.pack [ "Interactive hunk edit:" , " - Edit the section marked 'AFTER' (representing the state to which you'll revert)" , " - Arbitrary editing is supported" , " - Your working tree will be returned to the 'AFTER' state" , " - Do not touch the 'BEFORE' section" , " - Hints:" , " - To revert only a part of a text addition, delete the part you want to get rid of" , " - To revert only a part of a removal, copy back the part you want to retain" , "" ] reversePrimSplitter :: PrimPatch prim => D.DiffAlgorithm -> Splitter prim reversePrimSplitter da = Splitter { applySplitter = doReversePrimSplit da , canonizeSplit = canonizeFL da } darcs-2.14.5/src/Darcs/Patch/Summary.hs0000644000000000000000000001366607346545000015757 0ustar0000000000000000module Darcs.Patch.Summary ( plainSummary, plainSummaryPrim, plainSummaryPrims, xmlSummary ) where import Prelude () import Darcs.Prelude import Darcs.Util.Path ( fn2fp ) import Darcs.Patch.Conflict ( Conflict(..), IsConflictedPrim(IsC), ConflictState(..) ) import Darcs.Patch.Format ( FileNameFormat(UserFormat) ) import Darcs.Patch.Prim.Class ( PrimDetails(..), PrimPatchBase ) import Darcs.Patch.Show ( formatFileName ) import Darcs.Patch.SummaryData ( SummDetail(..), SummOp(..) ) import Darcs.Patch.Witnesses.Ordered ( FL, mapFL ) import Darcs.Util.Printer ( Doc, empty, vcat, text, minus, plus, ($$), (<+>) ) plainSummaryPrim :: PrimDetails prim => prim wX wY -> Doc plainSummaryPrim = vcat . map (summChunkToLine False) . genSummary . (:[]) . IsC Okay plainSummaryPrims :: PrimDetails prim => Bool -> FL prim wX wY -> Doc plainSummaryPrims machineReadable = vcat . map (summChunkToLine machineReadable) . genSummary . mapFL (IsC Okay) plainSummary :: (Conflict e, PrimPatchBase e) => e wX wY -> Doc plainSummary = vcat . map (summChunkToLine False) . genSummary . conflictedEffect xmlSummary :: (Conflict p, PrimPatchBase p) => p wX wY -> Doc xmlSummary p = text "" $$ (vcat . map summChunkToXML . genSummary . conflictedEffect $ p) $$ text "" -- Yuck duplicated code below... escapeXML :: String -> Doc escapeXML = text . strReplace '\'' "'" . strReplace '"' """ . strReplace '>' ">" . strReplace '<' "<" . strReplace '&' "&" strReplace :: Char -> String -> String -> String strReplace _ _ [] = [] strReplace x y (z:zs) | x == z = y ++ strReplace x y zs | otherwise = z : strReplace x y zs -- end yuck duplicated code. -- | High-level representation of a piece of patch summary data SummChunk = SummChunk SummDetail ConflictState deriving (Ord, Eq) genSummary :: forall p . PrimDetails p => [IsConflictedPrim p] -> [SummChunk] genSummary p = combine $ concatMap s2 p where s2 :: IsConflictedPrim p -> [SummChunk] s2 (IsC c x) = map (`SummChunk` c) $ summarizePrim x combine (x1@(SummChunk d1 c1) : x2@(SummChunk d2 c2) : ss) = case combineDetail d1 d2 of Nothing -> x1 : combine (x2:ss) Just d3 -> combine $ SummChunk d3 (combineConflictStates c1 c2) : ss combine (x:ss) = x : combine ss combine [] = [] -- combineDetail (SummFile o1 f1 r1 a1 x1) (SummFile o2 f2 r2 a2 x2) | f1 == f2 = do o3 <- combineOp o1 o2 return $ SummFile o3 f1 (r1 + r2) (a1 + a2) (x1 + x2) combineDetail _ _ = Nothing -- combineConflictStates Conflicted _ = Conflicted combineConflictStates _ Conflicted = Conflicted combineConflictStates Duplicated _ = Duplicated combineConflictStates _ Duplicated = Duplicated combineConflictStates Okay Okay = Okay -- Don't combine AddFile and RmFile: (maybe an old revision of) darcs -- allows a single patch to add and remove the same file, see issue 185 combineOp SummAdd SummRm = Nothing combineOp SummRm SummAdd = Nothing combineOp SummAdd _ = Just SummAdd combineOp _ SummAdd = Just SummAdd combineOp SummRm _ = Just SummRm combineOp _ SummRm = Just SummRm combineOp SummMod SummMod = Just SummMod summChunkToXML :: SummChunk -> Doc summChunkToXML (SummChunk detail c) = case detail of SummRmDir f -> xconf c "remove_directory" (xfn f) SummAddDir f -> xconf c "add_directory" (xfn f) SummFile SummRm f _ _ _ -> xconf c "remove_file" (xfn f) SummFile SummAdd f _ _ _ -> xconf c "add_file" (xfn f) SummFile SummMod f r a x -> xconf c "modify_file" $ xfn f <> xrm r <> xad a <> xrp x SummMv f1 f2 -> text " xfn f1 <> text "\" to=\"" <> xfn f2 <> text"\"/>" SummNone -> empty where xconf Okay t x = text ('<':t++">") $$ x $$ text ("") xconf Conflicted t x = text ('<':t++" conflict='true'>") $$ x $$ text ("") xconf Duplicated t x = text ('<':t++" duplicate='true'>") $$ x $$ text ("") xfn = escapeXML . dropDotSlash . fn2fp -- xad 0 = empty xad a = text "" xrm 0 = empty xrm a = text "" xrp 0 = empty xrp a = text "" summChunkToLine :: Bool -> SummChunk -> Doc summChunkToLine machineReadable (SummChunk detail c) = case detail of SummRmDir f -> lconf c "R" $ formatFileName UserFormat f <> text "/" SummAddDir f -> lconf c "A" $ formatFileName UserFormat f <> text "/" SummFile SummRm f _ _ _ -> lconf c "R" $ formatFileName UserFormat f SummFile SummAdd f _ _ _ -> lconf c "A" $ formatFileName UserFormat f SummFile SummMod f r a x | machineReadable -> lconf c "M" $ formatFileName UserFormat f | otherwise -> lconf c "M" $ formatFileName UserFormat f <+> rm r <+> ad a <+> rp x SummMv f1 f2 | machineReadable -> text "F " <> formatFileName UserFormat f1 $$ text "T " <> formatFileName UserFormat f2 | otherwise -> text " " <> formatFileName UserFormat f1 <> text " -> " <> formatFileName UserFormat f2 SummNone -> case c of Okay -> empty _ -> lconf c "" empty where lconf Okay t x = text t <+> x lconf Conflicted t x = text (t ++ "!") <+> x lconf Duplicated t x | machineReadable = text t <+> x | otherwise = text t <+> x <+> text "duplicate" -- ad 0 = empty ad a = plus <> text (show a) rm 0 = empty rm a = minus <> text (show a) rp 0 = empty rp a = text "r" <> text (show a) dropDotSlash :: FilePath -> FilePath dropDotSlash ('.':'/':str) = dropDotSlash str dropDotSlash str = str darcs-2.14.5/src/Darcs/Patch/SummaryData.hs0000644000000000000000000000066007346545000016537 0ustar0000000000000000module Darcs.Patch.SummaryData ( SummDetail(..), SummOp(..) ) where import Prelude () import Darcs.Prelude import Darcs.Util.Path ( FileName ) data SummDetail = SummAddDir FileName | SummRmDir FileName | SummFile SummOp FileName Int Int Int | SummMv FileName FileName | SummNone deriving (Ord, Eq) data SummOp = SummAdd | SummRm | SummMod deriving (Ord, Eq) darcs-2.14.5/src/Darcs/Patch/TokenReplace.hs0000644000000000000000000001021707346545000016663 0ustar0000000000000000module Darcs.Patch.TokenReplace ( tryTokReplace , forceTokReplace , annotateReplace , breakToTokens , defaultToks ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import Darcs.Patch.RegChars ( regChars ) -- | @breakOutToken tokChars input@ splits the @input@ 'ByteString' into -- @'Just' (before, token, after)@, where @token@ is the first non-empty -- substring consisting only of 'Char's in @tokChars@, or 'Nothing' if no token -- was found. The 'Char's in @tokChars@ should not have code points larger than -- 255 (0xff). breakOutToken :: String -> BC.ByteString -> Maybe (BC.ByteString, BC.ByteString, BC.ByteString) breakOutToken tokChars input | not (B.null tok) = Just (before, tok, remaining) | otherwise = Nothing where isTokChar = regChars tokChars (before, tokAndRest) = BC.break isTokChar input (tok, remaining) = BC.break (not . isTokChar) tokAndRest -- | @tryTokReplace tokChars old new input@ tries to find the token @old@ and -- replace it with the token @new@ everywhere in the @input@, returning 'Just' -- the modified @input@, unless the token @new@ is already in the @input@ in -- which case 'Nothing' is returned. A token is a sequence of bytes that match -- the class defined by @tokChars@. This function is supposed to work -- efficiently with large @input@s i.e. whole files. tryTokReplace :: String -> B.ByteString -> B.ByteString -> B.ByteString -> Maybe B.ByteString tryTokReplace tokChars old new | B.null old = bug "tryTokInternal called with empty old token" | BC.any (not . isTokChar) old = bug "tryTokInternal called with old non-token" | BC.any (not . isTokChar) new = bug "tryTokInternal called with new non-token" | otherwise = fmap B.concat . loop 0 where isTokChar = regChars tokChars loop !from input = case BC.findIndex isTokChar (B.drop from input) of Nothing -> Just [input] Just start -> case BC.span isTokChar (B.drop (from + start) input) of (tok, rest) | tok == old -> (B.take (from + start) input :).(new :) <$> loop 0 rest | tok == new -> Nothing | otherwise -> loop (from + start + B.length tok) input -- | @forceTokReplace tokChars old new input@ replaces all occurrences of -- the @old@ token with the @new@ one, throughout the @input@. forceTokReplace :: String -> B.ByteString -> B.ByteString -> B.ByteString -> B.ByteString forceTokReplace tokChars old new | B.null old = bug "tryTokInternal called with empty old token" | BC.any (not . isTokChar) old = bug "tryTokInternal called with old non-token" | BC.any (not . isTokChar) new = bug "tryTokInternal called with new non-token" | otherwise = B.concat . loop 0 where isTokChar = regChars tokChars len = B.length old loop !from input = case B.breakSubstring old (B.drop from input) of (before, match) | B.null match -> [input] -- not found | B.null before || not (isTokChar (BC.last before)) , B.length match == len || not (isTokChar (BC.index match len)) -> -- found and is token B.take (from + B.length before) input : new : loop 0 (B.drop len match) | otherwise -> -- found but not a token loop (from + B.length before + len) input -- | Check if a token replace operation touches the given line. annotateReplace :: String -> B.ByteString -> B.ByteString -> B.ByteString -> Bool annotateReplace tokChars old new input = case breakOutToken tokChars input of Just (_, tok, remaining) -> (tok == old || annotateReplace tokChars old new remaining) Nothing -> False -- | Break a 'Bytestring' into tokens, according to 'defaultToks', -- discarding non-tokens. breakToTokens :: BC.ByteString -> [BC.ByteString] breakToTokens input = case breakOutToken defaultToks input of Nothing -> [] Just (_, tok, remaining) -> tok : breakToTokens remaining defaultToks :: String defaultToks = "A-Za-z_0-9" darcs-2.14.5/src/Darcs/Patch/TouchesFiles.hs0000644000000000000000000001133307346545000016704 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.TouchesFiles ( lookTouch , chooseTouching , choosePreTouching , selectTouching , deselectNotTouching , selectNotTouching ) where import Darcs.Prelude import Prelude () import Data.List (isSuffixOf, nub) import Darcs.Patch.Apply (Apply, ApplyState, applyToFilePaths, effectOnFilePaths) import Darcs.Patch.Choices (PatchChoices, Label, LabelledPatch, patchChoices, label, getChoices, forceFirsts, forceLasts, unLabel) import Darcs.Patch.Commute (Commute) import Darcs.Patch.Inspect (PatchInspect) import Darcs.Patch.Invert (invert, Invert) import Darcs.Patch.Witnesses.Ordered (FL(..), (:>)(..), mapFL_FL, (+>+)) import Darcs.Patch.Witnesses.Sealed (Sealed, seal) import Darcs.Util.Tree (Tree) labelTouching :: (Apply p, PatchInspect p, ApplyState p ~ Tree) => Bool -> [FilePath] -> FL (LabelledPatch p) wX wY -> [Label] labelTouching _ _ NilFL = [] labelTouching wantTouching fs (lp :>: lps) = case lookTouchOnlyEffect fs (unLabel lp) of (doesTouch, fs') -> let rest = labelTouching wantTouching fs' lps in (if doesTouch == wantTouching then (label lp :) else id) rest labelNotTouchingFM :: (Apply p, Commute p, PatchInspect p, ApplyState p ~ Tree) => [FilePath] -> PatchChoices p wX wY -> [Label] labelNotTouchingFM files pc = case getChoices pc of fc :> mc :> _ -> labelTouching False (map fix files) (fc +>+ mc) selectTouching :: (Apply p, Commute p, PatchInspect p, ApplyState p ~ Tree) => Maybe [FilePath] -> PatchChoices p wX wY -> PatchChoices p wX wY selectTouching Nothing pc = pc selectTouching (Just files) pc = forceFirsts xs pc where xs = case getChoices pc of _ :> mc :> lc -> labelTouching True (map fix files) (mc +>+ lc) deselectNotTouching :: (Apply p, Commute p, PatchInspect p, ApplyState p ~ Tree) => Maybe [FilePath] -> PatchChoices p wX wY -> PatchChoices p wX wY deselectNotTouching Nothing pc = pc deselectNotTouching (Just files) pc = forceLasts (labelNotTouchingFM files pc) pc selectNotTouching :: (Apply p, Commute p, PatchInspect p, ApplyState p ~ Tree) => Maybe [FilePath] -> PatchChoices p wX wY -> PatchChoices p wX wY selectNotTouching Nothing pc = pc selectNotTouching (Just files) pc = forceFirsts (labelNotTouchingFM files pc) pc fix :: FilePath -> FilePath fix f | "/" `isSuffixOf` f = fix $ init f fix "" = "." fix "." = "." fix f = "./" ++ f chooseTouching :: (Apply p, Commute p, PatchInspect p, ApplyState p ~ Tree) => Maybe [FilePath] -> FL p wX wY -> Sealed (FL p wX) chooseTouching Nothing p = seal p chooseTouching files p = case getChoices $ selectTouching files $ patchChoices p of fc :> _ :> _ -> seal $ mapFL_FL unLabel fc choosePreTouching :: (Apply p, Commute p, Invert p, PatchInspect p, ApplyState p ~ Tree) => Maybe [FilePath] -> FL p wX wY -> Sealed (FL p wX) choosePreTouching files patch = chooseTouching filesBeforePatch patch where filesBeforePatch = effectOnFilePaths (invert patch) <$> files lookTouchOnlyEffect :: (Apply p, ApplyState p ~ Tree) => [FilePath] -> p wX wY -> (Bool, [FilePath]) lookTouchOnlyEffect fs p = (wasTouched, fs') where (wasTouched, _, fs', _) = lookTouch Nothing fs p lookTouch :: (Apply p, ApplyState p ~ Tree) => Maybe [(FilePath, FilePath)] -> [FilePath] -> p wX wY -> (Bool, [FilePath], [FilePath], [(FilePath, FilePath)]) lookTouch renames fs p = (anyTouched, touchedFs, fs', renames') where touchedFs = nub . concatMap fsAffectedBy $ affected fsAffectedBy af = filter (affectedBy af) fs anyTouched = length touchedFs > 0 affectedBy :: FilePath -> FilePath -> Bool touched `affectedBy` f = touched == f || touched `isSubPathOf` f || f `isSubPathOf` touched isSubPathOf :: FilePath -> FilePath -> Bool path `isSubPathOf` parent = case splitAt (length parent) path of (path', '/':_) -> path' == parent _ -> False (affected, fs', renames') = applyToFilePaths p renames fs darcs-2.14.5/src/Darcs/Patch/Type.hs0000644000000000000000000000045207346545000015230 0ustar0000000000000000module Darcs.Patch.Type ( PatchType(..), patchType ) where import Darcs.Patch.RepoType ( RepoType ) -- |Used for indicating a patch type without having a concrete patch data PatchType (rt :: RepoType) (p :: * -> * -> *) = PatchType patchType :: p wX wY -> PatchType rt p patchType _ = PatchType darcs-2.14.5/src/Darcs/Patch/V1.hs0000644000000000000000000000110307346545000014567 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.V1 ( RepoPatchV1 ) where import Darcs.Patch.Annotate ( Annotate ) import Darcs.Patch.Matchable ( Matchable ) import Darcs.Patch.Prim ( PrimPatch ) import Darcs.Patch.RepoPatch ( RepoPatch ) import Darcs.Patch.V1.Apply () import Darcs.Patch.V1.Commute () import Darcs.Patch.V1.Core ( RepoPatchV1 ) import Darcs.Patch.V1.Read () import Darcs.Patch.V1.Show () import Darcs.Patch.V1.Viewing () instance PrimPatch prim => Matchable (RepoPatchV1 prim) instance (PrimPatch prim, Annotate prim) => RepoPatch (RepoPatchV1 prim) darcs-2.14.5/src/Darcs/Patch/V1/0000755000000000000000000000000007346545000014240 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/V1/Apply.hs0000644000000000000000000000175607346545000015672 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.V1.Apply () where import Prelude () import Darcs.Prelude import Darcs.Patch.Annotate ( Annotate(..) ) import Darcs.Patch.Apply ( ApplyState, Apply, apply ) import Darcs.Patch.Prim ( PrimPatch, applyPrimFL ) import Darcs.Patch.Repair ( RepairToFL, applyAndTryToFixFL, mapMaybeSnd ) import Darcs.Patch.Effect ( effect ) import Darcs.Patch.V1.Commute () import Darcs.Patch.V1.Core ( RepoPatchV1(..) ) import Darcs.Patch.Witnesses.Ordered ( mapFL_FL ) instance PrimPatch prim => Apply (RepoPatchV1 prim) where type ApplyState (RepoPatchV1 prim) = ApplyState prim apply p = applyPrimFL $ effect p instance PrimPatch prim => RepairToFL (RepoPatchV1 prim) where applyAndTryToFixFL (PP x) = mapMaybeSnd (mapFL_FL PP) `fmap` applyAndTryToFixFL x applyAndTryToFixFL x = do apply x; return Nothing instance (PrimPatch prim, Annotate prim) => Annotate (RepoPatchV1 prim) where annotate = annotate . effect darcs-2.14.5/src/Darcs/Patch/V1/Commute.hs0000644000000000000000000005131207346545000016207 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.V1.Commute ( merge, merger, unravel, publicUnravel, ) where import Prelude () import Darcs.Prelude import Control.Monad ( MonadPlus, mplus, msum, mzero, guard ) import Control.Applicative ( Alternative(..) ) import Darcs.Patch.Commute ( selfCommuter ) import Darcs.Patch.CommuteFn ( commuterIdFL, commuterFLId ) import Darcs.Util.Path ( FileName ) import Darcs.Util.Printer ( errorDoc ) import Darcs.Patch.Invert ( invertRL ) import Darcs.Patch.Merge ( Merge(..), naturalMerge ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Invert ( Invert(..) ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.V1.Core ( RepoPatchV1(..), isMerger, mergerUndo ) import Darcs.Patch.Conflict ( Conflict(..), listConflictedFiles , IsConflictedPrim(..), ConflictState(..), CommuteNoConflicts(..) , mangleUnravelled ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.FileHunk ( IsHunk(..) ) import Darcs.Patch.Prim ( FromPrim(..), PrimPatch, is_filepatch, sortCoalesceFL, ) import Darcs.Patch.Permutations ( headPermutationsRL, simpleHeadPermutationsFL ) import Darcs.Util.Printer ( text, vcat, ($$) ) import Darcs.Patch.V1.Show ( showPatch_ ) import Data.List ( nub, nubBy ) import Data.List.Ordered ( nubSort ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..) , mapSeal, unseal, FlippedSeal(..), mapFlipped , unsafeUnseal, unsafeUnsealFlipped ) import Darcs.Patch.Witnesses.Eq ( EqCheck(..), Eq2(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP, unsafeCoercePStart , unsafeCoercePEnd ) import Darcs.Patch.Witnesses.Ordered ( mapFL_FL, mapFL, FL(..), RL(..), (:/\:)(..), (:\/:)(..), (:>)(..), lengthFL, mapRL, reverseFL, reverseRL, concatFL ) data Perhaps a = Unknown | Failed | Succeeded a instance Functor Perhaps where fmap _ Unknown = Unknown fmap _ Failed = Failed fmap f (Succeeded x) = Succeeded (f x) instance Applicative Perhaps where pure = Succeeded _ <*> Failed = Failed _ <*> Unknown = Unknown Failed <*> _ = Failed Unknown <*> _ = Unknown Succeeded f <*> Succeeded x = Succeeded (f x) instance Monad Perhaps where (Succeeded x) >>= k = k x Failed >>= _ = Failed Unknown >>= _ = Unknown return = Succeeded #if MIN_VERSION_base(4,13,0) instance MonadFail Perhaps where #endif fail _ = Unknown instance Alternative Perhaps where empty = Unknown Unknown <|> ys = ys Failed <|> _ = Failed (Succeeded x) <|> _ = Succeeded x instance MonadPlus Perhaps where mzero = Unknown mplus = (<|>) toMaybe :: Perhaps a -> Maybe a toMaybe (Succeeded x) = Just x toMaybe _ = Nothing toPerhaps :: Maybe a -> Perhaps a toPerhaps (Just x) = Succeeded x toPerhaps Nothing = Failed -- | 'cleverCommute' attempts to commute two patches @p1@ and @p2@, in their -- original order, with the given commute function. If the commute function -- doesn't know how to handle the patches (i.e. it returns Unknown as a -- result), then we try again with @invert p2@ and @invert p1@ (inverting the -- results, if succesful). -- -- TODO: when can the first attempt fail, but the second not? What's so clever -- in this function? cleverCommute :: Invert prim => CommuteFunction prim -> CommuteFunction prim cleverCommute c (p1 :> p2) = case c (p1 :> p2) of Succeeded x -> Succeeded x Failed -> Failed Unknown -> case c (invert p2 :> invert p1) of Succeeded (ip1' :> ip2') -> Succeeded (invert ip2' :> invert ip1') Failed -> Failed Unknown -> Unknown -- | If we have two Filepatches which modify different files, we can return a -- result early, since the patches trivially commute. speedyCommute :: PrimPatch prim => CommuteFunction prim speedyCommute (p1 :> p2) | Just m1 <- isFilepatchMerger p1 , Just m2 <- isFilepatchMerger p2 , m1 /= m2 = Succeeded (unsafeCoerceP p2 :> unsafeCoerceP p1) | otherwise = Unknown everythingElseCommute :: forall prim . PrimPatch prim => CommuteFunction prim everythingElseCommute (PP p1 :> PP p2) = toPerhaps $ do p2' :> p1' <- commute (p1 :> p2) return (PP p2' :> PP p1') everythingElseCommute ps = msum [ cleverCommute commuteRecursiveMerger ps , cleverCommute otherCommuteRecursiveMerger ps ] {- Note that it must be true that commutex (A^-1 A, P) = Just (P, A'^-1 A') and if commutex (A, B) == Just (B', A') then commutex (B^-1, A^-1) == Just (A'^-1, B'^-1) -} unsafeMerger :: PrimPatch prim => String -> RepoPatchV1 prim wX wY -> RepoPatchV1 prim wX wZ -> RepoPatchV1 prim wA wB unsafeMerger x p1 p2 = unsafeCoercePStart $ unsafeUnseal $ merger x p1 p2 -- | Attempt to commute two patches, the first of which is a Merger patch. mergerCommute :: PrimPatch prim => (RepoPatchV1 prim :> RepoPatchV1 prim) wX wY -> Perhaps ((RepoPatchV1 prim :> RepoPatchV1 prim) wX wY) mergerCommute (pA :> Merger _ _ p1 p2) | unsafeCompare pA p1 = Succeeded (unsafeCoercePStart p2 :> unsafeMerger "0.0" p2 p1) | unsafeCompare pA (invert (unsafeMerger "0.0" p2 p1)) = Failed mergerCommute (Merger _ _ b' c'' :> Merger _ _ (Merger _ _ c b) (Merger _ _ c' a)) | unsafeCompare b' b && unsafeCompare c c' && unsafeCompare c c'' = Succeeded ( unsafeMerger "0.0" b (unsafeCoercePStart a) :> unsafeMerger "0.0" (unsafeMerger "0.0" b (unsafeCoercePStart a)) (unsafeMerger "0.0" b c) ) mergerCommute _ = Unknown instance PrimPatch prim => Merge (RepoPatchV1 prim) where merge (y :\/: z) = case actualMerge (y:\/:z) of -- actualMerge returns one "arm" of a merge result (@y'@, which applies -- "after" @z@), but we need to return both arms. We therefore commute -- @z@ and @y'@, to obtain a @z'@, which applies "after" @y'' == y@. Sealed y' -> case commute (z :> y') of Nothing -> errorDoc $ text "merge_patches bug" $$ showPatch_ y $$ showPatch_ z $$ showPatch_ y' Just (_ :> z') -> unsafeCoercePStart z' :/\: y' instance PrimPatch prim => Commute (RepoPatchV1 prim) where commute x = toMaybe $ msum [speedyCommute x, (cleverCommute mergerCommute) x, everythingElseCommute x ] instance PrimPatch prim => PatchInspect (RepoPatchV1 prim) where -- Recurse on everything, these are potentially spoofed patches listTouchedFiles (Merger _ _ p1 p2) = nubSort $ listTouchedFiles p1 ++ listTouchedFiles p2 listTouchedFiles c@(Regrem{}) = listTouchedFiles $ invert c listTouchedFiles (PP p) = listTouchedFiles p hunkMatches f (Merger _ _ p1 p2) = hunkMatches f p1 || hunkMatches f p2 hunkMatches f c@(Regrem{}) = hunkMatches f $ invert c hunkMatches f (PP p) = hunkMatches f p commuteNoMerger :: PrimPatch prim => MaybeCommute prim commuteNoMerger x = toMaybe $ msum [ speedyCommute x , everythingElseCommute x ] isFilepatchMerger :: PrimPatch prim => RepoPatchV1 prim wX wY -> Maybe FileName isFilepatchMerger (PP p) = is_filepatch p isFilepatchMerger (Merger _ _ p1 p2) = do f1 <- isFilepatchMerger p1 f2 <- isFilepatchMerger p2 if f1 == f2 then return f1 else Nothing isFilepatchMerger (Regrem und unw p1 p2) = isFilepatchMerger (Merger und unw p1 p2) commuteRecursiveMerger :: PrimPatch prim => (RepoPatchV1 prim :> RepoPatchV1 prim) wX wY -> Perhaps ((RepoPatchV1 prim :> RepoPatchV1 prim) wX wY) commuteRecursiveMerger (pA :> p@(Merger _ _ p1 p2)) = toPerhaps $ do (_ :> pA') <- commuterIdFL selfCommuter (pA :> undo) _ <- commuterIdFL selfCommuter (pA' :> invert undo) (_ :> pAmid) <- commute (pA :> unsafeCoercePStart (invert p1)) (p1' :> pAx) <- commute (pAmid :> p1) guard (pAx `unsafeCompare` pA) (p2' :> _) <- commute (pAmid :> p2) (p2o :> _) <- commute (invert pAmid :> p2') guard (p2o `unsafeCompare` p2) let p' = if unsafeCompare p1' p1 && unsafeCompare p2' p2 then unsafeCoerceP p else unsafeMerger "0.0" p1' p2' undo' = mergerUndo p' (pAo :> _) <- commuterFLId selfCommuter (undo' :> pA') guard (pAo `unsafeCompare` pA) return (p' :> pA') where undo = mergerUndo p commuteRecursiveMerger _ = Unknown otherCommuteRecursiveMerger :: PrimPatch prim => (RepoPatchV1 prim :> RepoPatchV1 prim) wX wY -> Perhaps ((RepoPatchV1 prim :> RepoPatchV1 prim) wX wY) otherCommuteRecursiveMerger (p_old@(Merger _ _ p1' p2') :> pA') = toPerhaps $ do (pA :> _) <- commuterFLId selfCommuter (mergerUndo p_old :> pA') (pAmid :> p1) <- commute (unsafeCoercePEnd p1' :> pA) (_ :> pAmido) <- commute (pA :> invert p1) guard (pAmido `unsafeCompare` pAmid) (p2 :> _) <- commute (invert pAmid :> p2') (p2o' :> _) <- commute (pAmid :> p2) guard (p2o' `unsafeCompare` p2') let p = if p1 `unsafeCompare` p1' && p2 `unsafeCompare` p2' then unsafeCoerceP p_old else unsafeMerger "0.0" p1 p2 undo = mergerUndo p guard (not $ pA `unsafeCompare` p1) -- special case here... (_ :> pAo') <- commuterIdFL selfCommuter (pA :> undo) guard (pAo' `unsafeCompare` pA') return (pA :> p) otherCommuteRecursiveMerger _ = Unknown type CommuteFunction prim = forall wX wY . (RepoPatchV1 prim :> RepoPatchV1 prim) wX wY -> Perhaps ((RepoPatchV1 prim :> RepoPatchV1 prim) wX wY) type MaybeCommute prim = forall wX wY . (RepoPatchV1 prim :> RepoPatchV1 prim) wX wY -> Maybe ((RepoPatchV1 prim :> RepoPatchV1 prim) wX wY) commuteFLId :: MaybeCommute prim -> (RepoPatchV1 prim :> FL (RepoPatchV1 prim)) wX wY -> Maybe ((FL (RepoPatchV1 prim) :> RepoPatchV1 prim) wX wY) commuteFLId _ (p :> NilFL) = return (NilFL :> p) commuteFLId commuter (p :> (q :>: qs)) = do q' :> p' <- commuter (p :> q) qs' :> p'' <- commuteFLId commuter (p' :> qs) return ((q' :>: qs') :> p'') {- A note about mergers and type witnesses --------------------------------------- The merger code predates the introduction of type witnesses, and because of its complexity has proved the hardest part of the codebase to retrofit. Attempting to do this has exposed various places where the code behaves oddly (e.g. 'putBefore' below); these are likely to be bugs but fixing them would be potentially disruptive and dangerous as it might change the existing merge behaviour and thus break existing repositories. As a result the addition of witnesses to this code has required the liberal use of unsafe operators. In effect, witnesses bring no safety in this area; the sole purpose of adding them here was to allow this code to run as part of a codebase that uses witnesses everywhere else. A key problem point is the type of the 'Merger' and 'Regrem' constructors of Patch, where the witnesses seem odd. It is likely that some or many of the unsafe operations could be removed by finding a better type for these constructors. -} -- |actualMerge attempts to perform a merge; if successful, it returns the -- "right" branch of the merge -- -- TODO: why does this code throw away the other branch, only for merge to -- rebuild it? actualMerge :: PrimPatch prim => (RepoPatchV1 prim :\/: RepoPatchV1 prim) wX wY -> Sealed (RepoPatchV1 prim wY) actualMerge (p1 :\/: p2) = case naturalMerge (p1:\/:p2) of Just (_ :/\: p1') -> Sealed p1' Nothing -> merger "0.0" p2 p1 -- Recreates a patch history in reverse. unwind :: RepoPatchV1 prim wX wY -> Sealed (RL (RepoPatchV1 prim) wX) unwind (Merger _ unwindings _ _) = Sealed unwindings unwind p = Sealed (NilRL :<: p) -- Recreates a patch history in reverse. The patch being unwound is always at -- the start of the list of patches. trueUnwind :: PrimPatch prim => RepoPatchV1 prim wX wY -> Sealed (RL (RepoPatchV1 prim) wX) trueUnwind p@(Merger _ _ p1 p2) = case (unwind p1, unwind p2) of (Sealed (p1s:<:_),Sealed (p2s:<:_)) -> Sealed (unsafeUnsealFlipped (reconcileUnwindings p p1s (unsafeCoercePEnd p2s)) :<: unsafeCoerceP p1 :<: p) _ -> impossible trueUnwind _ = impossible reconcileUnwindings :: PrimPatch prim => RepoPatchV1 prim wA wB -> RL (RepoPatchV1 prim) wX wZ -> RL (RepoPatchV1 prim) wY wZ -> FlippedSeal (RL (RepoPatchV1 prim)) wZ reconcileUnwindings _ NilRL p2s = FlippedSeal p2s reconcileUnwindings _ p1s NilRL = FlippedSeal p1s reconcileUnwindings p (p1s:<:p1) p2s@(tp2s:<:p2) = case [(p1s', p2s')| p1s'@(_:<:hp1s') <- headPermutationsRL (p1s:<:p1), p2s'@(_:<:hp2s') <- headPermutationsRL p2s, hp1s' `unsafeCompare` hp2s'] of ((p1s':<:p1', p2s':<:_):_) -> mapFlipped (:<:p1') $ reconcileUnwindings p p1s' (unsafeCoercePEnd p2s') [] -> case reverseFL `fmap` putBefore p1 (reverseRL p2s) of Just p2s' -> mapFlipped (:<:p1) $ reconcileUnwindings p p1s p2s' Nothing -> case fmap reverseFL $ putBefore p2 $ reverseRL (p1s:<:p1) of Just p1s' -> mapFlipped (:<:p2) $ reconcileUnwindings p p1s' tp2s Nothing -> errorDoc $ text "in function reconcileUnwindings" $$ text "Original patch:" $$ showPatch_ p _ -> bug "in reconcileUnwindings" -- This code seems wrong, shouldn't the commute be invert p1 :> p2 ? And why isn't p1' re-inverted? -- it seems to have been this way forever: -- Fri May 23 10:27:04 BST 2003 droundy@abridgegame.org -- * fix bug in unwind and add docs on unwind algorithm. putBefore :: PrimPatch prim => RepoPatchV1 prim wY wZ -> FL (RepoPatchV1 prim) wX wZ -> Maybe (FL (RepoPatchV1 prim) wY wW) putBefore p1 (p2:>:p2s) = do p1' :> p2' <- commute (unsafeCoerceP p2 :> invert p1) _ <- commute (p2' :> p1) (unsafeCoerceP p2' :>:) `fmap` putBefore p1' (unsafeCoerceP p2s) putBefore _ NilFL = Just (unsafeCoerceP NilFL) instance PrimPatch prim => CommuteNoConflicts (RepoPatchV1 prim) where commuteNoConflicts (x :> y) = do y' :> x' <- commuteNoMerger (x :> y) return (y' :> x') instance PrimPatch prim => Conflict (RepoPatchV1 prim) where resolveConflicts patch = rcs NilFL (NilRL :<: patch) where rcs :: FL (RepoPatchV1 prim) wY wW -> RL (RepoPatchV1 prim) wX wY -> [[Sealed (FL prim wW)]] rcs _ NilRL = [] rcs passedby (ps:<:p@(Merger{})) = case commuteFLId commuteNoMerger (p :> passedby) of Just (_ :> p'@(Merger _ _ p1 p2)) -> map Sealed (nubBy unsafeCompare $ effect (unsafeCoercePStart $ unsafeUnseal (glump09 p1 p2)) : map (unsafeCoercePStart . unsafeUnseal) (unravel p')) : rcs (p :>: passedby) ps Nothing -> rcs (p :>: passedby) ps _ -> impossible rcs passedby (ps:<:p) = seq passedby $ rcs (p :>: passedby) ps conflictedEffect x = case listConflictedFiles x of [] -> mapFL (IsC Okay) $ effect x _ -> mapFL (IsC Conflicted) $ effect x -- This type seems wrong - the most natural type for the result would seem to be -- [Sealed (FL prim wX)], given the type of unwind. -- However downstream code in darcs convert assumes the wY type, and I was unable -- to figure out whether this could/should reasonably be changed -- Ganesh 13/4/10 publicUnravel :: PrimPatch prim => RepoPatchV1 prim wX wY -> [Sealed (FL prim wY)] publicUnravel = map (mapSeal unsafeCoercePStart) . unravel unravel :: PrimPatch prim => RepoPatchV1 prim wX wY -> [Sealed (FL prim wX)] unravel p = nub $ map (mapSeal (sortCoalesceFL . concatFL . mapFL_FL effect)) $ getSupers $ map (mapSeal reverseRL) $ unseal (newUr p) $ unwind p getSupers :: PrimPatch prim => [Sealed (FL (RepoPatchV1 prim) wX)] -> [Sealed (FL (RepoPatchV1 prim) wX)] getSupers (x:xs) = case filter (not.(x `isSuperpatchOf`)) xs of xs' -> if any (`isSuperpatchOf` x) xs' then getSupers xs' else x : getSupers xs' getSupers [] = [] isSuperpatchOf :: PrimPatch prim => Sealed (FL (RepoPatchV1 prim) wX) -> Sealed (FL (RepoPatchV1 prim) wX) -> Bool Sealed x `isSuperpatchOf` Sealed y | lengthFL y > lengthFL x = False -- should be just an optimisation Sealed x `isSuperpatchOf` Sealed y = x `iso` y where iso :: PrimPatch prim => FL (RepoPatchV1 prim) wX wY -> FL (RepoPatchV1 prim) wX wZ -> Bool _ `iso` NilFL = True NilFL `iso` _ = False a `iso` (b:>:bs) = head $ ([as `iso` bs | (ah :>: as) <- simpleHeadPermutationsFL a, IsEq <- [ah =\/= b]] :: [Bool]) ++ [False] -- | merger takes two patches, (which have been determined to conflict) and -- constructs a Merger patch to represent the conflict. @p1@ is considered to -- be conflicting with @p2@ (@p1@ is the "first" patch in the repo ordering), -- the resulting Merger is therefore a representation of @p2@. merger :: PrimPatch prim => String -> RepoPatchV1 prim wX wY -> RepoPatchV1 prim wX wZ -> Sealed (RepoPatchV1 prim wY) merger "0.0" p1 p2 = Sealed $ Merger undoit unwindings p1 p2 where fake_p = Merger NilFL NilRL p1 p2 unwindings = unsafeUnseal (trueUnwind fake_p) p = Merger NilFL unwindings p1 p2 undoit = case (isMerger p1, isMerger p2) of (True ,True ) -> case unwind p of Sealed (t:<:_) -> unsafeCoerceP $ invertRL t _ -> impossible (False,False) -> unsafeCoerceP $ invert p1 :>: NilFL (True ,False) -> unsafeCoerceP NilFL (False,True ) -> unsafeCoerceP $ invert p1 :>: mergerUndo p2 merger g _ _ = error $ "Cannot handle mergers other than version 0.0\n"++g ++ "\nPlease use darcs optimize --modernize with an older darcs." glump09 :: PrimPatch prim => RepoPatchV1 prim wX wY -> RepoPatchV1 prim wX wZ -> Sealed (FL (RepoPatchV1 prim) wY) glump09 p1 p2 = mapSeal (mapFL_FL fromPrim) $ mangleUnravelled $ unseal unravel $ merger "0.0" p1 p2 instance PrimPatch prim => Effect (RepoPatchV1 prim) where effect p@(Merger{}) = sortCoalesceFL $ effect $ mergerUndo p effect p@(Regrem{}) = invert $ effect $ invert p effect (PP p) = p :>: NilFL instance IsHunk prim => IsHunk (RepoPatchV1 prim) where isHunk p = do PP p' <- return p isHunk p' newUr :: PrimPatch prim => RepoPatchV1 prim wA wB -> RL (RepoPatchV1 prim) wX wY -> [Sealed (RL (RepoPatchV1 prim) wX)] newUr p (ps :<: Merger _ _ p1 p2) = case filter (\(_:<:pp) -> pp `unsafeCompare` p1) $ headPermutationsRL ps of ((ps':<:_):_) -> newUr p (ps':<:unsafeCoercePStart p1) ++ newUr p (ps':<:unsafeCoercePStart p2) _ -> errorDoc $ text "in function newUr" $$ text "Original patch:" $$ showPatch_ p $$ text "Unwound:" $$ vcat (unseal (mapRL showPatch_) $ unwind p) newUr op ps = case filter (\(_:<:p) -> isMerger p) $ headPermutationsRL ps of [] -> [Sealed ps] (ps':_) -> newUr op ps' instance Invert prim => Invert (RepoPatchV1 prim) where invert (Merger undo unwindings p1 p2) = Regrem undo unwindings p1 p2 invert (Regrem undo unwindings p1 p2) = Merger undo unwindings p1 p2 invert (PP p) = PP (invert p) instance Eq2 prim => Eq2 (RepoPatchV1 prim) where unsafeCompare = eqPatches instance Eq2 prim => Eq (RepoPatchV1 prim wX wY) where (==) = unsafeCompare eqPatches :: Eq2 prim => RepoPatchV1 prim wX wY -> RepoPatchV1 prim wW wZ -> Bool eqPatches (PP p1) (PP p2) = unsafeCompare p1 p2 eqPatches (Merger _ _ p1a p1b) (Merger _ _ p2a p2b) = eqPatches p1a p2a && eqPatches p1b p2b eqPatches (Regrem _ _ p1a p1b) (Regrem _ _ p2a p2b) = eqPatches p1a p2a && eqPatches p1b p2b eqPatches _ _ = False darcs-2.14.5/src/Darcs/Patch/V1/Core.hs0000644000000000000000000000651507346545000015473 0ustar0000000000000000{-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving #-} module Darcs.Patch.V1.Core ( RepoPatchV1(..), isMerger, mergerUndo ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Format ( PatchListFormat(..) , ListFormat(ListFormatV1) ) import Darcs.Patch.Debug ( PatchDebug(..) ) import Darcs.Patch.Prim ( FromPrim(..), PrimPatchBase(..), PrimPatch ) import Darcs.Patch.Repair ( Check ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL ) import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..) , ShowDict(ShowDictClass) , appPrec, showsPrec2 ) -- This haddock could be put on the individual bits of Merger instead -- once haddock supports doc comments on GADT constructors {- | The format of a merger is @Merger undos unwindings conflicting original@. @undos@ = the effect of the merger @unwindings@ = TODO: eh? @conflicting@ = the patch we conflict with @original@ = the patch we really are -} data RepoPatchV1 prim wX wY where PP :: prim wX wY -> RepoPatchV1 prim wX wY Merger :: FL (RepoPatchV1 prim) wX wY -> RL (RepoPatchV1 prim) wX wB -> RepoPatchV1 prim wC wB -> RepoPatchV1 prim wC wD -> RepoPatchV1 prim wX wY Regrem :: FL (RepoPatchV1 prim) wX wY -> RL (RepoPatchV1 prim) wX wB -> RepoPatchV1 prim wC wB -> RepoPatchV1 prim wC wA -> RepoPatchV1 prim wY wX instance Show2 prim => Show (RepoPatchV1 prim wX wY) where showsPrec d (PP p) = showParen (d > appPrec) $ showString "PP " . showsPrec2 (appPrec + 1) p showsPrec d (Merger undos unwindings conflicting original) = showParen (d > appPrec) $ showString "Merger " . showsPrec2 (appPrec + 1) undos . showString " " . showsPrec2 (appPrec + 1) unwindings . showString " " . showsPrec2 (appPrec + 1) conflicting . showString " " . showsPrec2 (appPrec + 1) original showsPrec d (Regrem undos unwindings conflicting original) = showParen (d > appPrec) $ showString "Regrem " . showsPrec2 (appPrec + 1) undos . showString " " . showsPrec2 (appPrec + 1) unwindings . showString " " . showsPrec2 (appPrec + 1) conflicting . showString " " . showsPrec2 (appPrec + 1) original instance Show2 prim => Show1 (RepoPatchV1 prim wX) where showDict1 = ShowDictClass instance Show2 prim => Show2 (RepoPatchV1 prim) where showDict2 = ShowDictClass instance PrimPatch prim => PrimPatchBase (RepoPatchV1 prim) where type PrimOf (RepoPatchV1 prim) = prim instance FromPrim (RepoPatchV1 prim) where fromPrim = PP isMerger :: RepoPatchV1 prim wA wB -> Bool isMerger (Merger{}) = True isMerger (Regrem{}) = True isMerger _ = False mergerUndo :: RepoPatchV1 prim wX wY -> FL (RepoPatchV1 prim) wX wY mergerUndo (Merger undo _ _ _) = undo mergerUndo _ = impossible instance PatchListFormat (RepoPatchV1 prim) where -- In principle we could use ListFormatDefault when prim /= V1 Prim patches, -- as those are the only case where we need to support a legacy on-disk -- format. In practice we don't expect Patch to be used with any other argument -- anyway, so it doesn't matter. patchListFormat = ListFormatV1 instance Check (RepoPatchV1 prim) -- no checks instance PatchDebug prim => PatchDebug (RepoPatchV1 prim) darcs-2.14.5/src/Darcs/Patch/V1/Prim.hs0000644000000000000000000000601407346545000015504 0ustar0000000000000000-- it is stupid that we need UndecidableInstances just to call another -- type function (see instance Apply below which requires this) {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Darcs.Patch.V1.Prim ( Prim(..) ) where import Prelude () import Darcs.Prelude import Data.Coerce ( coerce ) import Darcs.Patch.Annotate ( Annotate(..) ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute ) import Darcs.Patch.FileHunk ( IsHunk(..) ) import Darcs.Patch.Format ( PatchListFormat(..) , ListFormat(ListFormatV1) , FileNameFormat(OldFormat,UserFormat) ) import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Patch.Invert ( Invert ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.Repair ( RepairToFL(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..) , ShowPatchFor(..) , ShowPatch(..) , ShowContextPatch(..) ) import Darcs.Patch.Summary ( plainSummaryPrim, plainSummaryPrims ) import Darcs.Patch.Witnesses.Eq ( Eq2 ) import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..) , ShowDict(ShowDictClass) , appPrec, showsPrec2 ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..) ) import Darcs.Patch.Prim.Class ( PrimConstruct(..), PrimCanonize(..) , PrimClassify(..), PrimDetails(..) , PrimShow(..), PrimRead(..) , PrimApply(..) , PrimPatch, PrimPatchBase(..) , FromPrim(..), ToFromPrim(..) , PrimPatchCommon ) import qualified Darcs.Patch.Prim.V1 as Base ( Prim ) newtype Prim x y = Prim { unPrim :: Base.Prim x y } deriving ( Annotate , Commute , Invert , IsHunk , Eq2 , PatchInspect , PrimApply , PrimCanonize , PrimClassify , PrimConstruct , PrimDetails , PrimPatchCommon ) instance PrimPatch Prim instance Show (Prim wX wY) where showsPrec d (Prim p) = showParen (d > appPrec) $ showString "Prim " . showsPrec2 (appPrec + 1) p instance Show1 (Prim wX) where showDict1 = ShowDictClass instance Show2 Prim where showDict2 = ShowDictClass instance PrimPatchBase Prim where type PrimOf Prim = Prim instance FromPrim Prim where fromPrim = id instance ToFromPrim Prim where toPrim = Just instance ReadPatch Prim where readPatch' = do Sealed p <- readPrim OldFormat return (Sealed (Prim p)) fileNameFormat :: ShowPatchFor -> FileNameFormat fileNameFormat ForDisplay = UserFormat fileNameFormat ForStorage = OldFormat instance ShowPatchBasic Prim where showPatch fmt = showPrim (fileNameFormat fmt) . unPrim instance ShowContextPatch Prim where showContextPatch f = showPrimCtx (fileNameFormat f) . unPrim instance ShowPatch Prim where summary = plainSummaryPrim . unPrim summaryFL = plainSummaryPrims False thing _ = "change" instance PatchListFormat Prim where patchListFormat = ListFormatV1 instance Apply Prim where type ApplyState Prim = ApplyState Base.Prim apply = apply . unPrim instance RepairToFL Prim where applyAndTryToFixFL = fmap coerce . applyAndTryToFixFL . unPrim darcs-2.14.5/src/Darcs/Patch/V1/Read.hs0000644000000000000000000000302007346545000015442 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.V1.Read () where import Prelude () import Darcs.Prelude import Darcs.Patch.Invert ( invert ) import Darcs.Patch.Prim ( PrimPatch ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.ReadMonads ( ParserM, choice, string, lexChar, myLex', skipSpace ) import Darcs.Patch.V1.Core ( RepoPatchV1(..) ) import Darcs.Patch.V1.Commute ( merger ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), seal, mapSeal ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Control.Monad ( liftM ) import qualified Data.ByteString.Char8 as BC ( unpack, pack ) import qualified Data.ByteString as B (ByteString ) instance PrimPatch prim => ReadPatch (RepoPatchV1 prim) where readPatch' = choice [ liftM seal $ skipSpace >> readMerger True , liftM seal $ skipSpace >> readMerger False , liftM (mapSeal PP) readPatch' ] readMerger :: (ParserM m, PrimPatch prim) => Bool -> m (RepoPatchV1 prim wX wY) readMerger b = do string s g <- myLex' lexChar '(' Sealed p1 <- readPatch' Sealed p2 <- readPatch' lexChar ')' Sealed m <- return $ merger (BC.unpack g) p1 p2 return $ if b then unsafeCoerceP m else unsafeCoerceP (invert m) where s | b = merger' | otherwise = regrem merger' :: B.ByteString merger' = BC.pack "merger" regrem :: B.ByteString regrem = BC.pack "regrem" darcs-2.14.5/src/Darcs/Patch/V1/Show.hs0000644000000000000000000000201207346545000015507 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.V1.Show ( showPatch_ ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Show ( ShowPatchBasic(..), ShowPatchFor(..) ) import Darcs.Patch.V1.Core ( RepoPatchV1(..) ) import Darcs.Util.Printer ( Doc, text, blueText, ($$), (<+>) ) showPatch_ :: ShowPatchBasic prim => prim wX wY -> Doc showPatch_ = showPatch ForDisplay showMerger :: ShowPatchBasic prim => ShowPatchFor -> String -> RepoPatchV1 prim wA wB -> RepoPatchV1 prim wD wE -> Doc showMerger f merger_name p1 p2 = blueText merger_name <+> text "0.0" <+> blueText "(" $$ showPatch f p1 $$ showPatch f p2 $$ blueText ")" instance ShowPatchBasic prim => ShowPatchBasic (RepoPatchV1 prim) where showPatch f (PP p) = showPatch f p showPatch f (Merger _ _ p1 p2) = showMerger f "merger" p1 p2 showPatch f (Regrem _ _ p1 p2) = showMerger f "regrem" p1 p2 darcs-2.14.5/src/Darcs/Patch/V1/Viewing.hs0000644000000000000000000000122307346545000016202 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.V1.Viewing () where import Darcs.Patch.Prim ( PrimPatch ) import Darcs.Patch.Show ( ShowPatch(..), ShowContextPatch(..), showPatch ) import Darcs.Patch.Summary ( plainSummary ) import Darcs.Patch.V1.Apply () import Darcs.Patch.V1.Core ( RepoPatchV1(..) ) import Darcs.Patch.V1.Show () instance PrimPatch prim => ShowContextPatch (RepoPatchV1 prim) where showContextPatch f (PP p) = showContextPatch f p showContextPatch f p = return $ showPatch f p instance PrimPatch prim => ShowPatch (RepoPatchV1 prim) where summary = plainSummary summaryFL = plainSummary thing _ = "change" darcs-2.14.5/src/Darcs/Patch/V2.hs0000644000000000000000000000065207346545000014600 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Darcs.Patch.V2 ( RepoPatchV2 ) where import Darcs.Patch.Annotate ( Annotate ) import Darcs.Patch.Matchable ( Matchable ) import Darcs.Patch.Prim ( PrimPatch ) import Darcs.Patch.RepoPatch ( RepoPatch ) import Darcs.Patch.V2.RepoPatch ( RepoPatchV2 ) instance PrimPatch prim => Matchable (RepoPatchV2 prim) instance (PrimPatch prim, Annotate prim) => RepoPatch (RepoPatchV2 prim) darcs-2.14.5/src/Darcs/Patch/V2/0000755000000000000000000000000007346545000014241 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/V2/Non.hs0000644000000000000000000002545007346545000015335 0ustar0000000000000000-- Copyright (C) 2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# OPTIONS_GHC -fno-warn-orphans -fno-warn-name-shadowing #-} {-# LANGUAGE FlexibleContexts, UndecidableInstances #-} module Darcs.Patch.V2.Non ( Non(..) , Nonable(..) , unNon , showNon , showNons , readNon , readNons , commutePrimsOrAddToCtx , commuteOrAddToCtx , commuteOrRemFromCtx , commuteOrAddToCtxRL , commuteOrRemFromCtxFL , remNons , (*>) , (>*) , (*>>) , (>>*) ) where import Prelude () import Darcs.Prelude hiding ( (*>) ) import Data.List ( delete ) import Control.Monad ( liftM, mzero ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( commuteFL ) import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.Format ( PatchListFormat ) import Darcs.Patch.Invert ( Invert, invertFL, invertRL ) import Darcs.Patch.Prim ( FromPrim(..), ToFromPrim(..) , PrimOf, PrimPatchBase , sortCoalesceFL ) import Darcs.Patch.Commute ( Commute(..) ) import Darcs.Patch.Invert ( Invert(invert) ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.Show ( showPatch ) import Darcs.Patch.ReadMonads ( ParserM, lexChar ) import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), (+>+), mapRL_RL , (:>)(..), reverseFL, reverseRL ) import Darcs.Patch.Witnesses.Show ( ShowDict(..), Show1(..), Show2(..), appPrec , showsPrec2 ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed) ) import Darcs.Patch.Read ( peekfor ) import Darcs.Patch.Show ( ShowPatchBasic, ShowPatchFor ) import Darcs.Patch.Viewing () import Darcs.Patch.Permutations ( removeFL, commuteWhatWeCanFL ) import Darcs.Util.Printer ( Doc, empty, vcat, hiddenPrefix, blueText, ($$) ) import qualified Data.ByteString.Char8 as BC ( pack, singleton ) -- |A 'Non' stores a context with a 'Prim' patch. It is a patch whose effect -- isn't visible - a Non-affecting patch. data Non p wX where Non :: FL p wX wY -> PrimOf p wY wZ -> Non p wX -- |unNon converts a Non into a FL of its context followed by the primitive -- patch. unNon :: FromPrim p => Non p wX -> Sealed (FL p wX) unNon (Non c x) = Sealed (c +>+ fromPrim x :>: NilFL) instance (Show2 p, Show2 (PrimOf p)) => Show (Non p wX) where showsPrec d (Non cs p) = showParen (d > appPrec) $ showString "Non " . showsPrec2 (appPrec + 1) cs . showString " " . showsPrec2 (appPrec + 1) p instance (Show2 p, Show2 (PrimOf p)) => Show1 (Non p) where showDict1 = ShowDictClass -- |showNons creates a Doc representing a list of Nons. showNons :: (ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) => ShowPatchFor -> [Non p wX] -> Doc showNons _ [] = empty showNons f xs = blueText "{{" $$ vcat (map (showNon f) xs) $$ blueText "}}" -- |showNon creates a Doc representing a Non. showNon :: (ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) => ShowPatchFor -> Non p wX -> Doc showNon f (Non c p) = hiddenPrefix "|" (showPatch f c) $$ hiddenPrefix "|" (blueText ":") $$ showPatch f p -- |readNons is a parser that attempts to read a list of Nons. readNons :: (ReadPatch p, PatchListFormat p, PrimPatchBase p, ParserM m) => m [Non p wX] readNons = peekfor (BC.pack "{{") rns (return []) where rns = peekfor (BC.pack "}}") (return []) $ do Sealed ps <- readPatch' lexChar ':' Sealed p <- readPatch' (Non ps p :) `liftM` rns -- |readNon is a parser that attempts to read a single Non. readNon :: (ReadPatch p, PatchListFormat p, PrimPatchBase p, ParserM m) => m (Non p wX) readNon = do Sealed ps <- readPatch' let doReadPrim = do Sealed p <- readPatch' return $ Non ps p peekfor (BC.singleton ':') doReadPrim mzero -- |Nons are equal if their context patches are equal, and they have an equal -- prim patch. instance (Commute p, Eq2 p, Eq2 (PrimOf p)) => Eq (Non p wX) where Non (cx :: FL p wX wY1) (x :: PrimOf p wY1 wZ1) == Non (cy :: FL p wX wY2) (y :: PrimOf p wY2 wZ2) = case cx =\/= cy of IsEq -> case x =\/= y :: EqCheck wZ1 wZ2 of IsEq -> True NotEq -> False NotEq -> False -- |Nonable represents the class of patches that can be turned into a Non. class Nonable p where non :: p wX wY -> Non p wX -- |'commuteOrAddToCtx' @x cy@ tries to commute @x@ past @cy@ and always -- returns some variant @cy'@. If commutation suceeds, the variant is just -- straightforwardly the commuted version. If commutation fails, the variant -- consists of @x@ prepended to the context of @cy@. commuteOrAddToCtx :: (Commute p, ToFromPrim p) => p wX wY -> Non p wY -> Non p wX commuteOrAddToCtx p n | Just n' <- p >* n = n' commuteOrAddToCtx p (Non c x) = Non (p:>:c) x -- | 'commuteOrAddToCtxRL' @xs cy@ commutes as many patches of @xs@ past @cy@ -- as possible, adding any that don't commute to the context of cy. Suppose we -- have -- -- > x1 x2 x3 [c1 c2 y] -- -- and that in our example @x1@ fails to commute past @c1@, this function -- would commute down to -- -- > x1 [c1'' c2'' y''] x2' x3' -- -- and return @[x1 c1'' c2'' y'']@ commuteOrAddToCtxRL :: (Apply p, Commute p, Invert p, ToFromPrim p) => RL p wX wY -> Non p wY -> Non p wX commuteOrAddToCtxRL NilRL n = n commuteOrAddToCtxRL (ps:<:p) n = commuteOrAddToCtxRL ps $ commuteOrAddToCtx p n -- |abstract over 'FL'/'RL' class WL l where toRL :: l p wX wY -> RL p wX wY invertWL :: Invert p => l p wX wY -> l p wY wX instance WL FL where toRL = reverseFL invertWL = reverseRL . invertFL instance WL RL where toRL = id invertWL = reverseFL . invertRL -- |commutePrimsOrAddToCtx takes a WL of prims and attempts to commute them -- past a Non. commutePrimsOrAddToCtx :: (WL l, Apply p, Commute p, Invert p, ToFromPrim p) => l (PrimOf p) wX wY -> Non p wY -> Non p wX commutePrimsOrAddToCtx q = commuteOrAddToCtxRL (mapRL_RL fromPrim $ toRL q) -- TODO: Figure out what remNons is for; it's is only used in one place - when -- commuting two Conflictors: -- -- > commute (Conflictor a1 n1 p1 :> Conflictor a2 n2 p2) -- > ... -- > a1' = map (commutePrimsOrAddToCtx n2) a1 -- > p2ooo = remNons a1' p2 -- > n2n1 = n2 +>+ n1 -- > n1' :> n2' <- return $ filterConflictsFL p2ooo n2n1 -- -- which appears to be munging the not-yet-undone FLs in the Conflictors. a1' -- will be the list of Nons with n2 commuted in/past them. So we then want to -- modify p2, so that it doesn't have any of a1' in its context. -- remNons really only works right if the relevant nons are conflicting... remNons :: (Nonable p, Effect p, Apply p, Commute p, Invert p, Eq2 p, ToFromPrim p, PrimPatchBase p) => [Non p wX] -> Non p wX -> Non p wX remNons ns n@(Non c x) = case remNonHelper ns c of NilFL :> c' -> Non c' x _ -> n where remNonHelper :: (Nonable p, Effect p, Apply p, Commute p, Invert p, Eq2 p, ToFromPrim p, PrimPatchBase p) => [Non p wX] -> FL p wX wY -> (FL (PrimOf p) :> FL p) wX wY remNonHelper [] x = NilFL :> x remNonHelper _ NilFL = NilFL :> NilFL remNonHelper ns (c:>:cs) | non c `elem` ns = let nsWithoutC = delete (non c) ns in let commuteOrAddInvC = commuteOrAddToCtx $ invert c in case remNonHelper (map commuteOrAddInvC nsWithoutC) cs of a :> z -> sortCoalesceFL (effect c +>+ a) :> z | otherwise = case commuteWhatWeCanFL (c :> cs) of b :> c' :> d -> case remNonHelper ns b of a :> b' -> a :> (b' +>+ c' :>: d) -- |commuteOrRemFromCtx attempts to remove a given patch from a Non. If the -- patch was not in the Non, then the commute will succeed and the modified Non -- will be returned. If the commute fails then the patch is either in the Non -- context, or the Non patch itself; we attempt to remove the patch from the -- context and then return the non with the updated context. -- -- TODO: understand if there is any case where p is equal to the prim patch of -- the Non, in which case, we return the original Non, is that right? commuteOrRemFromCtx :: (Commute p, Invert p, Eq2 p, ToFromPrim p) => p wX wY -> Non p wX -> Maybe (Non p wY) commuteOrRemFromCtx p n | n'@(Just _) <- n *> p = n' commuteOrRemFromCtx p (Non pc x) = removeFL p pc >>= \c -> return (Non c x) -- |commuteOrRemFromCtxFL attempts to remove a FL of patches from a Non, -- returning Nothing if any of the individual removes fail. commuteOrRemFromCtxFL :: (Apply p, Commute p, Invert p, Eq2 p, ToFromPrim p) => FL p wX wY -> Non p wX -> Maybe (Non p wY) commuteOrRemFromCtxFL NilFL n = Just n commuteOrRemFromCtxFL (p:>:ps) n = do n' <- commuteOrRemFromCtx p n commuteOrRemFromCtxFL ps n' -- |(*>) attemts to modify a Non by commuting it past a given patch. (*>) :: (Commute p, Invert p, ToFromPrim p) => Non p wX -> p wX wY -> Maybe (Non p wY) n *> p = invert p >* n -- |(>*) attempts to modify a Non, by commuting a given patch past it. (>*) :: (Commute p, ToFromPrim p) => p wX wY -> Non p wY -> Maybe (Non p wX) y >* (Non c x) = do c' :> y' <- commuteFL (y :> c) px' :> _ <- commute (y' :> fromPrim x) x' <- toPrim px' return (Non c' x') -- |(*>>) attempts to modify a Non by commuting it past a given WL of patches. (*>>) :: (WL l, Apply p, Commute p, Invert p, ToFromPrim p, PrimPatchBase p) => Non p wX -> l (PrimOf p) wX wY -> Maybe (Non p wY) n *>> p = invertWL p >>* n -- |(>>*) attempts to modify a Non by commuting a given WL of patches past it. (>>*) :: (WL l, Apply p, Commute p, Invert p, ToFromPrim p) => l (PrimOf p) wX wY -> Non p wY -> Maybe (Non p wX) ps >>* n = commuteRLPastNon (toRL ps) n where commuteRLPastNon :: (Apply p, Commute p, Invert p, ToFromPrim p) => RL (PrimOf p) wX wY -> Non p wY -> Maybe (Non p wX) commuteRLPastNon NilRL n = Just n commuteRLPastNon (xs:<:x) n = fromPrim x >* n >>= commuteRLPastNon xs darcs-2.14.5/src/Darcs/Patch/V2/Prim.hs0000644000000000000000000000654407346545000015515 0ustar0000000000000000-- it is stupid that we need UndecidableInstances just to call another -- type function (see instance Apply below which requires this) {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Darcs.Patch.V2.Prim ( Prim(..) ) where import Prelude () import Darcs.Prelude import Data.Coerce (coerce ) import Darcs.Patch.Annotate ( Annotate ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Commute ( Commute ) import Darcs.Patch.FileHunk ( IsHunk ) import Darcs.Patch.Format ( PatchListFormat(..) , ListFormat(ListFormatV2) , FileNameFormat(NewFormat,UserFormat) ) import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Patch.Invert ( Invert ) import Darcs.Patch.Read ( ReadPatch(..) ) import Darcs.Patch.Repair ( RepairToFL(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..) , ShowPatchFor(..) , ShowPatch(..) , ShowContextPatch(..) ) import Darcs.Patch.Summary ( plainSummaryPrim, plainSummaryPrims ) import Darcs.Patch.Witnesses.Eq ( Eq2 ) import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..) , ShowDict(ShowDictClass) , appPrec, showsPrec2 ) import Darcs.Patch.Witnesses.Sealed ( mapSeal ) import Darcs.Patch.Prim.Class ( PrimConstruct(..), PrimCanonize(..) , PrimClassify(..), PrimDetails(..) , PrimShow(..), PrimRead(..) , PrimApply(..) , PrimPatch, PrimPatchBase(..) , FromPrim(..), ToFromPrim(..) , PrimPatchCommon ) import qualified Darcs.Patch.Prim.V1 as Base ( Prim ) newtype Prim x y = Prim { unPrim :: Base.Prim x y } deriving ( Annotate , Commute , Invert , IsHunk , Eq2 , PatchInspect , PrimApply , PrimCanonize , PrimClassify , PrimConstruct , PrimDetails , PrimPatchCommon ) instance PrimPatch Prim instance Show (Prim wX wY) where showsPrec d (Prim p) = showParen (d > appPrec) $ showString "Prim " . showsPrec2 (appPrec + 1) p instance Show1 (Prim wX) where showDict1 = ShowDictClass instance Show2 Prim where showDict2 = ShowDictClass instance PrimPatchBase Prim where type PrimOf Prim = Prim instance FromPrim Prim where fromPrim = id instance ToFromPrim Prim where toPrim = Just instance ReadPatch Prim where readPatch' = fmap (mapSeal Prim) (readPrim NewFormat) fileNameFormat :: ShowPatchFor -> FileNameFormat fileNameFormat ForDisplay = UserFormat fileNameFormat ForStorage = NewFormat instance ShowPatchBasic Prim where showPatch f = showPrim (fileNameFormat f) . unPrim instance ShowContextPatch Prim where showContextPatch f = showPrimCtx (fileNameFormat f) . unPrim instance ShowPatch Prim where summary = plainSummaryPrim . unPrim summaryFL = plainSummaryPrims False thing _ = "change" -- This instance is here so that FL Prim and RL Prim also get -- ShowPatch instances, see Darcs.Patch.Viewing instance PatchListFormat Prim where -- In principle we could use ListFormatDefault when prim /= V1 Prim patches, -- as those are the only case where we need to support a legacy on-disk -- format. In practice we don't expect RepoPatchV2 to be used with any other -- argument anyway, so it doesn't matter. patchListFormat = ListFormatV2 instance Apply Prim where type ApplyState Prim = ApplyState Base.Prim apply = apply . unPrim instance RepairToFL Prim where applyAndTryToFixFL = fmap coerce . applyAndTryToFixFL . unPrim darcs-2.14.5/src/Darcs/Patch/V2/RepoPatch.hs0000644000000000000000000012235207346545000016467 0ustar0000000000000000-- Copyright (C) 2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# OPTIONS_GHC -fno-warn-orphans -fno-warn-name-shadowing #-} module Darcs.Patch.V2.RepoPatch ( RepoPatchV2(..) , isConsistent , isForward , isDuplicate , mergeUnravelled ) where import Prelude () import Darcs.Prelude hiding ( (*>) ) import Control.Monad ( mplus, liftM ) import qualified Data.ByteString.Char8 as BC ( ByteString, pack ) import Data.Maybe ( fromMaybe ) import Data.List ( partition, nub ) import Data.List.Ordered ( nubSort ) import Darcs.Patch.Annotate ( Annotate(..) ) import Darcs.Patch.Commute ( commuteFL, commuteFLorComplain, commuteRL , commuteRLFL, Commute(..) ) import Darcs.Patch.Conflict ( Conflict(..), CommuteNoConflicts(..) , IsConflictedPrim(..), ConflictState(..) , mangleUnravelled ) import Darcs.Patch.Debug import Darcs.Patch.Effect ( Effect(..) ) import Darcs.Patch.FileHunk ( IsHunk(..) ) import Darcs.Patch.Format ( PatchListFormat(..), ListFormat(ListFormatV2) ) import Darcs.Patch.Invert ( invertFL, invertRL, Invert(..) ) import Darcs.Patch.Merge ( Merge(..), naturalMerge ) import Darcs.Patch.Prim ( FromPrim(..), ToFromPrim(..) , PrimPatchBase(..), PrimPatch ) import Darcs.Patch.Read ( bracketedFL, ReadPatch(..) ) import Darcs.Patch.ReadMonads ( skipSpace, string, choice ) import Darcs.Patch.Repair ( mapMaybeSnd, RepairToFL(..), Check(..) ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.Inspect ( PatchInspect(..) ) import Darcs.Patch.Permutations ( commuteWhatWeCanFL, commuteWhatWeCanRL , genCommuteWhatWeCanRL, removeRL, removeFL , removeSubsequenceFL ) import Darcs.Patch.Show ( ShowPatch(..), ShowPatchBasic(..), ShowContextPatch(..), ShowPatchFor(..) , displayPatch ) import Darcs.Patch.Summary ( plainSummary ) import Darcs.Patch.V2.Non ( Non(..), Nonable(..), unNon, showNons, showNon , readNons, readNon, commutePrimsOrAddToCtx , commuteOrAddToCtx, commuteOrAddToCtxRL , commuteOrRemFromCtx, commuteOrRemFromCtxFL , remNons, (*>), (>*), (*>>), (>>*) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), (:>)(..), (+>+), (+<+) , mapFL, mapFL_FL, reverseFL, (:\/:)(..), (:/\:)(..) , reverseRL, lengthFL, lengthRL, nullFL, initsFL ) import Darcs.Patch.Witnesses.Sealed ( FlippedSeal(..), Sealed(Sealed), mapSeal , unseal ) import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..), ShowDict(..) , showsPrec2, appPrec ) import Darcs.Util.Printer.Color ( errorDoc, assertDoc ) import Darcs.Util.Printer ( Doc, blueText, redText, (<+>), ($$), vcat ) -- |'RepoPatchV2' is used to represents prim patches that are duplicates of, or -- conflict with, another prim patch in the repository. -- -- @Normal prim@: A primitive patch -- -- @Duplicate x@: This patch has no effect since @x@ is already present in the -- repository. -- -- @Etacilpud x: invert (Duplicate x)@ -- -- @Conflictor ix xx x@: -- @ix@ is the set of patches: -- * that conflict with @x@ and also conflict with another patch in the -- repository. -- * that conflict with a patch that conflict with @x@ -- -- @xx@ is the sequence of patches that conflict *only* with @x@ -- -- @x@ is the original, conflicting patch. -- -- @ix@ and @x@ are stored as @Non@ objects, which include any necessary -- context to uniquely define the patch that is referred to. -- -- The intuition is that a Conflictor should have the effect of inverting any -- patches that 'x' conflicts with, that haven't already been undone by another -- Conflictor in the repository. -- Therefore, the effect of a Conflictor is @invert xx@. -- -- @InvConflictor ix xx x@: like @invert (Conflictor ix xx x)@ data RepoPatchV2 prim wX wY where Duplicate :: Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX Etacilpud :: Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX Normal :: prim wX wY -> RepoPatchV2 prim wX wY Conflictor :: [Non (RepoPatchV2 prim) wX] -> FL prim wX wY -> Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wY wX InvConflictor :: [Non (RepoPatchV2 prim) wX] -> FL prim wX wY -> Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wY instance PrimPatch prim => PrimPatchBase (RepoPatchV2 prim) where type PrimOf (RepoPatchV2 prim) = prim -- | 'isDuplicate' @p@ is @True@ if @p@ is either a 'Duplicate' or 'Etacilpud' -- patch. isDuplicate :: RepoPatchV2 prim wS wY -> Bool isDuplicate (Duplicate _) = True isDuplicate (Etacilpud _) = True isDuplicate _ = False -- | 'isForward' @p@ is @True@ if @p@ is either an 'InvConflictor' or -- 'Etacilpud'. isForward :: PrimPatch prim => RepoPatchV2 prim wS wY -> Maybe Doc isForward p = case p of p@(InvConflictor{}) -> justRedP "An inverse conflictor" p p@(Etacilpud _) -> justRedP "An inverse duplicate" p _ -> Nothing where justRedP msg p = Just $ redText msg $$ displayPatch p -- |'mergeUnravelled' is used when converting from Darcs V1 patches (Mergers) -- to Darcs V2 patches (Conflictors). mergeUnravelled :: PrimPatch prim => [Sealed ((FL prim) wX)] -> Maybe (FlippedSeal (RepoPatchV2 prim) wX) mergeUnravelled [] = Nothing mergeUnravelled [_] = Nothing mergeUnravelled ws = case mergeUnravelled_private ws of Nothing -> Nothing Just NilRL -> bug "found no patches in mergeUnravelled" Just (_ :<: z) -> Just $ FlippedSeal z where notNullS :: Sealed ((FL prim) wX) -> Bool notNullS (Sealed NilFL) = False notNullS _ = True mergeUnravelled_private :: PrimPatch prim => [Sealed (FL prim wX)] -> Maybe (RL (RepoPatchV2 prim) wX wX) mergeUnravelled_private xs = let nonNullXs = filter notNullS xs in reverseFL `fmap` mergeConflictingNons (map sealed2non nonNullXs) -- | 'sealed2non' @(Sealed xs)@ converts @xs@ to a 'Non'. -- @xs@ must be non-empty since we split this list at the last patch, -- taking @init xs@ as the context of @last xs@. sealed2non :: Sealed ((FL prim) wX) -> Non (RepoPatchV2 prim) wX sealed2non (Sealed xs) = case reverseFL xs of ys :<: y -> Non (mapFL_FL fromPrim $ reverseRL ys) y NilRL -> bug "NilFL encountered in sealed2non" mergeConflictingNons :: PrimPatch prim => [Non (RepoPatchV2 prim) wX] -> Maybe (FL (RepoPatchV2 prim) wX wX) mergeConflictingNons ns = mcn $ map unNon ns where mcn :: PrimPatch prim => [Sealed (FL (RepoPatchV2 prim) wX)] -> Maybe (FL (RepoPatchV2 prim) wX wX) mcn [] = Just NilFL -- Apparently, the joinEffects call is a safety check "and could be -- removed when we're sure of the code"! mcn [Sealed p] = case joinEffects p of NilFL -> Just p _ -> Nothing mcn (Sealed p1:Sealed p2:zs) = case pullCommon p1 p2 of Common c ps qs -> case merge (ps :\/: qs) of qs' :/\: _ -> mcn (Sealed (c +>+ ps +>+ qs'):zs) joinEffects :: forall p wX wY . (Effect p, Invert (PrimOf p), Commute (PrimOf p), Eq2 (PrimOf p)) => p wX wY -> FL (PrimOf p) wX wY joinEffects = joinInverses . effect where joinInverses :: FL (PrimOf p) wA wB -> FL (PrimOf p) wA wB joinInverses NilFL = NilFL joinInverses (p :>: ps) = let ps' = joinInverses ps in fromMaybe (p :>: ps') $ removeFL (invert p) ps' assertConsistent :: PrimPatch prim => RepoPatchV2 prim wX wY -> RepoPatchV2 prim wX wY assertConsistent x = flip assertDoc x $ do e <- isConsistent x Just (redText "Inconsistent patch:" $$ displayPatch x $$ e) -- | @mergeAfterConflicting@ takes as input a sequence of conflicting patches -- @xxx@ (which therefore have no effect) and a sequence of primitive patches -- @yyy@ that follow said sequence of conflicting patches, and may depend upon -- some of the conflicting patches (as a resolution). -- The output is two sequences of patches the first consisting of a set of -- mutually-conflicting patches, and the second having the same effect as the -- original primitive patch sequence in the input. -- So far as I can tell, the second output is always identical to @mapFL Normal -- yyy@ -- The first output is the set of patches from @xxx@ that are depended upon by -- @yyy@. mergeAfterConflicting :: PrimPatch prim => FL (RepoPatchV2 prim) wX wX -> FL prim wX wY -> Maybe ( FL (RepoPatchV2 prim) wX wX , FL (RepoPatchV2 prim) wX wY) mergeAfterConflicting xxx yyy = mac (reverseFL xxx) yyy NilFL where mac :: PrimPatch prim => RL (RepoPatchV2 prim) wX wY -> FL prim wY wZ -> FL (RepoPatchV2 prim) wZ wA -> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA) mac NilRL xs goneby = case joinEffects goneby of NilFL -> Just (NilFL, mapFL_FL Normal xs) _ -> Nothing mac (ps :<: p) xs goneby = case commuteFLorComplain (p :> mapFL_FL Normal xs) of Left _ -> case genCommuteWhatWeCanRL commuteNoConflicts (ps :> p) of a :> p' :> b -> do (b', xs') <- mac b xs goneby let pa = joinEffects $ a :<: p' NilFL <- return pa return (reverseRL (a :<: p') +>+ b', xs') `mplus` do NilFL <- return goneby NilFL <- return $ joinEffects (ps :<: p) return (reverseRL (ps :<: p), mapFL_FL Normal xs) Right (l :> p'') -> case allNormal l of Just xs'' -> mac ps xs'' (p'' :>: goneby) Nothing -> case genCommuteWhatWeCanRL commuteNoConflicts (ps :> p) of a :> p' :> b -> do (b', xs') <- mac b xs goneby let pa = joinEffects $ a :<: p' NilFL <- return pa return (reverseRL (a :<: p') +>+ b', xs') geteff :: PrimPatch prim => [Non (RepoPatchV2 prim) wX] -> FL prim wX wY -> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY) geteff _ NilFL = ([], NilFL) geteff ix (x :>: xs) | Just ix' <- mapM (commuteOrRemFromCtx (Normal x)) ix = case geteff ix' xs of (ns, xs') -> ( non (Normal x) : map (commuteOrAddToCtx (Normal x)) ns , Normal x :>: xs') geteff ix xx = case mergeConflictingNons ix of Nothing -> errorDoc $ redText "mergeConflictingNons failed in geteff: ix" $$ displayNons ix $$ redText "xx" $$ displayPatch xx Just rix -> case mergeAfterConflicting rix xx of Just (a, x) -> ( map (commuteOrAddToCtxRL (reverseFL a)) $ toNons x , a +>+ x) Nothing -> errorDoc $ redText "mergeAfterConflicting failed in geteff" $$ redText "where ix" $$ displayNons ix $$ redText "and xx" $$ displayPatch xx $$ redText "and rix" $$ displayPatch rix xx2nons :: PrimPatch prim => [Non (RepoPatchV2 prim) wX] -> FL prim wX wY -> [Non (RepoPatchV2 prim) wX] xx2nons ix xx = fst $ geteff ix xx xx2patches :: PrimPatch prim => [Non (RepoPatchV2 prim) wX] -> FL prim wX wY -> FL (RepoPatchV2 prim) wX wY xx2patches ix xx = snd $ geteff ix xx -- | If @xs@ consists only of 'Normal' patches, 'allNormal' @xs@ returns -- @Just pxs@ those patches (so @lengthFL pxs == lengthFL xs@). -- Otherwise, it returns 'Nothing'. allNormal :: FL (RepoPatchV2 prim) wX wY -> Maybe (FL prim wX wY) allNormal (Normal x :>: xs) = (x :>: ) `fmap` allNormal xs allNormal NilFL = Just NilFL allNormal _ = Nothing -- | This is used for unit-testing and for internal sanity checks isConsistent :: PrimPatch prim => RepoPatchV2 prim wX wY -> Maybe Doc isConsistent (Normal _) = Nothing isConsistent (Duplicate _) = Nothing isConsistent (Etacilpud _) = Nothing isConsistent c@(InvConflictor{}) = isConsistent (invert c) isConsistent (Conflictor im mm m@(Non deps _)) | not $ everyoneConflicts im = Just $ redText "Someone doesn't conflict in im in isConsistent" | Just _ <- commuteOrRemFromCtxFL rmm m, _ :>: _ <- mm = Just $ redText "m doesn't conflict with mm in isConsistent" | any (\x -> any (x `conflictsWith`) nmm) im = Just $ redText "mm conflicts with im in isConsistent where nmm is" $$ displayNons nmm | Nothing <- (nmm ++ im) `minus` toNons deps = Just $ redText "dependencies not in conflict:" $$ displayNons (toNons deps) $$ redText "compared with deps itself:" $$ displayPatch deps | otherwise = case allConflictsWith m im of (im1, []) | im1 `eqSet` im -> Nothing (_, imnc) -> Just $ redText ("m doesn't conflict with im in " ++ "isConsistent. unconflicting:") $$ displayNons imnc where (nmm, rmm) = geteff im mm everyoneConflicts :: PrimPatch prim => [Non (RepoPatchV2 prim) wX] -> Bool everyoneConflicts [] = True everyoneConflicts (x : xs) = case allConflictsWith x xs of ([], _) -> False (_, xs') -> everyoneConflicts xs' instance PatchDebug prim => PatchDebug (RepoPatchV2 prim) mergeWith :: PrimPatch prim => Non (RepoPatchV2 prim) wX -> [Non (RepoPatchV2 prim) wX] -> Sealed (FL prim wX) mergeWith p [] = effect `mapSeal` unNon p mergeWith p xs = mergeall . map unNon . (p :) . unconflicting_of $ nonDependsOrConflictsP xs where nonDependsOrConflictsP = filter (\x -> not ((p `dependsUpon` x) || (p `conflictsWith` x))) mergeall :: PrimPatch prim => [Sealed (FL (RepoPatchV2 prim) wX)] -> Sealed (FL prim wX) mergeall [Sealed x] = Sealed $ effect x mergeall [] = Sealed NilFL mergeall (Sealed x : Sealed y : rest) = case merge (x :\/: y) of y' :/\: _ -> mergeall (Sealed (x +>+ y') : rest) unconflicting_of [] = [] unconflicting_of (q : qs) = case allConflictsWith q qs of ([], _) -> q : qs (_, nc) -> unconflicting_of nc instance PrimPatch prim => Conflict (RepoPatchV2 prim) where conflictedEffect (Duplicate (Non _ x)) = [IsC Duplicated x] conflictedEffect (Etacilpud _) = impossible conflictedEffect (Conflictor _ _ (Non _ x)) = [IsC Conflicted x] conflictedEffect (InvConflictor{}) = impossible conflictedEffect (Normal x) = [IsC Okay x] resolveConflicts (Conflictor ix xx x) = [mangledUnravelled : unravelled] where mangledUnravelled = mangleUnravelled unravelled unravelled = nub $ filter isCons $ map (`mergeWith` xIxNonXX) xIxNonXX xIxNonXX = x : ix ++ nonxx nonxx = nonxx_ (reverseFL $ xx2patches ix xx) -- |nonxx_ takes an RL of patches, and returns a singleton list -- containing a Non, in the case where we have a Normal patch at the -- end of the list (using the rest of the RL as context), and an empty -- list otherwise. nonxx_ :: RL (RepoPatchV2 prim) wX wY -> [Non (RepoPatchV2 prim) wX] nonxx_ (qs :<: Normal q) = [Non (reverseRL qs) q] nonxx_ _ = [] isCons = unseal (not . nullFL) resolveConflicts _ = [] instance PrimPatch prim => CommuteNoConflicts (RepoPatchV2 prim) where commuteNoConflicts (d1@(Duplicate _) :> d2@(Duplicate _)) = Just (d2 :> d1) commuteNoConflicts (e@(Etacilpud _) :> d@(Duplicate _)) = Just (d :> e) commuteNoConflicts (d@(Duplicate _) :> e@(Etacilpud _)) = Just (e :> d) commuteNoConflicts (e1@(Etacilpud _) :> e2@(Etacilpud _)) = Just (e2 :> e1) -- If the duplicate is @x@, as a 'Non', with @invert x@ as the context, -- then it is the patch the duplicate @d@ represents, so commuting results -- in the same two patches (since we'd make one a duplicate, and the other -- would become @x@ as it would no longer be duplicated). -- Otherwise, we commute past, or remove @invert x@ from the context of @d@ -- to obtain a new Duplicate. commuteNoConflicts orig@(x :> Duplicate d) = if d == commuteOrAddToCtx (invert x) (non x) then Just orig else do d' <- commuteOrRemFromCtx (invert x) d return (Duplicate d' :> x) -- Commuting a Duplicate and any other patch simply places @invert x@ into -- the context of the non @d@, by commuting past, or adding to the context. commuteNoConflicts (Duplicate d :> x) = Just (x :> Duplicate (commuteOrAddToCtx (invert x) d)) -- handle Etacilpud cases by first inverting, then using the previous -- definitions. commuteNoConflicts c@(Etacilpud _ :> _) = invertCommuteNC c commuteNoConflicts c@(_ :> Etacilpud _) = invertCommuteNC c -- Two normal patches should be simply commuted (assuming the can). commuteNoConflicts (Normal x :> Normal y) = do y' :> x' <- commute (x :> y) return (Normal y' :> Normal x') -- Commuting a Normal patch past a Conflictor first commutes @x@ past the -- effect of the Conflictor, then commutes the resulting @x'@ past the -- conflicting patch and the already-undone patches. The commuting must be -- done in this order to make the contexts match up (@iy@ and @y@ are made -- in the context before @yy@ have their effect, so we need to commute past -- the effect of @yy@ first). commuteNoConflicts (Normal x :> Conflictor iy yy y) = do iyy' :> x' <- commuteFL (x :> invert yy) y' : iy' <- mapM (Normal x' >*) (y : iy) return (Conflictor iy' (invert iyy') y' :> Normal x') -- Handle via the previous case, using the inverting commuter. commuteNoConflicts c@(InvConflictor{} :> Normal _) = invertCommuteNC c -- Commuting a Conflictor past a Normal patch is the dual operation to -- commuting a Normal patch past a Conflictor. commuteNoConflicts (Conflictor iy yy y :> Normal x) = do y' : iy' <- mapM (*> Normal x) (y : iy) x' :> iyy' <- commuteRL (invertFL yy :> x) return (Normal x' :> Conflictor iy' (invertRL iyy') y') -- Handle via the previous case, using the inverting commuter. commuteNoConflicts c@(Normal _ :> InvConflictor{}) = invertCommuteNC c -- Commuting two Conflictors, c1 and c2, first commutes the Conflictors' -- effects, then commutes the effect of c1 and c2 and the other's -- already-undone, and conflicting patch, to bring the already-undone and -- conflicting patch into the context of the commuted effects. commuteNoConflicts (Conflictor ix xx x :> Conflictor iy yy y) = do xx' :> yy' <- commute (yy :> xx) x':ix' <- mapM (yy >>*) (x:ix) y':iy' <- mapM (*>> xx') (y:iy) False <- return $ any (conflictsWith y) (x':ix') False <- return $ any (conflictsWith x') iy return (Conflictor iy' yy' y' :> Conflictor ix' xx' x') -- Handle via the previous case, using the inverting commuter. commuteNoConflicts c@(InvConflictor{} :> InvConflictor{}) = invertCommuteNC c commuteNoConflicts (InvConflictor ix xx x :> Conflictor iy yy y) = do iyy' :> xx' <- commute (xx :> invert yy) y':iy' <- mapM (xx' >>*) (y:iy) x':ix' <- mapM (invertFL iyy' >>*) (x:ix) False <- return $ any (conflictsWith y') (x':ix') False <- return $ any (conflictsWith x') iy' return (Conflictor iy' (invert iyy') y' :> InvConflictor ix' xx' x') commuteNoConflicts (Conflictor iy' yy' y' :> InvConflictor ix' xx' x') = do xx :> iyy <- commute (invert yy' :> xx') y:iy <- mapM (*>> xx') (y':iy') x:ix <- mapM (*>> yy') (x':ix') False <- return $ any (conflictsWith y') (x':ix') False <- return $ any (conflictsWith x') iy' return (InvConflictor ix xx x :> Conflictor iy (invert iyy) y) instance PrimPatch prim => Check (RepoPatchV2 prim) where isInconsistent = isConsistent instance FromPrim (RepoPatchV2 prim) where fromPrim = Normal instance ToFromPrim (RepoPatchV2 prim) where toPrim (Normal p) = Just p toPrim _ = Nothing instance PrimPatch prim => Eq2 (RepoPatchV2 prim) where (Duplicate x) =\/= (Duplicate y) | x == y = IsEq (Etacilpud x) =\/= (Etacilpud y) | x == y = IsEq (Normal x) =\/= (Normal y) = x =\/= y (Conflictor cx xx x) =\/= (Conflictor cy yy y) | map commuteOrAddIXX cx `eqSet` map commuteOrAddIYY cy && commuteOrAddIXX x == commuteOrAddIYY y = xx =/\= yy where commuteOrAddIXX = commutePrimsOrAddToCtx (invertFL xx) commuteOrAddIYY = commutePrimsOrAddToCtx (invertFL yy) (InvConflictor cx xx x) =\/= (InvConflictor cy yy y) | cx `eqSet` cy && x == y = xx =\/= yy _ =\/= _ = NotEq eqSet :: Eq a => [a] -> [a] -> Bool eqSet [] [] = True eqSet (x:xs) xys | Just ys <- remove1 x xys = eqSet xs ys eqSet _ _ = False remove1 :: Eq a => a -> [a] -> Maybe [a] remove1 x (y : ys) = if x == y then Just ys else (y :) `fmap` remove1 x ys remove1 _ [] = Nothing minus :: Eq a => [a] -> [a] -> Maybe [a] minus xs [] = Just xs minus xs (y:ys) = do xs' <- remove1 y xs xs' `minus` ys invertNon :: PrimPatch prim => Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX invertNon (Non c x) | Just rc' <- removeRL nix (reverseFL c) = Non (reverseRL rc') (invert x) | otherwise = commuteOrAddToCtxRL (reverseFL c :<: Normal x) $ non nix where nix = Normal $ invert x nonTouches :: PatchInspect prim => Non (RepoPatchV2 prim) wX -> [FilePath] nonTouches (Non c x) = listTouchedFiles (c +>+ fromPrim x :>: NilFL) nonHunkMatches :: PatchInspect prim => (BC.ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool nonHunkMatches f (Non c x) = hunkMatches f c || hunkMatches f x toNons :: forall p wX wY . (Commute p, PatchListFormat p, Nonable p, ShowPatchBasic (PrimOf p), ShowPatchBasic p) => FL p wX wY -> [Non p wX] toNons xs = map lastNon $ initsFL xs where lastNon :: Sealed ((p :> FL p) wX) -> Non p wX lastNon (Sealed xxx) = case lastNon_aux xxx of deps :> p :> _ -> case non p of Non NilFL pp -> Non (reverseRL deps) pp Non ds pp -> errorDoc $ redText "Weird case in toNons" $$ redText "please report this bug!" $$ (case xxx of z :> zs -> displayPatch (z :>: zs)) $$ redText "ds are" $$ displayPatch ds $$ redText "pp is" $$ displayPatch pp reverseFoo :: (p :> FL p) wX wZ -> (RL p :> p) wX wZ reverseFoo (p :> ps) = rf NilRL p ps where rf :: RL p wA wB -> p wB wC -> FL p wC wD -> (RL p :> p) wA wD rf rs l NilFL = rs :> l rf rs x (y :>: ys) = rf (rs :<: x) y ys lastNon_aux :: (p :> FL p) wX wZ -> (RL p :> p :> RL p) wX wZ lastNon_aux = commuteWhatWeCanRL . reverseFoo filterConflictsFL :: PrimPatch prim => Non (RepoPatchV2 prim) wX -> FL prim wX wY -> (FL prim :> FL prim) wX wY filterConflictsFL _ NilFL = NilFL :> NilFL filterConflictsFL n (p :>: ps) | Just n' <- commuteOrRemFromCtx (fromPrim p) n = case filterConflictsFL n' ps of p1 :> p2 -> p :>: p1 :> p2 | otherwise = case commuteWhatWeCanFL (p :> ps) of p1 :> p' :> p2 -> case filterConflictsFL n p1 of p1a :> p1b -> p1a :> p1b +>+ p' :>: p2 instance Invert prim => Invert (RepoPatchV2 prim) where invert (Duplicate d) = Etacilpud d invert (Etacilpud d) = Duplicate d invert (Normal p) = Normal (invert p) invert (Conflictor x c p) = InvConflictor x c p invert (InvConflictor x c p) = Conflictor x c p instance PrimPatch prim => Commute (RepoPatchV2 prim) where commute (x :> y) | Just (y' :> x') <- commuteNoConflicts (assertConsistent x :> assertConsistent y) = Just (y' :> x') -- These patches conflicted, since we failed to commuteNoConflicts in the -- case above. commute (Normal x :> Conflictor a1'nop2 n1'x p1') | Just rn1' <- removeRL x (reverseFL n1'x) = do let p2 : n1nons = reverse $ xx2nons a1'nop2 $ reverseRL (rn1' :<: x) a2 = p1' : a1'nop2 ++ n1nons case (a1'nop2, reverseRL rn1', p1') of ([], NilFL, Non c y) | NilFL <- joinEffects c -> Just (Normal y :> Conflictor a1'nop2 (y :>: NilFL) p2) (a1, n1, _) -> Just (Conflictor a1 n1 p1' :> Conflictor a2 NilFL p2) -- Handle using the inverting commuter, and the previous case. N.b. this -- is innefficient, since we'll have to also try commuteNoConflicts again -- (which we know will fail, since we got here). commute c@(InvConflictor{} :> Normal _) = invertCommute c commute (Conflictor a1 n1 p1 :> Conflictor a2 n2 p2) | Just a2_minus_p1 <- remove1 p1' a2 , not (p2 `dependsUpon` p1') = do let n1nons = map (commutePrimsOrAddToCtx n2) $ xx2nons a1 n1 n2nons = xx2nons a2 n2 Just a2_minus_p1n1 = a2_minus_p1 `minus` n1nons n2n1 = n2 +>+ n1 a1' = map (commutePrimsOrAddToCtx n2) a1 p2ooo = remNons a1' p2 n1' :> n2' <- return $ filterConflictsFL p2ooo n2n1 let n1'n2'nons = xx2nons a2_minus_p1n1 (n1' +>+ n2') n1'nons = take (lengthFL n1') n1'n2'nons n2'nons = drop (lengthFL n1') n1'n2'nons Just a1'nop2 = (a2 ++ n2nons) `minus` (p1' : n1'nons) Just a2'o = fst (allConflictsWith p2 $ a2_minus_p1 ++ n2nons) `minus` n2'nons Just a2' = mapM (commuteOrRemFromCtxFL (xx2patches a1'nop2 n1')) a2'o Just p2' = commuteOrRemFromCtxFL (xx2patches a1'nop2 n1') p2 case (a2', n2', p2') of ([], NilFL, Non c x) -> case joinEffects c of NilFL -> let n1'x = n1' +>+ x :>: NilFL in Just (Normal x :> Conflictor a1'nop2 n1'x p1') _ -> impossible _ -> Just (c1 :> c2) where c1 = Conflictor a2' n2' p2' c2 = Conflictor (p2 : a1'nop2) n1' p1' where (_, rpn2) = geteff a2 n2 p1' = commuteOrAddToCtxRL (reverseFL rpn2) p1 -- Handle using the inverting commuter, and the previous case. This is also -- innefficient, since we'll have to also try commuteNoConflicts again -- (which we know will fail, since we got here). commute c@(InvConflictor{} :> InvConflictor{}) = invertCommute c commute _ = Nothing instance PrimPatch prim => Merge (RepoPatchV2 prim) where merge (InvConflictor{} :\/: _) = impossible merge (_ :\/: InvConflictor{}) = impossible merge (Etacilpud _ :\/: _) = impossible merge (_ :\/: Etacilpud _) = impossible merge (Duplicate a :\/: Duplicate b) = Duplicate b :/\: Duplicate a -- We had a FIXME comment on this case, why? merge (Duplicate a :\/: b) = b :/\: Duplicate (commuteOrAddToCtx (invert b) a) -- Handle using the swap merge and the previous case. merge m@(_ :\/: Duplicate _) = swapMerge m merge (x :\/: y) -- First try the natural (non-conflicting) merge. | Just (y' :/\: x') <- naturalMerge ((assertConsistent x) :\/: (assertConsistent y)) = assertConsistent y' :/\: assertConsistent x' -- If we detect equal patches, we have a duplicate. | IsEq <- x =\/= y , n <- commuteOrAddToCtx (invert x) $ non x = Duplicate n :/\: Duplicate n -- We know that these two patches conflict, and aren't Duplicates, since we -- failed the previous case. We therefore create basic Conflictors, which -- undo the other patch. merge (nx@(Normal x) :\/: ny@(Normal y)) = cy :/\: cx where cy = Conflictor [] (x :>: NilFL) (non ny) cx = Conflictor [] (y :>: NilFL) (non nx) -- If a Normal patch @x@ and a Conflictor @cy@ conflict, we add @x@ to the -- effect of @cy@ on one side, and create a Conflictor that has no effect, -- but has the already-undone and conflicted patch of @cy@ and some foos as -- the already-undone on the other side. -- -- TODO: what is foo? -- Why do we need nyy? I think @x'@ is @x@ in the context of @yy@. merge (Normal x :\/: Conflictor iy yy y) = Conflictor iy yyx y :/\: Conflictor (y : iy ++ nyy) NilFL x' where yyx = yy +>+ x :>: NilFL (x' : nyy) = reverse $ xx2nons iy yyx -- Handle using the swap merge and the previous case. merge m@(Conflictor{} :\/: Normal _) = swapMerge m -- mH see also cH merge (Conflictor ix xx x :\/: Conflictor iy yy y) = case pullCommonRL (reverseFL xx) (reverseFL yy) of CommonRL rxx1 ryy1 c -> case commuteRLFL (ryy1 :> invertRL rxx1) of Just (ixx' :> ryy') -> let xx' = invert ixx' yy' = reverseRL ryy' y' : iy' = map (commutePrimsOrAddToCtx xx') (y : iy) x' : ix' = map (commutePrimsOrAddToCtx ryy') (x : ix) nyy' = xx2nons iy' yy' nxx' = xx2nons ix' xx' icx = drop (lengthRL rxx1) $ xx2nons ix (reverseRL $ rxx1 +<+ c) ic' = map (commutePrimsOrAddToCtx ryy') icx -- +++ is a more efficient version of nub (iy' ++ -- ix') given that we know each element shows up -- only once in either list. ixy' = ic' ++ (iy' +++ ix') c1 = Conflictor (x' : ixy' ++ nxx') yy' y' c2 = Conflictor (y' : ixy' ++ nyy') xx' x' in c1 :/\: c2 Nothing -> impossible instance PatchInspect prim => PatchInspect (RepoPatchV2 prim) where listTouchedFiles (Duplicate p) = nonTouches p listTouchedFiles (Etacilpud p) = nonTouches p listTouchedFiles (Normal p) = listTouchedFiles p listTouchedFiles (Conflictor x c p) = nubSort $ concatMap nonTouches x ++ listTouchedFiles c ++ nonTouches p listTouchedFiles (InvConflictor x c p) = nubSort $ concatMap nonTouches x ++ listTouchedFiles c ++ nonTouches p hunkMatches f (Duplicate p) = nonHunkMatches f p hunkMatches f (Etacilpud p) = nonHunkMatches f p hunkMatches f (Normal p) = hunkMatches f p hunkMatches f (Conflictor x c p) = any (nonHunkMatches f) x || hunkMatches f c || nonHunkMatches f p hunkMatches f (InvConflictor x c p) = any (nonHunkMatches f) x || hunkMatches f c || nonHunkMatches f p allConflictsWith :: PrimPatch prim => Non (RepoPatchV2 prim) wX -> [Non (RepoPatchV2 prim) wX] -> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX]) allConflictsWith x ys = acw $ partition (conflictsWith x) ys where acw ([], nc) = ([], nc) acw (c:cs, nc) = case allConflictsWith c nc of (c1, nc1) -> case acw (cs, nc1) of (xs', nc') -> (c : c1 ++ xs', nc') conflictsWith :: PrimPatch prim => Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool conflictsWith x y | x `dependsUpon` y || y `dependsUpon` x = False conflictsWith x (Non cy y) = case commuteOrRemFromCtxFL cy x of Just (Non cx' x') -> let iy = fromPrim $ invert y in case commuteFLorComplain (iy :> cx' +>+ fromPrim x' :>: NilFL) of Right _ -> False Left _ -> True Nothing -> True dependsUpon :: PrimPatch prim => Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool dependsUpon (Non xs _) (Non ys y) = case removeSubsequenceFL (ys +>+ fromPrim y :>: NilFL) xs of Just _ -> True Nothing -> False (+++) :: Eq a => [a] -> [a] -> [a] [] +++ x = x x +++ [] = x (x:xs) +++ xys | Just ys <- remove1 x xys = x : (xs +++ ys) | otherwise = x : (xs +++ xys) swapMerge :: Merge p => (p :\/: p) wX wY -> (p :/\: p) wX wY swapMerge (x :\/: y) = case merge (y :\/: x) of x' :/\: y' -> y' :/\: x' invertCommute :: (Invert p, Commute p) => (p :> p) wX wY -> Maybe ((p :> p) wX wY) invertCommute (x :> y) = do ix' :> iy' <- commute (invert y :> invert x) return (invert iy' :> invert ix') invertCommuteNC :: PrimPatch prim => (RepoPatchV2 prim :> RepoPatchV2 prim) wX wY -> Maybe ((RepoPatchV2 prim :> RepoPatchV2 prim) wX wY) invertCommuteNC (x :> y) = do ix' :> iy' <- commuteNoConflicts (invert y :> invert x) return (invert iy' :> invert ix') -- | 'pullCommon' @xs ys@ returns the set of patches that can be commuted out -- of both @xs@ and @ys@ along with the remnants of both lists pullCommon :: (Commute p, Eq2 p) => FL p wO wX -> FL p wO wY -> Common p wO wX wY pullCommon NilFL ys = Common NilFL NilFL ys pullCommon xs NilFL = Common NilFL xs NilFL pullCommon (x :>: xs) xys | Just ys <- removeFL x xys = case pullCommon xs ys of Common c xs' ys' -> Common (x :>: c) xs' ys' pullCommon (x :>: xs) ys = case commuteWhatWeCanFL (x :> xs) of xs1 :> x' :> xs2 -> case pullCommon xs1 ys of Common c xs1' ys' -> Common c (xs1' +>+ x' :>: xs2) ys' -- | 'Common' @cs xs ys@ represents two sequences of patches that have @cs@ in -- common, in other words @cs +>+ xs@ and @cs +>+ ys@ data Common p wO wX wY where Common :: FL p wO wI -> FL p wI wX -> FL p wI wY -> Common p wO wX wY -- | 'pullCommonRL' @xs ys@ returns the set of patches that can be commuted -- out of both @xs@ and @ys@ along with the remnants of both lists pullCommonRL :: (Commute p, Eq2 p) => RL p wX wO -> RL p wY wO -> CommonRL p wX wY wO pullCommonRL NilRL ys = CommonRL NilRL ys NilRL pullCommonRL xs NilRL = CommonRL xs NilRL NilRL pullCommonRL (xs :<: x) xys | Just ys <- removeRL x xys = case pullCommonRL xs ys of CommonRL xs' ys' c -> CommonRL xs' ys' (c :<: x) pullCommonRL (xs :<: x) ys = case commuteWhatWeCanRL (xs :> x) of xs1 :> x' :> xs2 -> case pullCommonRL xs2 ys of CommonRL xs2' ys' c -> CommonRL (xs1 :<: x' +<+ xs2') ys' c -- | 'CommonRL' @xs ys cs@' represents two sequences of patches that have @cs@ -- in common, in other words @xs +<+ cs@ and @ys +<+ cs@ data CommonRL p wX wY wF where CommonRL :: RL p wX wI -> RL p wY wI -> RL p wI wF -> CommonRL p wX wY wF instance PrimPatch prim => Apply (RepoPatchV2 prim) where type ApplyState (RepoPatchV2 prim) = ApplyState prim apply p = apply (effect p) instance PrimPatch prim => RepairToFL (RepoPatchV2 prim) where applyAndTryToFixFL (Normal p) = mapMaybeSnd (mapFL_FL Normal) `liftM` applyAndTryToFixFL p applyAndTryToFixFL x = do apply x; return Nothing instance (PrimPatch prim, Annotate prim) => Annotate (RepoPatchV2 prim) where annotate = annotate . effect instance PatchListFormat (RepoPatchV2 prim) where -- In principle we could use ListFormatDefault when prim /= V1 Prim patches, -- as those are the only case where we need to support a legacy on-disk -- format. In practice we don't expect RepoPatchV2 to be used with any other -- argument anyway, so it doesn't matter. patchListFormat = ListFormatV2 duplicate, etacilpud, conflictor, rotcilfnoc :: String duplicate = "duplicate" etacilpud = "etacilpud" conflictor = "conflictor" rotcilfnoc = "rotcilfnoc" instance PrimPatch prim => ShowPatchBasic (RepoPatchV2 prim) where showPatch f (Duplicate d) = blueText duplicate $$ showNon f d showPatch f (Etacilpud d) = blueText etacilpud $$ showNon f d showPatch f (Normal p) = showPatch f p showPatch f (Conflictor i NilFL p) = blueText conflictor <+> showNons f i <+> blueText "[]" $$ showNon f p showPatch f (Conflictor i cs p) = blueText conflictor <+> showNons f i <+> blueText "[" $$ showFL f cs $$ blueText "]" $$ showNon f p showPatch f (InvConflictor i NilFL p) = blueText rotcilfnoc <+> showNons f i <+> blueText "[]" $$ showNon f p showPatch f (InvConflictor i cs p) = blueText rotcilfnoc <+> showNons f i <+> blueText "[" $$ showFL f cs $$ blueText "]" $$ showNon f p instance PrimPatch prim => ShowContextPatch (RepoPatchV2 prim) where showContextPatch f (Normal p) = showContextPatch f p showContextPatch f p = return $ showPatch f p instance PrimPatch prim => ShowPatch (RepoPatchV2 prim) where summary = plainSummary summaryFL = plainSummary thing _ = "change" instance PrimPatch prim => ReadPatch (RepoPatchV2 prim) where readPatch' = do skipSpace let str = string . BC.pack readConflictorPs = do i <- readNons ps <- bracketedFL readPatch' '[' ']' p <- readNon return (i, ps, p) choice [ do str duplicate p <- readNon return $ Sealed $ Duplicate p , do str etacilpud p <- readNon return $ Sealed $ Etacilpud p , do str conflictor (i, Sealed ps, p) <- readConflictorPs return $ Sealed $ Conflictor i (unsafeCoerceP ps) p , do str rotcilfnoc (i, Sealed ps, p) <- readConflictorPs return $ Sealed $ InvConflictor i ps p , do Sealed p <- readPatch' return $ Sealed $ Normal p ] instance Show2 prim => Show (RepoPatchV2 prim wX wY) where showsPrec d (Normal prim) = showParen (d > appPrec) $ showString "Normal " . showsPrec2 (appPrec + 1) prim showsPrec d (Duplicate x) = showParen (d > appPrec) $ showString "Duplicate " . showsPrec (appPrec + 1) x showsPrec d (Etacilpud x) = showParen (d > appPrec) $ showString "Etacilpud " . showsPrec (appPrec + 1) x showsPrec d (Conflictor ix xx x) = showParen (d > appPrec) $ showString "Conflictor " . showsPrec (appPrec + 1) ix . showString " " . showsPrec (appPrec + 1) xx . showString " " . showsPrec (appPrec + 1) x showsPrec d (InvConflictor ix xx x) = showParen (d > appPrec) $ showString "InvConflictor " . showsPrec (appPrec + 1) ix . showString " " . showsPrec (appPrec + 1) xx . showString " " . showsPrec (appPrec + 1) x instance Show2 prim => Show1 (RepoPatchV2 prim wX) where showDict1 = ShowDictClass instance Show2 prim => Show2 (RepoPatchV2 prim) where showDict2 = ShowDictClass instance PrimPatch prim => Nonable (RepoPatchV2 prim) where non (Duplicate d) = d non (Etacilpud d) = invertNon d -- FIXME !!! ??? non (Normal p) = Non NilFL p non (Conflictor _ xx x) = commutePrimsOrAddToCtx (invertFL xx) x non (InvConflictor _ _ n) = invertNon n instance PrimPatch prim => Effect (RepoPatchV2 prim) where effect (Duplicate _) = NilFL effect (Etacilpud _) = NilFL effect (Normal p) = p :>: NilFL effect (Conflictor _ e _) = invert e effect (InvConflictor _ e _) = e effectRL (Duplicate _) = NilRL effectRL (Etacilpud _) = NilRL effectRL (Normal p) = NilRL :<: p effectRL (Conflictor _ e _) = invertFL e effectRL (InvConflictor _ e _) = reverseFL e instance IsHunk prim => IsHunk (RepoPatchV2 prim) where isHunk rp = do Normal p <- return rp isHunk p displayNons :: (PatchListFormat p, ShowPatchBasic p, PrimPatchBase p) => [Non p wX] -> Doc displayNons p = showNons ForDisplay p showFL :: ShowPatchBasic p => ShowPatchFor -> FL p wX wY -> Doc showFL f = vcat . mapFL (showPatch f) darcs-2.14.5/src/Darcs/Patch/Viewing.hs0000644000000000000000000001660607346545000015727 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# OPTIONS_GHC -fno-warn-orphans -fno-warn-unused-imports #-} module Darcs.Patch.Viewing ( showContextHunk ) where import Prelude () import Darcs.Prelude import Control.Applicative( (<$>) ) import qualified Data.ByteString as B ( null ) import Prelude hiding ( pi, readFile ) import Darcs.Util.Tree ( Tree ) import Darcs.Util.Tree.Monad ( virtualTreeMonad ) import Darcs.Patch.Apply ( Apply(..) ) import Darcs.Patch.ApplyMonad ( getApplyState, ApplyMonad(..), ApplyMonadTree(..), toTree ) import Darcs.Patch.FileHunk ( IsHunk(..), FileHunk(..), showFileHunk ) import Darcs.Patch.Format ( PatchListFormat(..), ListFormat(..), FileNameFormat(..) ) import Darcs.Patch.Show ( ShowPatchBasic(..), ShowPatch(..) , formatFileName, ShowPatchFor(..), ShowContextPatch(..) ) import Darcs.Patch.Witnesses.Ordered ( RL(..), FL(..), mapFL, mapFL_FL, reverseRL, concatFL ) import Darcs.Util.ByteString ( linesPS ) import Darcs.Util.Printer ( Doc, empty, vcat, text, blueText, Color(Cyan, Magenta), lineColor, ($$), (<+>), prefix, userchunkPS ) showContextSeries :: forall p m wX wY . (Apply p, ShowContextPatch p, IsHunk p, ApplyMonad (ApplyState p) m) => ShowPatchFor -> FileNameFormat -> FL p wX wY -> m Doc showContextSeries use fmt = scs Nothing where scs :: forall wWw wXx wYy . Maybe (FileHunk wWw wXx) -> FL p wXx wYy -> m Doc scs pold (p :>: ps) = do (_, s') <- nestedApply (apply p) =<< getApplyState case isHunk p of Nothing -> do a <- showContextPatch use p b <- nestedApply (scs Nothing ps) s' return $ a $$ fst b Just fh -> case ps of NilFL -> fst <$> liftApply (cool pold fh Nothing) s' (p2 :>: _) -> do a <- fst <$> liftApply (cool pold fh (isHunk p2)) s' b <- nestedApply (scs (Just fh) ps) s' return $ a $$ fst b scs _ NilFL = return empty cool :: Maybe (FileHunk wA wB) -> FileHunk wB wC -> Maybe (FileHunk wC wD) -> (ApplyState p) (ApplyMonadBase m) -> (ApplyMonadBase m) Doc cool pold fh ps s = fst <$> virtualTreeMonad (coolContextHunk fmt pold fh ps) (toTree s) showContextHunk :: (ApplyMonad Tree m) => FileNameFormat -> FileHunk wX wY -> m Doc showContextHunk fmt h = coolContextHunk fmt Nothing h Nothing coolContextHunk :: (ApplyMonad Tree m) => FileNameFormat -> Maybe (FileHunk wA wB) -> FileHunk wB wC -> Maybe (FileHunk wC wD) -> m Doc coolContextHunk fmt prev fh@(FileHunk f l o n) next = do have <- mDoesFileExist f content <- if have then Just `fmap` mReadFilePS f else return Nothing case linesPS `fmap` content of -- FIXME This is a weird error... Nothing -> return $ showFileHunk fmt fh Just ls -> let pre = take numpre $ drop (l - numpre - 1) ls cleanedls = case reverse ls of (x : xs) | B.null x -> reverse xs _ -> ls post = take numpost $ drop (max 0 $ l+length o-1) cleanedls in return $ blueText "hunk" <+> formatFileName fmt f <+> text (show l) $$ prefix " " (vcat $ map userchunkPS pre) $$ lineColor Magenta (prefix "-" (vcat $ map userchunkPS o)) $$ lineColor Cyan (prefix "+" (vcat $ map userchunkPS n)) $$ prefix " " (vcat $ map userchunkPS post) where numpre = case prev of Just (FileHunk f' lprev _ nprev) | f' == f && l - (lprev + length nprev + 3) < 3 && lprev < l -> max 0 $ l - (lprev + length nprev + 3) _ -> if l >= 4 then 3 else l - 1 numpost = case next of Just (FileHunk f' lnext _ _) | f' == f && lnext < l + length n + 4 && lnext > l -> lnext - (l + length n) _ -> 3 instance (PatchListFormat p, ShowPatchBasic p) => ShowPatchBasic (FL p) where showPatch ForDisplay = vcat . mapFL (showPatch ForDisplay) showPatch ForStorage = showPatchInternal patchListFormat where showPatchInternal :: ListFormat p -> FL p wX wY -> Doc showPatchInternal ListFormatV1 (p :>: NilFL) = (showPatch ForStorage) p showPatchInternal ListFormatV1 NilFL = blueText "{" $$ blueText "}" showPatchInternal ListFormatV1 ps = blueText "{" $$ vcat (mapFL (showPatch ForStorage) ps) $$ blueText "}" showPatchInternal ListFormatV2 ps = vcat (mapFL (showPatch ForStorage) ps) showPatchInternal ListFormatDefault ps = vcat (mapFL (showPatch ForStorage) ps) instance (Apply p, IsHunk p, PatchListFormat p, ShowContextPatch p) => ShowContextPatch (FL p) where showContextPatch ForDisplay = showContextSeries ForDisplay UserFormat showContextPatch ForStorage = showContextPatchInternal patchListFormat where showContextPatchInternal :: (ApplyMonad (ApplyState (FL p)) m) => ListFormat p -> FL p wX wY -> m Doc showContextPatchInternal ListFormatV1 (p :>: NilFL) = showContextPatch ForStorage p showContextPatchInternal ListFormatV1 NilFL = return $ blueText "{" $$ blueText "}" showContextPatchInternal ListFormatV1 ps = do x <- showContextSeries ForStorage OldFormat ps return $ blueText "{" $$ x $$ blueText "}" showContextPatchInternal ListFormatV2 ps = showContextSeries ForStorage NewFormat ps showContextPatchInternal ListFormatDefault ps = showContextSeries ForStorage NewFormat ps instance (PatchListFormat p, ShowPatch p) => ShowPatch (FL p) where description = vcat . mapFL description summary = summaryFL summaryFL = summaryFL . concatFL thing x = thing (helperx x) ++ "s" where helperx :: FL a wX wY -> a wX wY helperx _ = undefined things = thing instance (PatchListFormat p, ShowPatchBasic p) => ShowPatchBasic (RL p) where showPatch f = showPatch f . reverseRL instance (ShowContextPatch p, Apply p, IsHunk p, PatchListFormat p) => ShowContextPatch (RL p) where showContextPatch use = showContextPatch use . reverseRL instance (PatchListFormat p, ShowPatch p) => ShowPatch (RL p) where description = description . reverseRL summary = summary . reverseRL summaryFL = summaryFL . mapFL_FL reverseRL thing = thing . reverseRL things = things . reverseRL darcs-2.14.5/src/Darcs/Patch/Witnesses/0000755000000000000000000000000007346545000015736 5ustar0000000000000000darcs-2.14.5/src/Darcs/Patch/Witnesses/Eq.hs0000644000000000000000000000360707346545000016645 0ustar0000000000000000module Darcs.Patch.Witnesses.Eq ( EqCheck(..) , Eq2(..) , isIsEq ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) -- |'EqCheck' is used to pass around evidence (or lack thereof) of -- two witness types being equal. data EqCheck wA wB where IsEq :: EqCheck wA wA NotEq :: EqCheck wA wB instance Eq (EqCheck wA wB) where IsEq == IsEq = True NotEq == NotEq = True _ == _ = False instance Show (EqCheck wA wB) where show IsEq = "IsEq" show NotEq = "NotEq" -- |An witness aware equality class. -- A minimal definition defines any one of 'unsafeCompare', '=\/=' and '=/\='. class Eq2 p where -- |It is unsafe to define a class instance via this method, because -- if it returns True then the default implementations of '=\/=' and '=/\=' -- will coerce the equality of two witnesses. -- -- Calling this method is safe, although '=\/=' or '=/\=' would be better -- choices as it is not usually meaningul to compare two patches that -- don't share either a starting or an ending context unsafeCompare :: p wA wB -> p wC wD -> Bool unsafeCompare a b = IsEq == (a =/\= unsafeCoerceP b) -- |Compare two things with the same starting witness. If the things -- compare equal, evidence of the ending witnesses being equal will -- be returned. (=\/=) :: p wA wB -> p wA wC -> EqCheck wB wC a =\/= b | unsafeCompare a b = unsafeCoerceP IsEq | otherwise = NotEq -- |Compare two things with the same ending witness. If the things -- compare equal, evidence of the starting witnesses being equal will -- be returned. (=/\=) :: p wA wC -> p wB wC -> EqCheck wA wB a =/\= b | IsEq == (a =\/= unsafeCoerceP b) = unsafeCoerceP IsEq | otherwise = NotEq infix 4 =\/=, =/\= isIsEq :: EqCheck wA wB -> Bool isIsEq IsEq = True isIsEq NotEq = False darcs-2.14.5/src/Darcs/Patch/Witnesses/Ordered.hs0000644000000000000000000003403707346545000017665 0ustar0000000000000000-- Copyright (C) 2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.Witnesses.Ordered ( -- * Directed Types -- $DirectedTypes (:>)(..) , FL(..) , RL(..) -- * Merge Types -- $MergeTypes , (:\/:)(..) , (:/\:)(..) , (:||:)(..) , Fork(..) -- * Functions for 'FL's and 'RL's , nullFL , nullRL , lengthFL , lengthRL , mapFL , mapRL , mapFL_FL , mapRL_RL , foldlFL , foldlRL , allFL , allRL , anyFL , anyRL , filterFL , filterRL , splitAtFL , splitAtRL , filterOutFLFL , filterOutRLRL , reverseFL , reverseRL , (+>+) , (+<+) , (+>>+) , (+<<+) , concatFL , concatRL , dropWhileFL , dropWhileRL -- * 'FL' only , bunchFL , foldFL_M , spanFL , spanFL_M , zipWithFL , toFL , mapFL_FL_M , sequenceFL_ , eqFL , eqFLRev , eqFLUnsafe , initsFL -- * 'RL' only , isShorterThanRL , snocRLSealed ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Witnesses.Show import Darcs.Patch.Witnesses.Sealed ( FlippedSeal(..) , flipSeal , Sealed(..) , FreeLeft , unFreeLeft , Sealed2(..) , seal ) import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) ) -- * Directed Types -- $DirectedTypes -- Darcs patches have a notion of transforming between contexts. This -- naturally leads us to container types that are \"directed\" and -- transform from one context to another. -- -- For example, the swap of names of files x and y could be represented -- with the following sequence of patches: -- -- @ Move x z ':>' Move y x ':>' Move z y @ -- -- or using forward lists, like -- -- @ Move x z ':>:' Move y x ':>:' Move z y ':>:' NilFL @ -- | Directed Forward Pairs data (a1 :> a2) wX wY = forall wZ . (a1 wX wZ) :> (a2 wZ wY) infixr 1 :> -- | Forward lists data FL a wX wZ where (:>:) :: a wX wY -> FL a wY wZ -> FL a wX wZ NilFL :: FL a wX wX -- | Reverse lists data RL a wX wZ where (:<:) :: RL a wX wY -> a wY wZ -> RL a wX wZ NilRL :: RL a wX wX instance Show2 a => Show (FL a wX wZ) where showsPrec _ NilFL = showString "NilFL" showsPrec d (x :>: xs) = showParen (d > prec) $ showsPrec2 (prec + 1) x . showString " :>: " . showsPrec (prec + 1) xs where prec = 5 instance Show2 a => Show1 (FL a wX) where showDict1 = ShowDictClass instance Show2 a => Show2 (FL a) where showDict2 = ShowDictClass instance Show2 a => Show (RL a wX wZ) where showsPrec _ NilRL = showString "NilRL" showsPrec d (xs :<: x) = showParen (d > prec) $ showsPrec (prec + 1) xs . showString " :<: " . showsPrec2 (prec + 1) x where prec = 5 instance Show2 a => Show1 (RL a wX) where showDict1 = ShowDictClass instance Show2 a => Show2 (RL a) where showDict2 = ShowDictClass instance (Show2 a, Show2 b) => Show1 ((a :> b) wX) where showDict1 = ShowDictClass -- * Merge Types -- $MergeTypes -- When we have two patches which commute and share the same pre-context we can -- merge the patches. Whenever patches, or sequences of patches, share a -- pre-context we say they are Forking Pairs (':\/:'). The same way, when -- patches or sequences of patches, share a post-context we say they are -- Joining Pairs (':/\:'). -- -- The following diagram shows the symmetry of merge types: -- -- @ wZ -- ':/\:' -- a3 / \ a4 -- / \ -- wX wY -- \ / -- a1 \ / a2 -- ':\/:' -- wZ -- @ -- -- (non-haddock version) -- wZ -- :/\: -- a3 / \ a4 -- / \ -- wX wY -- \ / -- a1 \ / a2 -- :\/: -- wZ -- infix 1 :/\:, :\/:, :||: -- | Forking Pairs (Implicit starting context) data (a1 :\/: a2) wX wY = forall wZ . (a1 wZ wX) :\/: (a2 wZ wY) -- | Joining Pairs data (a3 :/\: a4) wX wY = forall wZ . (a3 wX wZ) :/\: (a4 wY wZ) -- | Forking Pair (Explicit starting context) -- -- @ wX wY -- \ / -- \ / -- \ / -- wU -- | -- | -- | -- wA -- @ -- -- (non-haddock version) -- -- wX wY -- \ / -- \ / -- \ / -- wU -- | -- | -- | -- wA -- data Fork common left right wA wX wY = forall wU. Fork (common wA wU) (left wU wX) (right wU wY) -- | Parallel Pairs data (a1 :||: a2) wX wY = (a1 wX wY) :||: (a2 wX wY) instance (Show2 a, Show2 b) => Show ( (a :> b) wX wY ) where showsPrec d (x :> y) = showOp2 1 ":>" d x y instance (Eq2 a, Eq2 b) => Eq2 (a :> b) where (a1 :> b1) =\/= (a2 :> b2) | IsEq <- a1 =\/= a2 = b1 =\/= b2 | otherwise = NotEq instance (Eq2 a, Eq2 b) => Eq ((a :> b) wX wY) where (==) = unsafeCompare instance (Show2 a, Show2 b) => Show2 (a :> b) where showDict2 = ShowDictClass instance (Show2 a, Show2 b) => Show ( (a :\/: b) wX wY ) where showsPrec d (x :\/: y) = showOp2 9 ":\\/:" d x y instance (Show2 a, Show2 b) => Show2 (a :\/: b) where showDict2 = ShowDictClass instance (Show2 a, Show2 b) => Show ( (a :/\: b) wX wY ) where showsPrec d (x :/\: y) = showOp2 1 ":/\\:" d x y instance (Show2 a, Show2 b) => Show2 ( (a :/\: b) ) where showDict2 = ShowDictClass -- * Functions infixr 5 :>:, +>+ infixl 5 :<:, +<+ nullFL :: FL a wX wZ -> Bool nullFL NilFL = True nullFL _ = False nullRL :: RL a wX wZ -> Bool nullRL NilRL = True nullRL _ = False -- | @filterOutFLFL p xs@ deletes any @x@ in @xs@ for which @p x == IsEq@ -- (indicating that @x@ has no effect as far as we are concerned, and can be -- safely removed from the chain) filterOutFLFL :: (forall wX wY . p wX wY -> EqCheck wX wY) -> FL p wW wZ -> FL p wW wZ filterOutFLFL _ NilFL = NilFL filterOutFLFL f (x:>:xs) | IsEq <- f x = filterOutFLFL f xs | otherwise = x :>: filterOutFLFL f xs filterOutRLRL :: (forall wX wY . p wX wY -> EqCheck wX wY) -> RL p wW wZ -> RL p wW wZ filterOutRLRL _ NilRL = NilRL filterOutRLRL f (xs:<:x) | IsEq <- f x = filterOutRLRL f xs | otherwise = filterOutRLRL f xs :<: x filterRL :: (forall wX wY . p wX wY -> Bool) -> RL p wA wB -> [Sealed2 p] filterRL _ NilRL = [] filterRL f (xs :<: x) | f x = Sealed2 x : (filterRL f xs) | otherwise = filterRL f xs (+>+) :: FL a wX wY -> FL a wY wZ -> FL a wX wZ NilFL +>+ ys = ys (x:>:xs) +>+ ys = x :>: xs +>+ ys (+<+) :: RL a wX wY -> RL a wY wZ -> RL a wX wZ xs +<+ NilRL = xs xs +<+ (ys:<:y) = xs +<+ ys :<: y reverseFL :: FL a wX wZ -> RL a wX wZ reverseFL xs = r NilRL xs where r :: RL a wL wM -> FL a wM wO -> RL a wL wO r ls NilFL = ls r ls (a:>:as) = r (ls:<:a) as reverseRL :: RL a wX wZ -> FL a wX wZ reverseRL xs = r NilFL xs where r :: FL a wM wO -> RL a wL wM -> FL a wL wO r ls NilRL = ls r ls (as:<:a) = r (a:>:ls) as concatFL :: FL (FL a) wX wZ -> FL a wX wZ concatFL NilFL = NilFL concatFL (a:>:as) = a +>+ concatFL as concatRL :: RL (RL a) wX wZ -> RL a wX wZ concatRL NilRL = NilRL concatRL (as:<:a) = concatRL as +<+ a spanFL :: (forall wW wY . a wW wY -> Bool) -> FL a wX wZ -> (FL a :> FL a) wX wZ spanFL f (x:>:xs) | f x = case spanFL f xs of ys :> zs -> (x:>:ys) :> zs spanFL _ xs = NilFL :> xs spanFL_M :: forall a m wX wZ. Monad m => (forall wW wY . a wW wY -> m Bool) -> FL a wX wZ -> m ((FL a :> FL a) wX wZ) spanFL_M f (x:>:xs) = do continue <- f x if continue then do (ys :> zs) <- spanFL_M f xs return $ (x :>: ys) :> zs else return $ NilFL :> (x :>: xs) spanFL_M _ (NilFL) = return $ NilFL :> NilFL splitAtFL :: Int -> FL a wX wZ -> (FL a :> FL a) wX wZ splitAtFL 0 xs = NilFL :> xs splitAtFL _ NilFL = NilFL :> NilFL splitAtFL n (x:>:xs) = case splitAtFL (n-1) xs of (xs':>xs'') -> (x:>:xs' :> xs'') splitAtRL :: Int -> RL a wX wZ -> (RL a :> RL a) wX wZ splitAtRL 0 xs = xs :> NilRL splitAtRL _ NilRL = NilRL :> NilRL splitAtRL n (xs:<:x) = case splitAtRL (n-1) xs of (xs'':>xs') -> (xs'':> xs':<:x) -- 'bunchFL n' groups patches into batches of n, except that it always puts -- the first patch in its own group, this being a recognition that the -- first patch is often *very* large. bunchFL :: Int -> FL a wX wY -> FL (FL a) wX wY bunchFL _ NilFL = NilFL bunchFL n (x:>:xs) = (x :>: NilFL) :>: bFL xs where bFL :: FL a wX wY -> FL (FL a) wX wY bFL NilFL = NilFL bFL bs = case splitAtFL n bs of a :> b -> a :>: bFL b -- | Monadic fold over an 'FL' -- associating to the left, i.e. from left to right. -- The order of arguments follows the standard 'foldM' from base. foldFL_M :: Monad m => (forall wA wB. r wA -> p wA wB -> m (r wB)) -> r wX -> FL p wX wY -> m (r wY) foldFL_M _ r NilFL = return r foldFL_M f r (x :>: xs) = f r x >>= \r' -> foldFL_M f r' xs allFL :: (forall wX wY . a wX wY -> Bool) -> FL a wW wZ -> Bool allFL f xs = and $ mapFL f xs anyFL :: (forall wX wY . a wX wY -> Bool) -> FL a wW wZ -> Bool anyFL f xs = or $ mapFL f xs allRL :: (forall wA wB . a wA wB -> Bool) -> RL a wX wY -> Bool allRL f xs = and $ mapRL f xs anyRL :: (forall wA wB . a wA wB -> Bool) -> RL a wX wY -> Bool anyRL f xs = or $ mapRL f xs foldlFL :: (forall wW wY . a -> b wW wY -> a) -> a -> FL b wX wZ -> a foldlFL _ x NilFL = x foldlFL f x (y:>:ys) = foldlFL f (f x y) ys foldlRL :: (forall wW wY . a -> b wW wY -> a) -> a -> RL b wX wZ -> a foldlRL _ x NilRL = x foldlRL f x (ys:<:y) = foldlRL f (f x y) ys mapFL_FL :: (forall wW wY . a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ mapFL_FL _ NilFL = NilFL mapFL_FL f (a:>:as) = f a :>: mapFL_FL f as mapFL_FL_M :: Monad m => (forall wW wY . a wW wY -> m (b wW wY)) -> FL a wX wZ -> m (FL b wX wZ) mapFL_FL_M _ NilFL = return NilFL mapFL_FL_M f (a:>:as) = do b <- f a bs <- mapFL_FL_M f as return (b:>:bs) sequenceFL_ :: Monad m => (forall wW wZ . a wW wZ -> m b) -> FL a wX wY -> m () sequenceFL_ f = sequence_ . mapFL f zipWithFL :: (forall wX wY . a -> p wX wY -> q wX wY) -> [a] -> FL p wW wZ -> FL q wW wZ zipWithFL f (x:xs) (y :>: ys) = f x y :>: zipWithFL f xs ys zipWithFL _ _ NilFL = NilFL zipWithFL _ [] (_:>:_) = bug "zipWithFL called with too short a list" mapRL_RL :: (forall wW wY . a wW wY -> b wW wY) -> RL a wX wZ -> RL b wX wZ mapRL_RL _ NilRL = NilRL mapRL_RL f (as:<:a) = mapRL_RL f as :<: f a mapFL :: (forall wW wZ . a wW wZ -> b) -> FL a wX wY -> [b] mapFL _ NilFL = [] mapFL f (a :>: b) = f a : mapFL f b filterFL :: (forall wX wY . a wX wY -> Bool) -> FL a wW wZ -> [Sealed2 a] filterFL _ NilFL = [] filterFL f (a :>: b) = if f a then (Sealed2 a):(filterFL f b) else filterFL f b mapRL :: (forall wW wZ . a wW wZ -> b) -> RL a wX wY -> [b] mapRL _ NilRL = [] mapRL f (as :<: a) = f a : mapRL f as lengthFL :: FL a wX wZ -> Int lengthFL xs = l xs 0 where l :: FL a wX wZ -> Int -> Int l NilFL n = n l (_:>:as) n = l as $! n+1 lengthRL :: RL a wX wZ -> Int lengthRL xs = l xs 0 where l :: RL a wX wZ -> Int -> Int l NilRL n = n l (as:<:_) n = l as $! n+1 isShorterThanRL :: RL a wX wY -> Int -> Bool isShorterThanRL _ n | n <= 0 = False isShorterThanRL NilRL _ = True isShorterThanRL (xs:<:_) n = isShorterThanRL xs (n-1) snocRLSealed :: FlippedSeal (RL a) wY -> a wY wZ -> FlippedSeal (RL a) wZ snocRLSealed (FlippedSeal as) a = flipSeal $ as :<: a toFL :: [FreeLeft a] -> Sealed (FL a wX) toFL [] = Sealed NilFL toFL (x:xs) = case unFreeLeft x of Sealed y -> case toFL xs of Sealed ys -> Sealed (y :>: ys) dropWhileFL :: (forall wX wY . a wX wY -> Bool) -> FL a wR wV -> FlippedSeal (FL a) wV dropWhileFL _ NilFL = flipSeal NilFL dropWhileFL p xs@(x:>:xs') | p x = dropWhileFL p xs' | otherwise = flipSeal xs dropWhileRL :: (forall wX wY . a wX wY -> Bool) -> RL a wR wV -> Sealed (RL a wR) dropWhileRL _ NilRL = seal NilRL dropWhileRL p xs@(xs':<:x) | p x = dropWhileRL p xs' | otherwise = seal xs -- |Check that two 'FL's are equal element by element. -- This differs from the 'Eq2' instance for 'FL' which -- uses commutation. eqFL :: Eq2 a => FL a wX wY -> FL a wX wZ -> EqCheck wY wZ eqFL NilFL NilFL = IsEq eqFL (x:>:xs) (y:>:ys) | IsEq <- x =\/= y, IsEq <- eqFL xs ys = IsEq eqFL _ _ = NotEq eqFLRev :: Eq2 a => FL a wX wZ -> FL a wY wZ -> EqCheck wX wY eqFLRev NilFL NilFL = IsEq eqFLRev (x:>:xs) (y:>:ys) | IsEq <- eqFLRev xs ys, IsEq <- x =/\= y = IsEq eqFLRev _ _ = NotEq eqFLUnsafe :: Eq2 a => FL a wX wY -> FL a wZ wW -> Bool eqFLUnsafe NilFL NilFL = True eqFLUnsafe (x:>:xs) (y:>:ys) = unsafeCompare x y && eqFLUnsafe xs ys eqFLUnsafe _ _ = False infixr 5 +>>+ infixl 5 +<<+ -- | Prepend an 'RL' to an 'FL'. This traverses only the left hand side. (+>>+) :: RL p wX wY -> FL p wY wZ -> FL p wX wZ NilRL +>>+ ys = ys (xs:<:x) +>>+ ys = xs +>>+ (x :>: ys) -- | Append an 'FL' to an 'RL'. This traverses only the right hand side. (+<<+) :: RL p wX wY -> FL p wY wZ -> RL p wX wZ xs +<<+ NilFL = xs xs +<<+ (y:>:ys) = (xs:<:y) +<<+ ys initsFL :: FL p wX wY -> [Sealed ((p :> FL p) wX)] initsFL NilFL = [] initsFL (x :>: xs) = Sealed (x :> NilFL) : map (\(Sealed (y :> xs')) -> Sealed (x :> y :>: xs')) (initsFL xs) darcs-2.14.5/src/Darcs/Patch/Witnesses/Sealed.hs0000644000000000000000000001453207346545000017474 0ustar0000000000000000-- Copyright (C) 2007 David Roundy, 2009 Ganesh Sittampalam -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE FlexibleInstances #-} {-# OPTIONS_HADDOCK ignore-exports #-} module Darcs.Patch.Witnesses.Sealed ( Sealed(..) , seal , unseal , mapSeal , unsafeUnseal , unsafeUnsealFlipped , unsafeUnseal2 , Sealed2(..) , seal2 , unseal2 , mapSeal2 , FlippedSeal(..) , flipSeal , unsealFlipped , mapFlipped , unsealM , liftSM , Gap(..) , FreeLeft , unFreeLeft , FreeRight , unFreeRight ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Witnesses.Eq ( Eq2, EqCheck(..) ) import Darcs.Patch.Witnesses.Show import Darcs.Patch.Witnesses.Eq ( (=\/=) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP1, unsafeCoerceP ) -- |A 'Sealed' type is a way of hide an existentially quantified type parameter, -- in this case wX, inside the type. Note that the only thing we can currently -- recover about the existentially quantified type wX is that it exists. data Sealed a where Sealed :: a wX -> Sealed a seal :: a wX -> Sealed a seal = Sealed instance Eq2 a => Eq (Sealed (a wX)) where Sealed x == Sealed y | IsEq <- x =\/= y = True | otherwise = False -- |The same as 'Sealed' but for two parameters (wX and wY). data Sealed2 a where Sealed2 :: !(a wX wY) -> Sealed2 a seal2 :: a wX wY -> Sealed2 a seal2 = Sealed2 data FlippedSeal a wY where FlippedSeal :: !(a wX wY) -> FlippedSeal a wY flipSeal :: a wX wY -> FlippedSeal a wY flipSeal = FlippedSeal unsafeUnseal :: Sealed a -> a wX unsafeUnseal (Sealed a) = unsafeCoerceP1 a unsafeUnsealFlipped :: FlippedSeal a wY -> a wX wY unsafeUnsealFlipped (FlippedSeal a) = unsafeCoerceP a unsafeUnseal2 :: Sealed2 a -> a wX wY unsafeUnseal2 (Sealed2 a) = unsafeCoerceP a unseal :: (forall wX . a wX -> b) -> Sealed a -> b unseal f x = f (unsafeUnseal x) -- laziness property: -- unseal (const True) undefined == True unsealM :: Monad m => m (Sealed a) -> (forall wX . a wX -> m b) -> m b unsealM m1 m2 = do sx <- m1 unseal m2 sx liftSM :: Monad m => (forall wX . a wX -> b) -> m (Sealed a) -> m b liftSM f m = do sx <- m return (unseal f sx) mapSeal :: (forall wX . a wX -> b wX) -> Sealed a -> Sealed b mapSeal f = unseal (seal . f) mapFlipped :: (forall wX . a wX wY -> b wX wZ) -> FlippedSeal a wY -> FlippedSeal b wZ mapFlipped f (FlippedSeal x) = FlippedSeal (f x) unseal2 :: (forall wX wY . a wX wY -> b) -> Sealed2 a -> b unseal2 f a = f (unsafeUnseal2 a) mapSeal2 :: (forall wX wY . a wX wY -> b wX wY) -> Sealed2 a -> Sealed2 b mapSeal2 f = unseal2 (seal2 . f) unsealFlipped :: (forall wX wY . a wX wY -> b) -> FlippedSeal a wZ -> b unsealFlipped f (FlippedSeal a) = f a instance Show1 a => Show (Sealed a) where showsPrec d (Sealed x) = showParen (d > appPrec) $ showString "Sealed " . showsPrec1 (appPrec + 1) x instance Show2 a => Show (Sealed2 a) where showsPrec d (Sealed2 x) = showParen (d > appPrec) $ showString "Sealed2 " . showsPrec2 (appPrec + 1) x -- |'Poly' is similar to 'Sealed', but the type argument is -- universally quantified instead of being existentially quantified. newtype Poly a = Poly { unPoly :: forall wX . a wX } -- |'Stepped' is a type level composition operator. -- For example, @ 'Stepped' ('Sealed' p) @ is equivalent to -- @ \\x -> 'Sealed' (p x) @ newtype Stepped (f :: (* -> *) -> *) a wX = Stepped { unStepped :: f (a wX) } -- |'FreeLeft' p is @ \forall x . \exists y . p x y @ -- In other words the caller is free to specify the left witness, -- and then the right witness is an existential. -- Note that the order of the type constructors is important for ensuring -- that @ y @ is dependent on the @ x @ that is supplied. -- This is why 'Stepped' is needed, rather than writing the more obvious -- 'Sealed' ('Poly' p) which would notionally have the same quantification -- of the type witnesses. newtype FreeLeft p = FLInternal (Poly (Stepped Sealed p)) -- |'FreeRight' p is @ \forall y . \exists x . p x y @ -- In other words the caller is free to specify the right witness, -- and then the left witness is an existential. -- Note that the order of the type constructors is important for ensuring -- that @ x @ is dependent on the @ y @ that is supplied. newtype FreeRight p = FRInternal (Poly (FlippedSeal p)) -- |Unwrap a 'FreeLeft' value unFreeLeft :: FreeLeft p -> Sealed (p wX) unFreeLeft (FLInternal x) = unStepped (unPoly x) -- |Unwrap a 'FreeRight' value unFreeRight :: FreeRight p -> FlippedSeal p wX unFreeRight (FRInternal x) = unPoly x -- |'Gap' abstracts over 'FreeLeft' and 'FreeRight' for code constructing these values class Gap w where -- |An empty 'Gap', e.g. 'NilFL' or 'NilRL' emptyGap :: (forall wX . p wX wX) -> w p -- |A 'Gap' constructed from a completely polymorphic value, for example the constructors -- for primitive patches freeGap :: (forall wX wY . p wX wY) -> w p -- |Compose two 'Gap' values together in series, e.g. 'joinGap (+>+)' or 'joinGap (:>:)' joinGap :: (forall wX wY wZ . p wX wY -> q wY wZ -> r wX wZ) -> w p -> w q -> w r instance Gap FreeLeft where emptyGap e = FLInternal (Poly (Stepped (Sealed e))) freeGap e = FLInternal (Poly (Stepped (Sealed e))) joinGap op (FLInternal p) (FLInternal q) = FLInternal (Poly (case unPoly p of Stepped (Sealed p') -> case unPoly q of Stepped (Sealed q') -> Stepped (Sealed (p' `op` q')))) instance Gap FreeRight where emptyGap e = FRInternal (Poly (FlippedSeal e)) freeGap e = FRInternal (Poly (FlippedSeal e)) joinGap op (FRInternal p) (FRInternal q) = FRInternal (Poly (case unPoly q of FlippedSeal q' -> case unPoly p of FlippedSeal p' -> FlippedSeal (p' `op` q'))) darcs-2.14.5/src/Darcs/Patch/Witnesses/Show.hs0000644000000000000000000000272407346545000017217 0ustar0000000000000000module Darcs.Patch.Witnesses.Show ( ShowDict(..) , showD , showListD , showsPrecD , Show1(..) , Show2(..) , show1 , showsPrec1 , show2 , showsPrec2 , showOp2 , appPrec ) where import Prelude () import Darcs.Prelude import Darcs.Util.Show ( appPrec ) data ShowDict a where ShowDictClass :: Show a => ShowDict a ShowDictRecord :: (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> ShowDict a showsPrecD :: ShowDict a -> Int -> a -> ShowS showsPrecD ShowDictClass = showsPrec showsPrecD (ShowDictRecord showsPrecR _ _) = showsPrecR showD :: ShowDict a -> a -> String showD ShowDictClass = show showD (ShowDictRecord _ showR _) = showR showListD :: ShowDict a -> [a] -> ShowS showListD ShowDictClass = showList showListD (ShowDictRecord _ _ showListR) = showListR class Show1 a where showDict1 :: ShowDict (a wX) showsPrec1 :: Show1 a => Int -> a wX -> ShowS showsPrec1 = showsPrecD showDict1 show1 :: Show1 a => a wX -> String show1 = showD showDict1 class Show2 a where showDict2 :: ShowDict (a wX wY) showsPrec2 :: Show2 a => Int -> a wX wY -> ShowS showsPrec2 = showsPrecD showDict2 show2 :: Show2 a => a wX wY -> String show2 = showD showDict2 showOp2 :: (Show2 a, Show2 b) => Int -> String -> Int -> a wW wX -> b wY wZ -> String -> String showOp2 prec opstr d x y = showParen (d > prec) $ showsPrec2 (prec + 1) x . showString opstr . showsPrec2 (prec + 1) y darcs-2.14.5/src/Darcs/Patch/Witnesses/Unsafe.hs0000644000000000000000000000103407346545000017511 0ustar0000000000000000module Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP , unsafeCoercePStart , unsafeCoercePEnd , unsafeCoerceP2 , unsafeCoerceP1 ) where import Unsafe.Coerce unsafeCoerceP :: a wX wY -> a wB wC unsafeCoerceP = unsafeCoerce unsafeCoercePStart :: a wX1 wY -> a wX2 wY unsafeCoercePStart = unsafeCoerce unsafeCoercePEnd :: a wX wY1 -> a wX wY2 unsafeCoercePEnd = unsafeCoerce unsafeCoerceP2 :: t wW wX wY wZ -> t wA wB wC wD unsafeCoerceP2 = unsafeCoerce unsafeCoerceP1 :: a wX -> a wY unsafeCoerceP1 = unsafeCoerce darcs-2.14.5/src/Darcs/Patch/Witnesses/WZipper.hs0000644000000000000000000000531107346545000017672 0ustar0000000000000000-- Copyright (C) 2009 Florent Becker -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Patch.Witnesses.WZipper ( FZipper(..) , focus , leftmost , left , rightmost , right , jokers , clowns , flToZipper , lengthFZ , nullFZ , toEnd , toStart ) where import Prelude () import Darcs.Prelude import Darcs.Patch.Witnesses.Ordered ( FL(..) , RL(..) , nullFL , nullRL , lengthFL , lengthRL , reverseFL , reverseRL , (+<+) , (+>+) ) import Darcs.Patch.Witnesses.Sealed(Sealed2(..), Sealed(..), FlippedSeal(..)) -- forward zipper data FZipper a wX wZ where FZipper :: RL a wX wY -> FL a wY wZ -> FZipper a wX wZ -- Constructors flToZipper :: FL a wX wY -> FZipper a wX wY flToZipper = FZipper NilRL --destructors nullFZ :: FZipper a wX wY -> Bool nullFZ (FZipper l r) = nullRL l && nullFL r lengthFZ :: FZipper a wX wY -> Int lengthFZ (FZipper l r) = lengthRL l + lengthFL r focus :: FZipper a wX wY -> Maybe (Sealed2 a) focus (FZipper _ (x :>: _)) = Just $ Sealed2 x focus _ = Nothing -- | \"Clowns to the left of me, jokers to the right. Here I am, stuck -- in the middle of you\" -- clowns :: FZipper a wX wY -> Sealed ((RL a) wX) clowns (FZipper l _) = Sealed l -- | See 'clowns' jokers :: FZipper a wX wY -> FlippedSeal (FL a) wY jokers (FZipper _ r) = FlippedSeal r rightmost :: FZipper p wX wY -> Bool rightmost (FZipper _ NilFL) = True rightmost _ = False right :: FZipper p wX wY -> FZipper p wX wY right (FZipper l (m:>:r)) = FZipper (l :<: m) r right x@(FZipper _ NilFL) = x leftmost :: FZipper p wX wY -> Bool leftmost (FZipper NilRL _) = True leftmost _ = False left :: FZipper p wX wY -> FZipper p wX wY left (FZipper (l :<: m) r) = FZipper l (m :>: r) left x@(FZipper NilRL _) = x toEnd :: FZipper p wX wY -> FZipper p wX wY toEnd (FZipper l r) = FZipper (l +<+ reverseFL r) NilFL toStart :: FZipper p wX wY -> FZipper p wX wY toStart (FZipper l r) = FZipper NilRL $ reverseRL l +>+ r darcs-2.14.5/src/Darcs/Prelude.hs0000644000000000000000000000405207346545000014650 0ustar0000000000000000-- Copyright (C) 2015 Ganesh Sittampalam -- BSD3 {- This module abstracts over the differences in the Haskell Prelude over multiple GHC versions, and also hides some symbols that are exported by the Prelude but clash with common names in the Darcs code. Broadly it exports everything that the latest Prelude supports, minus the things we explicitly exclude By default it should be imported with import Prelude () import Darcs.Prelude If necessary more things can be hidden in the 'Darcs.Prelude' import if they clash with something local, but consider whether to either hide them globally instead or to choose a different name for the local thing. If something is needed from the Prelude that's hidden by default, then add it to the Prelude import. -} {-# LANGUAGE CPP #-} module Darcs.Prelude ( module Prelude , module Control.Applicative , module Data.Monoid , Semigroup(..) , module Data.Traversable , impossible, bug ) where import Prelude hiding ( -- because it's a good name for a PatchInfo pi , -- because they're in the new Prelude but only in Control.Applicative -- in older GHCs Applicative(..), (<$>), (<*>) , -- because it's in the new Prelude but only in Data.Monoid in older GHCs Monoid(..) , #if MIN_VERSION_base(4,11,0) -- because it's in the new Prelude but only in Data.Semigroup in older GHCs Semigroup(..) , #endif -- because it's in the new Prelude but only in Data.Traversable in older GHCs traverse , -- because it's a good name for a patch log log , -- used by the options system (^) , -- used by various code for no particularly good reason lookup, pred ) import Control.Applicative ( Applicative(..), (<$>), (<*>) ) import Data.Monoid ( Monoid(..) ) import Data.Semigroup ( Semigroup(..) ) import Data.Traversable ( traverse ) impossible :: a impossible = error "Impossible case" bug :: String -> a bug str = error ("This is a bug! Please report it at http://darcs.net\n" ++ str) darcs-2.14.5/src/Darcs/Repository.hs0000644000000000000000000001120307346545000015423 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- Copyright (C) 2005 Juliusz Chroboczek -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Repository ( Repository , repoLocation , repoFormat , repoPristineType , repoCache , PristineType(..) , HashedDir(..) , Cache(..) , CacheLoc(..) , WritableOrNot(..) , RepoJob(..) , maybeIdentifyRepository , identifyRepositoryFor , withRecorded , withRepoLock , withRepoLockCanFail , withRepository , withRepositoryLocation , withUMaskFlag , writePatchSet , findRepository , amInRepository , amNotInRepository , amInHashedRepository , replacePristine , readRepo , prefsUrl , repoPatchType , addToPending , addPendingDiffToPending , tentativelyAddPatch , tentativelyRemovePatches , tentativelyAddToPending , readTentativeRepo , RebaseJobFlags(..) , withManualRebaseUpdate , tentativelyMergePatches , considerMergeToWorking , revertRepositoryChanges , finalizeRepositoryChanges , createRepository , createRepositoryV1 , createRepositoryV2 , EmptyRepository(..) , cloneRepository , unrevertUrl , applyToWorking , createPristineDirectoryTree , createPartialsPristineDirectoryTree , reorderInventory , cleanRepository , PatchSet , SealedPatchSet , PatchInfoAnd , setScriptsExecutable , setScriptsExecutablePatches , testTentative , modifyCache , reportBadSources -- * Recorded and unrecorded and pending. , readRecorded , readUnrecorded , unrecordedChanges , filterOutConflicts , readPending , readRecordedAndPending -- * Index. , readIndex , invalidateIndex ) where import Darcs.Repository.State ( readRecorded , readUnrecorded , unrecordedChanges , readPending , readIndex , invalidateIndex , readRecordedAndPending , filterOutConflicts , addPendingDiffToPending , addToPending ) import Darcs.Repository.Prefs ( prefsUrl ) import Darcs.Repository.Identify ( maybeIdentifyRepository , identifyRepositoryFor , findRepository , amInRepository , amNotInRepository , amInHashedRepository ) import Darcs.Repository.Hashed ( readRepo , readTentativeRepo , withRecorded , tentativelyAddPatch , tentativelyRemovePatches , revertRepositoryChanges , finalizeRepositoryChanges , unrevertUrl , createPristineDirectoryTree , createPartialsPristineDirectoryTree , reorderInventory , cleanRepository ) import Darcs.Repository.Pending ( tentativelyAddToPending ) import Darcs.Repository.Working ( applyToWorking , setScriptsExecutable , setScriptsExecutablePatches ) import Darcs.Repository.Job ( RepoJob(..) , withRepoLock , withRepoLockCanFail , withRepository , withRepositoryLocation , withUMaskFlag ) import Darcs.Repository.Rebase ( RebaseJobFlags(..), withManualRebaseUpdate ) import Darcs.Repository.Test ( testTentative ) import Darcs.Repository.Merge( tentativelyMergePatches , considerMergeToWorking ) import Darcs.Repository.Cache ( HashedDir(..) , Cache(..) , CacheLoc(..) , WritableOrNot(..) , reportBadSources ) import Darcs.Repository.InternalTypes ( Repository , PristineType(..) , modifyCache , repoPatchType , repoLocation , repoFormat , repoPristineType , repoCache ) import Darcs.Repository.Clone ( cloneRepository , replacePristine , writePatchSet ) import Darcs.Repository.Create ( createRepository , createRepositoryV1 , createRepositoryV2 , EmptyRepository(..) ) import Darcs.Patch.Set ( PatchSet(..), SealedPatchSet ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd ) darcs-2.14.5/src/Darcs/Repository/0000755000000000000000000000000007346545000015072 5ustar0000000000000000darcs-2.14.5/src/Darcs/Repository/ApplyPatches.hs0000644000000000000000000001734707346545000020037 0ustar0000000000000000-- Copyright (C) 2002-2005,2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# OPTIONS_GHC -fno-warn-missing-methods #-} {-# LANGUAGE MultiParamTypeClasses, GeneralizedNewtypeDeriving #-} module Darcs.Repository.ApplyPatches ( applyPatches , runTolerantly , runSilently , DefaultIO, runDefault ) where import Prelude hiding ( Applicative ) import Control.Exception ( catch, SomeException, IOException ) import Data.Char ( toLower ) import Data.List ( isSuffixOf ) import System.IO ( stderr ) import System.IO.Error ( isDoesNotExistError, isPermissionError ) import Control.Monad ( unless, mplus ) import Control.Applicative (Applicative) import System.Directory ( createDirectory, removeDirectory, removeFile, renameFile, renameDirectory, doesDirectoryExist, doesFileExist ) import Darcs.Patch.ApplyMonad( ApplyMonad(..), ApplyMonadTree(..) ) import Darcs.Patch.ApplyPatches ( applyPatches ) import Darcs.Patch.MonadProgress ( MonadProgress(..), ProgressAction(..) ) import Darcs.Repository.Prefs( changePrefval ) import Darcs.Util.Lock ( writeAtomicFilePS ) import Darcs.Util.Exception ( prettyException ) import Darcs.Util.Progress ( beginTedious, endTedious, tediousSize, finishedOneIO ) import Darcs.Util.Printer ( hPutDocLn ) import Darcs.Util.Printer.Color ( showDoc ) import Darcs.Util.External ( backupByCopying, backupByRenaming ) import Darcs.Util.Path ( FileName, fn2fp ) import qualified Data.ByteString as B (empty, null, readFile) import Darcs.Util.Tree( Tree ) newtype DefaultIO a = DefaultIO { runDefaultIO :: IO a } deriving (Functor, Applicative, Monad) instance MonadProgress DefaultIO where runProgressActions _ [] = return () runProgressActions what items = DefaultIO $ do do beginTedious what tediousSize what (length items) mapM_ go items endTedious what where go item = do finishedOneIO what (showDoc $ paMessage item) runDefaultIO (paAction item) `catch` \e -> do hPutDocLn stderr $ paOnError item ioError e instance ApplyMonad Tree DefaultIO where type ApplyMonadBase DefaultIO = IO instance ApplyMonadTree DefaultIO where mDoesDirectoryExist = DefaultIO . doesDirectoryExist . fn2fp mChangePref a b c = DefaultIO $ changePrefval a b c mModifyFilePS f j = DefaultIO $ B.readFile (fn2fp f) >>= runDefaultIO . j >>= writeAtomicFilePS (fn2fp f) mCreateDirectory = DefaultIO . createDirectory . fn2fp mCreateFile f = DefaultIO $ do exf <- doesFileExist (fn2fp f) if exf then fail $ "File '"++fn2fp f++"' already exists!" else do exd <- doesDirectoryExist $ fn2fp f if exd then fail $ "File '"++fn2fp f++"' already exists!" else writeAtomicFilePS (fn2fp f) B.empty mRemoveFile f = DefaultIO $ do let fp = fn2fp f x <- B.readFile fp unless (B.null x) $ fail $ "Cannot remove non-empty file "++fp removeFile fp mRemoveDirectory = DefaultIO . removeDirectory . fn2fp mRename a b = DefaultIO $ catch (renameDirectory x y `mplus` renameFile x y) -- We need to catch does not exist errors, since older -- versions of darcs allowed users to rename nonexistent -- files. :( (\e -> unless (isDoesNotExistError e) $ ioError e) where x = fn2fp a y = fn2fp b class (Functor m, Monad m) => TolerantMonad m where warning :: IO () -> m () runIO :: m a -> IO a runTM :: IO a -> m a newtype TolerantIO a = TIO { runTIO :: IO a } deriving (Functor, Applicative, Monad) instance TolerantMonad TolerantIO where warning io = TIO $ io `catch` \e -> putStrLn $ "Warning: " ++ prettyException e runIO (TIO io) = io runTM = TIO newtype SilentIO a = SIO { runSIO :: IO a } deriving (Functor, Applicative, Monad) instance TolerantMonad SilentIO where warning io = SIO $ io `catch` \(_ :: SomeException) -> return () runIO (SIO io) = io runTM = SIO newtype TolerantWrapper m a = TolerantWrapper { runTolerantWrapper :: m a } deriving (Functor, Applicative, Monad, TolerantMonad) -- | Apply patches, emitting warnings if there are any IO errors runTolerantly :: TolerantWrapper TolerantIO a -> IO a runTolerantly = runTIO . runTolerantWrapper -- | Apply patches, ignoring all errors runSilently :: TolerantWrapper SilentIO a -> IO a runSilently = runSIO . runTolerantWrapper -- | The default mode of applying patches: fail if the directory is not -- as we expect runDefault :: DefaultIO a -> IO a runDefault = runDefaultIO instance TolerantMonad m => ApplyMonad Tree (TolerantWrapper m) where type ApplyMonadBase (TolerantWrapper m) = IO instance TolerantMonad m => ApplyMonadTree (TolerantWrapper m) where mDoesDirectoryExist d = runTM $ runDefaultIO $ mDoesDirectoryExist d mReadFilePS f = runTM $ runDefaultIO $ mReadFilePS f mChangePref a b c = warning $ runDefaultIO $ mChangePref a b c mModifyFilePS f j = warning $ runDefaultIO $ mModifyFilePS f (DefaultIO . runIO . j) mCreateFile f = warning $ backup f >> runDefaultIO (mCreateFile f) mCreateDirectory d = warning $ backup d >> runDefaultIO (mCreateDirectory d) mRemoveFile f = warning $ runDefaultIO (mRemoveFile f) mRemoveDirectory d = warning $ catch (runDefaultIO (mRemoveDirectory d)) (\(e :: IOException) -> if "(Directory not empty)" `isSuffixOf` show e then ioError $ userError $ "Not deleting " ++ fn2fp d ++ " because it is not empty." else ioError $ userError $ "Not deleting " ++ fn2fp d ++ " because:\n" ++ show e) mRename a b = warning $ catch (let do_backup = if map toLower x == map toLower y then backupByCopying (fn2fp b) -- avoid making the original vanish else backupByRenaming (fn2fp b) in do_backup >> runDefaultIO (mRename a b)) (\e -> case () of _ | isPermissionError e -> ioError $ userError $ couldNotRename ++ "." | isDoesNotExistError e -> ioError $ userError $ couldNotRename ++ " because " ++ x ++ " does not exist." | otherwise -> ioError e ) where x = fn2fp a y = fn2fp b couldNotRename = "Could not rename " ++ x ++ " to " ++ y backup :: FileName -> IO () backup f = backupByRenaming (fn2fp f) darcs-2.14.5/src/Darcs/Repository/Cache.hs0000644000000000000000000005510407346545000016436 0ustar0000000000000000module Darcs.Repository.Cache ( cacheHash , okayHash , Cache(..) , CacheType(..) , CacheLoc(..) , WritableOrNot(..) , HashedDir(..) , hashedDir , bucketFolder , unionCaches , unionRemoteCaches , cleanCaches , cleanCachesWithHint , fetchFileUsingCache , speculateFileUsingCache , speculateFilesUsingCache , writeFileUsingCache , peekInCache , repo2cache , writable , isThisRepo , hashedFilePath , allHashedDirs , compareByLocality , reportBadSources ) where import Control.Monad ( liftM, when, unless, filterM, forM_, mplus ) import qualified Data.ByteString as B (length, ByteString ) import Data.List ( nub, intercalate ) import Data.Maybe ( catMaybes, fromMaybe ) import System.FilePath.Posix ( (), joinPath, dropFileName ) import System.Directory ( createDirectoryIfMissing, removeFile, doesFileExist, doesDirectoryExist, getDirectoryContents, getPermissions ) import qualified System.Directory as SD ( writable ) import System.IO ( hPutStrLn, stderr ) import System.Posix.Files ( createLink, linkCount, getSymbolicLinkStatus ) import Darcs.Util.ByteString ( gzWriteFilePS ) import Darcs.Util.Global ( darcsdir, addBadSource, isBadSource, addReachableSource, isReachableSource, getBadSourcesList, defaultRemoteDarcsCmd ) import Darcs.Util.External ( gzFetchFilePS, fetchFilePS , speculateFileOrUrl, copyFileOrUrl , Cachable( Cachable ) ) import Darcs.Repository.Flags ( Compression(..) ) import Darcs.Util.Lock ( writeAtomicFilePS, gzWriteAtomicFilePS, withTemp ) import Darcs.Util.SignalHandler ( catchNonSignal ) import Darcs.Util.URL ( isValidLocalPath, isHttpUrl, isSshUrl ) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Hash ( sha256sum ) import Darcs.Util.English ( englishNum, Noun(..), Pronoun(..) ) import Darcs.Util.Exception ( catchall ) import Darcs.Util.Progress ( progressList, debugMessage, debugFail ) import qualified Darcs.Util.Download as Download ( ConnectionError(..) ) data HashedDir = HashedPristineDir | HashedPatchesDir | HashedInventoriesDir hashedDir :: HashedDir -> String hashedDir HashedPristineDir = "pristine.hashed" hashedDir HashedPatchesDir = "patches" hashedDir HashedInventoriesDir = "inventories" allHashedDirs :: [HashedDir] allHashedDirs = [ HashedPristineDir , HashedPatchesDir , HashedInventoriesDir ] data WritableOrNot = Writable | NotWritable deriving ( Eq, Show ) data CacheType = Repo | Directory deriving ( Eq, Show ) data CacheLoc = Cache { cacheType :: !CacheType , cacheWritable :: !WritableOrNot , cacheSource :: !String } -- | Cache is an abstract type for hiding the underlying cache locations newtype Cache = Ca [CacheLoc] instance Eq CacheLoc where (Cache aTy _ aSrc) == (Cache bTy _ bSrc) = aTy == bTy && aSrc == bSrc instance Show CacheLoc where show (Cache Repo Writable a) = "thisrepo:" ++ a show (Cache Repo NotWritable a) = "repo:" ++ a show (Cache Directory Writable a) = "cache:" ++ a show (Cache Directory NotWritable a) = "readonly:" ++ a instance Show Cache where show (Ca cs) = unlines $ map show cs unionCaches :: Cache -> Cache -> Cache unionCaches (Ca a) (Ca b) = Ca (nub (a ++ b)) -- | unionRemoteCaches merges caches. It tries to do better than just blindly -- copying remote cache entries: -- -- * If remote repository is accessed through network, do not copy any cache -- entries from it. Taking local entries does not make sense and using -- network entries can lead to darcs hang when it tries to get to -- unaccessible host. -- -- * If remote repositoty is local, copy all network cache entries. For local -- cache entries if the cache directory exists and is writable it is added -- as writable cache, if it exists but is not writable it is added as -- read-only cache. -- -- This approach should save us from bogus cache entries. One case it does -- not work very well is when you fetch from partial repository over network. -- Hopefully this is not a common case. unionRemoteCaches :: Cache -> Cache -> String -> IO Cache unionRemoteCaches local (Ca remote) repourl | isValidLocalPath repourl = do f <- filtered return $ local `unionCaches` Ca f | otherwise = return local where filtered = catMaybes `fmap` mapM (\x -> mbGetRemoteCacheLoc x `catchall` return Nothing) remote mbGetRemoteCacheLoc :: CacheLoc -> IO (Maybe CacheLoc) mbGetRemoteCacheLoc (Cache Repo Writable _) = return Nothing mbGetRemoteCacheLoc c@(Cache t _ url) | isValidLocalPath url = do ex <- doesDirectoryExist url if ex then do p <- getPermissions url return $ Just $ if writable c && SD.writable p then c else Cache t NotWritable url else return Nothing | otherwise = return $ Just c -- | Compares two caches, a remote cache is greater than a local one. -- The order of the comparison is given by: local < http < ssh compareByLocality :: CacheLoc -> CacheLoc -> Ordering compareByLocality (Cache _ w x) (Cache _ z y) | isValidLocalPath x && isRemote y = LT | isRemote x && isValidLocalPath y = GT | isHttpUrl x && isSshUrl y = LT | isSshUrl x && isHttpUrl y = GT | isValidLocalPath x && isWritable w && isValidLocalPath y && isNotWritable z = LT | otherwise = EQ where isRemote r = isHttpUrl r || isSshUrl r isWritable = (==) Writable isNotWritable = (==) NotWritable repo2cache :: String -> Cache repo2cache r = Ca [Cache Repo NotWritable r] -- | 'cacheHash' computes the cache hash (i.e. filename) of a packed string. cacheHash :: B.ByteString -> String cacheHash ps = if sizeStrLen > 10 then shaOfPs else replicate (10 - sizeStrLen) '0' ++ sizeStr ++ '-' : shaOfPs where sizeStr = show $ B.length ps sizeStrLen = length sizeStr shaOfPs = sha256sum ps okayHash :: String -> Bool okayHash s = length s `elem` [64, 75] checkHash :: String -> B.ByteString -> Bool checkHash h s | length h == 64 = sha256sum s == h | length h == 75 = B.length s == read (take 10 h) && sha256sum s == drop 11 h | otherwise = False -- |@fetchFileUsingCache cache dir hash@ receives a list of caches @cache@, the -- directory for which that file belongs @dir@ and the @hash@ of the file to -- fetch. It tries to fetch the file from one of the sources, trying them in -- order one by one. If the file cannot be fetched from any of the sources, -- this operation fails. fetchFileUsingCache :: Cache -> HashedDir -> String -> IO (String, B.ByteString) fetchFileUsingCache = fetchFileUsingCachePrivate Anywhere writable :: CacheLoc -> Bool writable (Cache _ NotWritable _) = False writable (Cache _ Writable _) = True isThisRepo :: CacheLoc -> Bool isThisRepo (Cache Repo Writable _) = True isThisRepo _ = False bucketFolder :: String -> String bucketFolder f = take 2 (cleanHash f) where cleanHash fileName = case dropWhile (/= '-') fileName of [] -> fileName s -> drop 1 s -- | @hashedFilePath cachelocation subdir hash@ returns the physical filename -- of hash @hash@ in the @subdir@ section of @cachelocation@. hashedFilePath :: CacheLoc -> HashedDir -> String -> String hashedFilePath (Cache Directory _ d) s f = joinPath [d, hashedDir s, bucketFolder f, f] hashedFilePath (Cache Repo _ r) s f = joinPath [r, darcsdir, hashedDir s, f] -- | @hashedFilePathReadOnly cachelocation subdir hash@ returns the physical filename -- of hash @hash@ in the @subdir@ section of @cachelocation@. -- If directory, assume it is non-bucketed cache (old cache location). hashedFilePathReadOnly :: CacheLoc -> HashedDir -> String -> String hashedFilePathReadOnly (Cache Directory _ d) s f = d ++ "/" ++ hashedDir s ++ "/" ++ f hashedFilePathReadOnly (Cache Repo _ r) s f = r ++ "/" ++ darcsdir ++ "/" ++ hashedDir s ++ "/" ++ f -- | @peekInCache cache subdir hash@ tells whether @cache@ and contains an -- object with hash @hash@ in a writable position. Florent: why do we want it -- to be in a writable position? peekInCache :: Cache -> HashedDir -> String -> IO Bool peekInCache (Ca cache) subdir f = cacheHasIt cache `catchall` return False where cacheHasIt [] = return False cacheHasIt (c : cs) | not $ writable c = cacheHasIt cs | otherwise = do ex <- doesFileExist $ hashedFilePath c subdir f if ex then return True else cacheHasIt cs -- | @speculateFileUsingCache cache subdirectory name@ takes note that the file -- @name@ is likely to be useful soon: pipelined downloads will add it to the -- (low-priority) queue, for the rest it is a noop. speculateFileUsingCache :: Cache -> HashedDir -> String -> IO () speculateFileUsingCache c sd h = do debugMessage $ "Speculating on " ++ h copyFileUsingCache OnlySpeculate c sd h -- | Note that the files are likely to be useful soon: pipelined downloads will -- add them to the (low-priority) queue, for the rest it is a noop. speculateFilesUsingCache :: Cache -> HashedDir -> [String] -> IO () speculateFilesUsingCache _ _ [] = return () speculateFilesUsingCache cache sd hs = do debugMessage $ "Thinking about speculating on " ++ unwords hs hs' <- filterM (fmap not . peekInCache cache sd) hs unless (null hs') $ do debugMessage $ "Speculating on " ++ unwords hs' copyFilesUsingCache OnlySpeculate cache sd hs' data OrOnlySpeculate = ActuallyCopy | OnlySpeculate deriving ( Eq ) -- | We hace a list of locations (@cache@) ordered from "closest/fastest" -- (typically, the destination repo) to "farthest/slowest" (typically, -- the source repo). -- @copyFileUsingCache@ first checks whether given file @f@ is present -- in some writeable location, if yes, do nothing. If no, it copies it -- to the last writeable location, which would be the global cache -- by default, or the destination repo if `--no-cache` is passed. -- Function does nothing if there is no writeable location at all. -- If the copy should occur between two locations of the same filesystem, -- a hard link is actually made. -- TODO document @oos@: what happens when we only speculate? copyFileUsingCache :: OrOnlySpeculate -> Cache -> HashedDir -> String -> IO () copyFileUsingCache oos (Ca cache) subdir f = do debugMessage $ "I'm doing copyFileUsingCache on " ++ hashedDir subdir ++ "/" ++ f Just stickItHere <- cacheLoc cache createDirectoryIfMissing True (reverse $ dropWhile (/= '/') $ reverse stickItHere) debugMessage $ "Will effectively do copyFileUsingCache to: " ++ show stickItHere filterBadSources cache >>= sfuc stickItHere `catchall` return () where -- return last writeable cache/repo location for file. -- usually returns the global cache unless `--no-cache` is passed. cacheLoc [] = return Nothing cacheLoc (c : cs) | not $ writable c = cacheLoc cs | otherwise = do let attemptPath = hashedFilePath c subdir f ex <- doesFileExist attemptPath if ex then fail $ "File already present in writable location." else do othercache <- cacheLoc cs return $ othercache `mplus` Just attemptPath -- do the actual copy, or hard link, or put file in download queue sfuc _ [] = return () sfuc out (c : cs) | not (writable c) = let cacheFile = hashedFilePathReadOnly c subdir f in if oos == OnlySpeculate then speculateFileOrUrl cacheFile out `catchNonSignal` \e -> checkCacheReachability (show e) c else do debugMessage $ "Copying from " ++ show cacheFile ++ " to " ++ show out copyFileOrUrl defaultRemoteDarcsCmd cacheFile out Cachable `catchNonSignal` (\e -> do checkCacheReachability (show e) c sfuc out cs) -- try another read-only location | otherwise = sfuc out cs copyFilesUsingCache :: OrOnlySpeculate -> Cache -> HashedDir -> [String] -> IO () copyFilesUsingCache oos cache subdir hs = forM_ hs $ copyFileUsingCache oos cache subdir data FromWhere = LocalOnly | Anywhere deriving ( Eq ) -- | Checks if a given cache entry is reachable or not. It receives an error -- caught during execution and the cache entry. If the caches is not reachable -- it is blacklisted and not longer tried for the rest of the session. If it is -- reachable it is whitelisted and future errors with such cache get ignore. -- To determine reachability: -- * For a local cache, if the given source doesn't exist anymore, it is -- blacklisted. -- * For remote sources if the error is timeout, it is blacklisted, if not, -- it checks if _darcs/hashed_inventory exist, if it does, the entry is -- whitelisted, if it doesn't, it is blacklisted. checkCacheReachability :: String -> CacheLoc -> IO () checkCacheReachability e cache | isValidLocalPath source = doUnreachableCheck $ checkFileReachability (doesDirectoryExist source) | isHttpUrl source = doUnreachableCheck $ do let err = case dropWhile (/= '(') e of (_ : xs) -> fst (break (==')') xs) _ -> e case reads err :: [(Download.ConnectionError, String)] of [(_, _)] -> addBadSource source _ -> checkFileReachability (checkHashedInventoryReachability cache) | isSshUrl source = doUnreachableCheck $ checkFileReachability (checkHashedInventoryReachability cache) | otherwise = fail $ "unknown transport protocol for: " ++ source where source = cacheSource cache doUnreachableCheck unreachableAction = do reachable <- isReachableSource unless (reachable source) unreachableAction checkFileReachability doCheck = do reachable <- doCheck if reachable then addReachableSource source else addBadSource source -- | Returns a list of reachables cache entries, removing blacklisted entries. filterBadSources :: [CacheLoc] -> IO [CacheLoc] filterBadSources cache = do badSource <- isBadSource return $ filter (not . badSource . cacheSource) cache -- | Checks if the _darcs/hashed_inventory exist and is reachable checkHashedInventoryReachability :: CacheLoc -> IO Bool checkHashedInventoryReachability cache = withTemp $ \tempout -> do let f = cacheSource cache darcsdir "hashed_inventory" copyFileOrUrl defaultRemoteDarcsCmd f tempout Cachable return True `catchNonSignal` const (return False) -- | Get contents of some hashed file taking advantage of the cache system. -- We hace a list of locations (@cache@) ordered from "closest/fastest" -- (typically, the destination repo) to "farthest/slowest" (typically, -- the source repo). -- First, if possible it copies the file from remote location to local. -- Then, it reads it contents, and links the file across all writeable -- locations including the destination repository. fetchFileUsingCachePrivate :: FromWhere -> Cache -> HashedDir -> String -> IO (String, B.ByteString) fetchFileUsingCachePrivate fromWhere (Ca cache) subdir f = do when (fromWhere == Anywhere) $ copyFileUsingCache ActuallyCopy (Ca cache) subdir f filterBadSources cache >>= ffuc `catchall` debugFail ("Couldn't fetch `" ++ f ++ "'\nin subdir " ++ hashedDir subdir ++ " from sources:\n\n" ++ show (Ca cache)) where ffuc (c : cs) | not (writable c) && (Anywhere == fromWhere || isValidLocalPath (hashedFilePathReadOnly c subdir f)) = do let cacheFile = hashedFilePathReadOnly c subdir f -- looks like `copyFileUsingCache` could not copy the file we wanted. -- this can happen if `--no-cache` is NOT passed and the global cache is not accessible debugMessage $ "In fetchFileUsingCachePrivate I'm directly grabbing file contents from " ++ cacheFile x <- gzFetchFilePS cacheFile Cachable if not $ checkHash f x then do x' <- fetchFilePS cacheFile Cachable unless (checkHash f x') $ do hPutStrLn stderr $ "Hash failure in " ++ cacheFile fail $ "Hash failure in " ++ cacheFile return (cacheFile, x') else return (cacheFile, x) -- FIXME: create links in caches `catchNonSignal` \e -> do -- something bad happened, check if cache became unaccessible and try other ones checkCacheReachability (show e) c filterBadSources cs >>= ffuc | writable c = let cacheFile = hashedFilePath c subdir f in do debugMessage $ "About to gzFetchFilePS from " ++ show cacheFile x1 <- gzFetchFilePS cacheFile Cachable debugMessage $ "gzFetchFilePS done." x <- if not $ checkHash f x1 then do x2 <- fetchFilePS cacheFile Cachable unless (checkHash f x2) $ do hPutStrLn stderr $ "Hash failure in " ++ cacheFile removeFile cacheFile fail $ "Hash failure in " ++ cacheFile return x2 else return x1 mapM_ (tryLinking cacheFile) cs return (cacheFile, x) `catchNonSignal` \e -> do debugMessage "Caught exception, now attempt creating cache." createCache c subdir `catchall` return () checkCacheReachability (show e) c (fname, x) <- filterBadSources cs >>= ffuc -- fetch file from remaining locations debugMessage $ "Attempt creating link from: " ++ show fname ++ " to " ++ show cacheFile (createLink fname cacheFile >> (debugMessage "successfully created link") >> return (cacheFile, x)) `catchall` do debugMessage $ "Attempt writing file: " ++ show cacheFile -- the following block is usually when files get actually written -- inside of _darcs or global cache. do createDirectoryIfMissing True (dropFileName cacheFile) gzWriteFilePS cacheFile x debugMessage $ "successfully wrote file" `catchall` return () -- above block can fail if cache is not writeable return (fname, x) | otherwise = ffuc cs ffuc [] = debugFail $ "No sources from which to fetch file `" ++ f ++ "'\n"++ show (Ca cache) tryLinking ff c@(Cache Directory Writable d) = do createDirectoryIfMissing False (d ++ "/" ++ hashedDir subdir) createLink ff (hashedFilePath c subdir f) `catchall` return () tryLinking _ _ = return () createCache :: CacheLoc -> HashedDir -> IO () createCache (Cache Directory _ d) subdir = createDirectoryIfMissing True (d ++ "/" ++ hashedDir subdir) createCache _ _ = return () -- | @write compression filename content@ writes @content@ to the file -- @filename@ according to the policy given by @compression@. write :: Compression -> String -> B.ByteString -> IO () write NoCompression = writeAtomicFilePS write GzipCompression = gzWriteAtomicFilePS -- | @writeFileUsingCache cache compression subdir contents@ write the string -- @contents@ to the directory subdir, except if it is already in the cache, in -- which case it is a noop. Warning (?) this means that in case of a hash -- collision, writing using writeFileUsingCache is a noop. The returned value -- is the filename that was given to the string. writeFileUsingCache :: Cache -> Compression -> HashedDir -> B.ByteString -> IO String writeFileUsingCache (Ca cache) compr subdir ps = do _ <- fetchFileUsingCachePrivate LocalOnly (Ca cache) subdir hash return hash `catchall` wfuc cache `catchall` debugFail ("Couldn't write `" ++ hash ++ "'\nin subdir " ++ hashedDir subdir ++ " to sources:\n\n"++ show (Ca cache)) where hash = cacheHash ps wfuc (c : cs) | not $ writable c = wfuc cs | otherwise = do createCache c subdir -- FIXME: create links in caches write compr (hashedFilePath c subdir hash) ps return hash wfuc [] = debugFail $ "No location to write file `" ++ hashedDir subdir ++ "/" ++ hash ++ "'" cleanCaches :: Cache -> HashedDir -> IO () cleanCaches c d = cleanCachesWithHint' c d Nothing cleanCachesWithHint :: Cache -> HashedDir -> [String] -> IO () cleanCachesWithHint c d h = cleanCachesWithHint' c d (Just h) cleanCachesWithHint' :: Cache -> HashedDir -> Maybe [String] -> IO () cleanCachesWithHint' (Ca cs) subdir hint = mapM_ cleanCache cs where cleanCache (Cache Directory Writable d) = withCurrentDirectory (d ++ "/" ++ hashedDir subdir) (do fs' <- getDirectoryContents "." let fs = filter okayHash $ fromMaybe fs' hint cleanMsg = "Cleaning cache " ++ d ++ "/" ++ hashedDir subdir mapM_ clean $ progressList cleanMsg fs) `catchall` return () cleanCache _ = return () clean f = do lc <- linkCount `liftM` getSymbolicLinkStatus f when (lc < 2) $ removeFile f `catchall` return () -- | Prints an error message with a list of bad caches. reportBadSources :: IO () reportBadSources = do sources <- getBadSourcesList let size = length sources unless (null sources) $ hPutStrLn stderr $ concat [ "\nHINT: I could not reach the following " , englishNum size (Noun "repository") ":" , "\n" , intercalate "\n" (map (" " ++) sources) , "\n If you're not using " , englishNum size It ", you should probably delete" , "\n the corresponding " , englishNum size (Noun "entry") " from _darcs/prefs/sources." ] darcs-2.14.5/src/Darcs/Repository/Clone.hs0000644000000000000000000004431107346545000016471 0ustar0000000000000000module Darcs.Repository.Clone ( cloneRepository , replacePristine , writePatchSet ) where import Prelude () import Darcs.Prelude import Control.Exception ( catch, SomeException ) import Control.Monad ( when ) import qualified Data.ByteString.Char8 as BC import Data.List( intercalate ) import Data.Maybe( catMaybes ) import System.FilePath( () ) import System.Directory ( removeFile , getDirectoryContents ) import System.IO ( stderr ) import Darcs.Repository.Create ( EmptyRepository(..) , createRepository , writePristine ) import Darcs.Repository.State ( invalidateIndex ) import Darcs.Repository.Pending ( tentativelyAddToPending ) import Darcs.Repository.Identify ( IdentifyRepo(..) , identifyRepositoryFor , maybeIdentifyRepository ) import Darcs.Repository.Hashed ( readRepo , tentativelyRemovePatches , finalizeRepositoryChanges , createPristineDirectoryTree , revertRepositoryChanges ) import Darcs.Repository.Working ( setScriptsExecutable , setScriptsExecutablePatches ) import Darcs.Repository.InternalTypes ( Repository , repoLocation , repoFormat , repoCache , modifyCache , repoPatchType ) import Darcs.Repository.Job ( withUMaskFlag ) import Darcs.Repository.Cache ( unionRemoteCaches , unionCaches , fetchFileUsingCache , speculateFileUsingCache , HashedDir(..) , Cache(..) , CacheLoc(..) , repo2cache ) import qualified Darcs.Repository.Cache as DarcsCache import qualified Darcs.Repository.Hashed as HashedRepo import Darcs.Repository.ApplyPatches ( runDefault ) import Darcs.Repository.Hashed ( applyToTentativePristineCwd , peekPristineHash ) import Darcs.Repository.Format ( RepoProperty ( HashedInventory, Darcs2 ) , RepoFormat , formatHas , readProblem ) import Darcs.Repository.Prefs ( addRepoSource, deleteSources ) import Darcs.Repository.Match ( getOnePatchset ) import Darcs.Util.External ( copyFileOrUrl , Cachable(..) , gzFetchFilePS ) import Darcs.Repository.PatchIndex ( doesPatchIndexExist , createPIWithInterrupt ) import Darcs.Repository.Packs ( fetchAndUnpackBasic , fetchAndUnpackPatches , packsDir ) import Darcs.Util.Lock ( appendTextFile, withNewDirectory ) import Darcs.Repository.Flags ( UpdateWorking(..) , UseCache(..) , RemoteDarcs (..) , remoteDarcs , Compression (..) , CloneKind (..) , Verbosity (..) , DryRun (..) , UMask (..) , SetScriptsExecutable (..) , RemoteRepos (..) , SetDefault (..) , WithWorkingDir (..) , ForgetParent (..) , WithPatchIndex (..) , PatchFormat (..) ) import Darcs.Patch ( RepoPatch, IsRepoType, apply, invert, effect ) import Darcs.Patch.Depends ( findCommonWithThem, countUsThem ) import Darcs.Patch.Set ( Origin , PatchSet , patchSet2RL , patchSet2FL , progressPatchSet ) import Darcs.Patch.Match ( MatchFlag(..), havePatchsetMatch ) import Darcs.Patch.Progress ( progressRLShowTags, progressFL ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..) ) import Darcs.Patch.Witnesses.Ordered ( (:>)(..) , lengthFL , mapFL_FL , RL(..) , bunchFL , mapFL , mapRL , lengthRL ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, extractHash, hopefully ) import Darcs.Util.Tree( Tree, emptyTree ) import Darcs.Util.Download ( maxPipelineLength ) import Darcs.Util.Exception ( catchall ) import Darcs.Util.English ( englishNum, Noun(..) ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.URL ( isValidLocalPath ) import Darcs.Util.SignalHandler ( catchInterrupt ) import Darcs.Util.Printer ( Doc, text, hPutDocLn, putDocLn, errorDoc ) import Darcs.Util.Progress ( debugMessage , tediousSize , beginTedious , endTedious ) joinUrl :: [String] -> String joinUrl = intercalate "/" cloneRepository :: String -- origin repository path -> String -- new repository name (for relative path) -> Verbosity -> UseCache -> CloneKind -> UMask -> RemoteDarcs -> SetScriptsExecutable -> RemoteRepos -> SetDefault -> [MatchFlag] -> RepoFormat -> WithWorkingDir -> WithPatchIndex -- use patch index -> Bool -- use packs -> ForgetParent -> IO () cloneRepository repodir mysimplename v useCache cloneKind um rdarcs sse remoteRepos setDefault matchFlags rfsource withWorkingDir usePatchIndex usePacks forget = withUMaskFlag um $ withNewDirectory mysimplename $ do let patchfmt = if formatHas Darcs2 rfsource then PatchFormat2 else PatchFormat1 EmptyRepository toRepo' <- createRepository patchfmt withWorkingDir (if cloneKind == LazyClone then NoPatchIndex else usePatchIndex) useCache debugMessage "Finished initializing new repository." addRepoSource repodir NoDryRun remoteRepos setDefault debugMessage "Identifying and copying repository..." fromRepo <- identifyRepositoryFor toRepo' useCache repodir let fromLoc = repoLocation fromRepo let rffrom = repoFormat fromRepo case readProblem rffrom of Just e -> fail $ "Incompatibility with repository " ++ fromLoc ++ ":\n" ++ e Nothing -> return () debugMessage "Copying prefs..." copyFileOrUrl (remoteDarcs rdarcs) (joinUrl [fromLoc, darcsdir, "prefs", "prefs"]) (darcsdir "prefs/prefs") (MaxAge 600) `catchall` return () debugMessage "Copying sources..." cache <- unionRemoteCaches (repoCache toRepo') (repoCache fromRepo) fromLoc appendTextFile (darcsdir "prefs/sources") (show $ repo2cache fromLoc `unionCaches` dropNonRepos cache) debugMessage "Done copying and filtering sources." -- put remote source last let toRepo = modifyCache toRepo' (const $ cache `unionCaches` repo2cache fromLoc) if formatHas HashedInventory rffrom then do -- copying basic repository (hashed_inventory and pristine) if usePacks && (not . isValidLocalPath) fromLoc then copyBasicRepoPacked fromRepo toRepo v rdarcs withWorkingDir else copyBasicRepoNotPacked fromRepo toRepo v rdarcs withWorkingDir when (cloneKind /= LazyClone) $ do when (cloneKind /= CompleteClone) $ putInfo v $ text "Copying patches, to get lazy repository hit ctrl-C..." -- copying complete repository (inventories and patches) if usePacks && (not . isValidLocalPath) fromLoc then copyCompleteRepoPacked fromRepo toRepo v cloneKind else copyCompleteRepoNotPacked fromRepo toRepo v cloneKind else -- old-fashioned repositories are cloned diferently since -- we need to copy all patches first and then build pristine copyRepoOldFashioned fromRepo toRepo v withWorkingDir when (sse == YesSetScriptsExecutable) setScriptsExecutable when (havePatchsetMatch (repoPatchType toRepo) matchFlags) $ do putInfo v $ text "Going to specified version..." -- the following is necessary to be able to read repo's patches revertRepositoryChanges toRepo YesUpdateWorking patches <- readRepo toRepo Sealed context <- getOnePatchset toRepo matchFlags when (snd (countUsThem patches context) > 0) $ errorDoc $ text "Missing patches from context!" -- FIXME : - ( _ :> us' <- return $ findCommonWithThem patches context let ps = mapFL_FL hopefully us' putInfo v $ text $ "Unapplying " ++ show (lengthFL ps) ++ " " ++ englishNum (lengthFL ps) (Noun "patch") "" invalidateIndex toRepo _ <- tentativelyRemovePatches toRepo GzipCompression YesUpdateWorking us' tentativelyAddToPending toRepo YesUpdateWorking $ invert $ effect us' finalizeRepositoryChanges toRepo YesUpdateWorking GzipCompression runDefault (apply (invert $ effect ps)) `catch` \(e :: SomeException) -> fail ("Couldn't undo patch in working dir.\n" ++ show e) when (sse == YesSetScriptsExecutable) $ setScriptsExecutablePatches (invert $ effect ps) when (forget == YesForgetParent) deleteSources -- | This keeps only NonWritable Repo entries. dropNonRepos :: Cache -> Cache dropNonRepos (Ca cache) = Ca $ filter notRepo cache where notRepo xs = case xs of Cache DarcsCache.Directory _ _ -> False -- we don't want to write thisrepo: entries to the disk Cache DarcsCache.Repo DarcsCache.Writable _ -> False _ -> True putInfo :: Verbosity -> Doc -> IO () putInfo Quiet _ = return () putInfo _ d = hPutDocLn stderr d putVerbose :: Verbosity -> Doc -> IO () putVerbose Verbose d = putDocLn d putVerbose _ _ = return () copyBasicRepoNotPacked :: forall rt p wR wU wT. Repository rt p wR wU wT -- remote -> Repository rt p wR wU wT -- existing empty local -> Verbosity -> RemoteDarcs -> WithWorkingDir -> IO () copyBasicRepoNotPacked fromRepo toRepo verb rdarcs withWorkingDir = do putVerbose verb $ text "Copying hashed inventory from remote repo..." HashedRepo.copyHashedInventory toRepo rdarcs (repoLocation fromRepo) putVerbose verb $ text "Writing pristine and working directory contents..." createPristineDirectoryTree toRepo "." withWorkingDir copyCompleteRepoNotPacked :: forall rt p wR wU wT. (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -- remote -> Repository rt p wR wU wT -- existing basic local -> Verbosity -> CloneKind -> IO () copyCompleteRepoNotPacked _ toRepo verb cloneKind = do let cleanup = putInfo verb $ text "Using lazy repository." allowCtrlC cloneKind cleanup $ do fetchPatchesIfNecessary toRepo pi <- doesPatchIndexExist (repoLocation toRepo) ps <- readRepo toRepo when pi $ createPIWithInterrupt toRepo ps copyBasicRepoPacked :: forall rt p wR wU wT. Repository rt p wR wU wT -- remote -> Repository rt p wR wU wT -- existing empty local repository -> Verbosity -> RemoteDarcs -> WithWorkingDir -> IO () copyBasicRepoPacked fromRepo toRepo verb rdarcs withWorkingDir = do let fromLoc = repoLocation fromRepo let hashURL = joinUrl [fromLoc, darcsdir, packsDir, "pristine"] mPackHash <- (Just <$> gzFetchFilePS hashURL Uncachable) `catchall` (return Nothing) let hiURL = joinUrl [fromLoc, darcsdir, "hashed_inventory"] i <- gzFetchFilePS hiURL Uncachable let currentHash = BC.pack $ peekPristineHash i let copyNormally = copyBasicRepoNotPacked fromRepo toRepo verb rdarcs withWorkingDir case mPackHash of Just packHash | packHash == currentHash -> ( copyBasicRepoPacked2 fromRepo toRepo verb withWorkingDir `catch` \(e :: SomeException) -> do putStrLn ("Exception while getting basic pack:\n" ++ show e) copyNormally) _ -> do putVerbose verb $ text "Remote repo has no basic pack or outdated basic pack, copying normally." copyNormally copyBasicRepoPacked2 :: forall rt p wR wU wT. Repository rt p wR wU wT -- remote -> Repository rt p wR wU wT -- existing empty local repository -> Verbosity -> WithWorkingDir -> IO () copyBasicRepoPacked2 fromRepo toRepo verb withWorkingDir = do putVerbose verb $ text "Cloning packed basic repository." -- unpack inventory & pristine cache cleanDir $ darcsdir "pristine.hashed" removeFile $ darcsdir "hashed_inventory" fetchAndUnpackBasic (repoCache toRepo) (repoLocation fromRepo) putInfo verb $ text "Done fetching and unpacking basic pack." createPristineDirectoryTree toRepo "." withWorkingDir copyCompleteRepoPacked :: forall rt p wR wU wT. (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -- remote -> Repository rt p wR wU wT -- existing basic local repository -> Verbosity -> CloneKind -> IO () copyCompleteRepoPacked from to verb cloneKind = copyCompleteRepoPacked2 from to verb cloneKind `catch` \(e :: SomeException) -> do putStrLn ("Exception while getting patches pack:\n" ++ show e) putVerbose verb $ text "Problem while copying patches pack, copying normally." copyCompleteRepoNotPacked from to verb cloneKind copyCompleteRepoPacked2 :: forall rt p wR wU wT. (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> Repository rt p wR wU wT -> Verbosity -> CloneKind -> IO () copyCompleteRepoPacked2 fromRepo toRepo verb cloneKind = do us <- readRepo toRepo -- get old patches let cleanup = putInfo verb $ text "Using lazy repository." allowCtrlC cloneKind cleanup $ do putVerbose verb $ text "Using patches pack." fetchAndUnpackPatches (mapRL hashedPatchFileName $ patchSet2RL us) (repoCache toRepo) (repoLocation fromRepo) pi <- doesPatchIndexExist (repoLocation toRepo) when pi $ createPIWithInterrupt toRepo us -- TODO or do another readRepo? cleanDir :: FilePath -> IO () cleanDir d = mapM_ (\x -> removeFile $ d x) . filter (\x -> head x /= '.') =<< getDirectoryContents d copyRepoOldFashioned :: forall rt p wR wU wT. (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -- remote repo -> Repository rt p wR wU wT -- local empty repo -> Verbosity -> WithWorkingDir -> IO () copyRepoOldFashioned fromrepository toRepo verb withWorkingDir = do HashedRepo.revertTentativeChanges patches <- readRepo fromrepository let k = "Copying patch" beginTedious k tediousSize k (lengthRL $ patchSet2RL patches) let patches' = progressPatchSet k patches HashedRepo.writeTentativeInventory (repoCache toRepo) GzipCompression patches' endTedious k HashedRepo.finalizeTentativeChanges toRepo GzipCompression -- apply all patches into current hashed repository HashedRepo.revertTentativeChanges local_patches <- readRepo toRepo replacePristine toRepo emptyTree let patchesToApply = progressFL "Applying patch" $ patchSet2FL local_patches sequence_ $ mapFL applyToTentativePristineCwd $ bunchFL 100 patchesToApply finalizeRepositoryChanges toRepo YesUpdateWorking GzipCompression putVerbose verb $ text "Writing pristine and working directory contents..." createPristineDirectoryTree toRepo "." withWorkingDir -- | This function fetches all patches that the given repository has -- with fetchFileUsingCache, unless --lazy is passed. fetchPatchesIfNecessary :: forall rt p wR wU wT. (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wT -> IO () fetchPatchesIfNecessary toRepo = do ps <- readRepo toRepo pipelineLength <- maxPipelineLength let patches = patchSet2RL ps ppatches = progressRLShowTags "Copying patches" patches (first, other) = splitAt (pipelineLength - 1) $ tail $ hashes patches speculate | pipelineLength > 1 = [] : first : map (:[]) other | otherwise = [] mapM_ fetchAndSpeculate $ zip (hashes ppatches) (speculate ++ repeat []) where hashes :: forall wX wY . RL (PatchInfoAnd rt p) wX wY -> [String] hashes = catMaybes . mapRL (either (const Nothing) Just . extractHash) fetchAndSpeculate :: (String, [String]) -> IO () fetchAndSpeculate (f, ss) = do _ <- fetchFileUsingCache c HashedPatchesDir f mapM_ (speculateFileUsingCache c HashedPatchesDir) ss c = repoCache toRepo {- -- | patchSetToRepository takes a patch set, and writes a new repository -- in the current directory that contains all the patches in the patch -- set. This function is used when 'darcs get'ing a repository with -- the --to-match flag. -- bf: no it is not used anywhere patchSetToRepository :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR1 wU1 wR1 -> PatchSet rt p Origin wX -> UseCache -> RemoteDarcs -> IO () patchSetToRepository fromRepo patchset useCache rDarcs = do when (formatHas HashedInventory (repoFormat fromRepo)) $ -- set up sources and all that do writeFile (darcsdir "tentative_pristine") "" -- this is hokey repox <- writePatchSet patchset useCache let fromLoc = repoLocation fromRepo HashedRepo.copyHashedInventory repox rDarcs fromLoc void $ copySources repox fromLoc repo <- writePatchSet patchset useCache readRepo repo >>= (runDefault . applyPatches . patchSet2FL) debugMessage "Writing the pristine" withRepoLocation repo $ readWorking >>= replacePristine repo -} -- | writePatchSet is like patchSetToRepository, except that it doesn't -- touch the working directory or pristine cache. writePatchSet :: (IsRepoType rt, RepoPatch p) => PatchSet rt p Origin wX -> UseCache -> IO (Repository rt p wR wU wT) writePatchSet patchset useCache = do maybeRepo <- maybeIdentifyRepository useCache "." let repo = case maybeRepo of GoodRepository r -> r BadRepository e -> bug ("Current directory is a bad repository in writePatchSet: " ++ e) NonRepository e -> bug ("Current directory not a repository in writePatchSet: " ++ e) debugMessage "Writing inventory" HashedRepo.writeTentativeInventory (repoCache repo) GzipCompression patchset HashedRepo.finalizeTentativeChanges repo GzipCompression return repo -- | Replace the existing pristine with a new one (loaded up in a Tree object). replacePristine :: Repository rt p wR wU wT -> Tree IO -> IO () replacePristine = writePristine . repoLocation allowCtrlC :: CloneKind -> IO () -> IO () -> IO () allowCtrlC CompleteClone _ action = action allowCtrlC _ cleanup action = action `catchInterrupt` cleanup hashedPatchFileName :: PatchInfoAnd rt p wA wB -> String hashedPatchFileName x = case extractHash x of Left _ -> fail "unexpected unhashed patch" Right h -> h darcs-2.14.5/src/Darcs/Repository/Create.hs0000644000000000000000000001252007346545000016631 0ustar0000000000000000module Darcs.Repository.Create ( createRepository , createRepositoryV1 , createRepositoryV2 , EmptyRepository(..) , writePristine ) where import Prelude () import Darcs.Prelude import Control.Monad ( when ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import Data.Maybe( isJust ) import System.Directory ( createDirectory , getCurrentDirectory , setCurrentDirectory ) import System.FilePath ( () ) import System.IO.Error ( catchIOError , isAlreadyExistsError ) import Darcs.Patch ( RepoPatch ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.RepoType ( RepoType(..), RebaseType(..) ) import Darcs.Patch.Set ( Origin, emptyPatchSet ) import Darcs.Patch.V1 ( RepoPatchV1 ) import Darcs.Patch.V2 ( RepoPatchV2 ) import qualified Darcs.Patch.V1.Prim as V1 ( Prim(..) ) import qualified Darcs.Patch.V2.Prim as V2 ( Prim(..) ) import Darcs.Repository.Cache ( Cache ) import Darcs.Repository.Format ( RepoFormat , createRepoFormat , writeRepoFormat ) import Darcs.Repository.Flags ( UseCache(..) , WithWorkingDir (..) , WithPatchIndex (..) , PatchFormat (..) ) import Darcs.Repository.Hashed ( pokePristineHash , pristineDirPath , patchesDirPath , inventoriesDirPath , hashedInventoryPath ) import Darcs.Repository.Identify ( seekRepo ) import Darcs.Repository.InternalTypes ( Repository , PristineType(..) , mkRepo ) import Darcs.Repository.PatchIndex ( createOrUpdatePatchIndexDisk ) import Darcs.Repository.Prefs ( writeDefaultPrefs , getCaches , prefsDirPath ) import Darcs.Util.ByteString( gzReadFilePS ) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Hash( encodeBase16 ) import Darcs.Util.Lock ( writeBinFile , writeDocBinFile ) import Darcs.Util.Tree( Tree, emptyTree ) import Darcs.Util.Tree.Hashed( writeDarcsHashed, darcsAddMissingHashes ) createRepositoryFiles :: PatchFormat -> WithWorkingDir -> IO RepoFormat createRepositoryFiles patchfmt withWorkingDir = do cwd <- getCurrentDirectory x <- seekRepo when (isJust x) $ do setCurrentDirectory cwd putStrLn "WARNING: creating a nested repository." createDirectory darcsdir `catchIOError` (\e-> if isAlreadyExistsError e then fail "Tree has already been initialized!" else fail $ "Error creating directory `"++darcsdir++"'.") createDirectory pristineDirPath createDirectory patchesDirPath createDirectory inventoriesDirPath createDirectory prefsDirPath writeDefaultPrefs let repo_format = createRepoFormat patchfmt withWorkingDir writeRepoFormat repo_format (darcsdir "format") -- note: all repos we create nowadays are hashed writeBinFile hashedInventoryPath B.empty writePristine here emptyTree return repo_format data EmptyRepository where EmptyRepository :: (RepoPatch p, ApplyState p ~ Tree) => Repository ('RepoType 'NoRebase) p Origin Origin Origin -> EmptyRepository createRepository :: PatchFormat -> WithWorkingDir -> WithPatchIndex -> UseCache -> IO EmptyRepository createRepository patchfmt withWorkingDir withPatchIndex useCache = do rfmt <- createRepositoryFiles patchfmt withWorkingDir cache <- getCaches useCache here repo@(EmptyRepository r) <- case patchfmt of PatchFormat1 -> return $ EmptyRepository $ mkRepoV1 rfmt cache PatchFormat2 -> return $ EmptyRepository $ mkRepoV2 rfmt cache maybeCreatePatchIndex withPatchIndex r return repo mkRepoV1 :: RepoFormat -> Cache -> Repository ('RepoType 'NoRebase) (RepoPatchV1 V1.Prim) Origin Origin Origin mkRepoV1 repofmt cache = mkRepo "." repofmt HashedPristine cache mkRepoV2 :: RepoFormat -> Cache -> Repository ('RepoType 'NoRebase) (RepoPatchV2 V2.Prim) Origin Origin Origin mkRepoV2 repofmt cache = mkRepo "." repofmt HashedPristine cache createRepositoryV1 :: WithWorkingDir -> WithPatchIndex -> UseCache -> IO (Repository ('RepoType 'NoRebase) (RepoPatchV1 V1.Prim) Origin Origin Origin) createRepositoryV1 withWorkingDir withPatchIndex useCache = do rfmt <- createRepositoryFiles PatchFormat1 withWorkingDir cache <- getCaches useCache here let repo = mkRepoV1 rfmt cache maybeCreatePatchIndex withPatchIndex repo return repo createRepositoryV2 :: WithWorkingDir -> WithPatchIndex -> UseCache -> IO (Repository ('RepoType 'NoRebase) (RepoPatchV2 V2.Prim) Origin Origin Origin) createRepositoryV2 withWorkingDir withPatchIndex useCache = do rfmt <- createRepositoryFiles PatchFormat2 withWorkingDir cache <- getCaches useCache here let repo = mkRepoV2 rfmt cache maybeCreatePatchIndex withPatchIndex repo return repo maybeCreatePatchIndex :: (RepoPatch p, ApplyState p ~ Tree) => WithPatchIndex -> Repository rt p Origin wU Origin -> IO () maybeCreatePatchIndex NoPatchIndex _ = return () maybeCreatePatchIndex YesPatchIndex repo = createOrUpdatePatchIndexDisk repo emptyPatchSet writePristine :: FilePath -> Tree IO -> IO () writePristine dir tree = withCurrentDirectory dir $ do inv <- gzReadFilePS hashedInventoryPath tree' <- darcsAddMissingHashes tree root <- writeDarcsHashed tree' pristineDirPath writeDocBinFile hashedInventoryPath $ pokePristineHash (BC.unpack $ encodeBase16 root) inv here :: String here = "." darcs-2.14.5/src/Darcs/Repository/Diff.hs0000644000000000000000000001701107346545000016276 0ustar0000000000000000-- Copyright (C) 2009 Petr Rockai -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. -- | -- Module : Darcs.Repository.Diff -- Copyright : 2009 Petr Rockai -- License : MIT -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.Repository.Diff ( treeDiff ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString.Lazy.Char8 as BLC import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import Data.List ( sortBy ) import Darcs.Util.Tree ( diffTrees , zipTrees , TreeItem(..) , Tree , readBlob , emptyBlob ) import Darcs.Util.Path( AnchoredPath, anchorPath ) import Darcs.Util.ByteString ( isFunky ) import Darcs.Patch ( PrimPatch , hunk , canonize , binary , addfile , rmfile , adddir , rmdir , invert ) import Darcs.Repository.Prefs ( FileType(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (+>+) ) import Darcs.Patch.Witnesses.Sealed ( Gap(..) ) import Darcs.Repository.Flags ( DiffAlgorithm(..) ) data Diff m = Added (TreeItem m) | Removed (TreeItem m) | Changed (TreeItem m) (TreeItem m) getDiff :: AnchoredPath -> Maybe (TreeItem m) -> Maybe (TreeItem m) -> (AnchoredPath, Diff m) getDiff p Nothing (Just t) = (p, Added t) getDiff p (Just from) (Just to) = (p, Changed from to) getDiff p (Just t) Nothing = (p, Removed t) getDiff _ Nothing Nothing = impossible -- zipTrees should never return this treeDiff :: forall m w prim . (Monad m, Gap w, PrimPatch prim) => DiffAlgorithm -> (FilePath -> FileType) -> Tree m -> Tree m -> m (w (FL prim)) treeDiff da ft t1 t2 = do (from, to) <- diffTrees t1 t2 diffs <- mapM (uncurry diff) $ sortBy organise $ zipTrees getDiff from to return $ foldr (joinGap (+>+)) (emptyGap NilFL) diffs where -- sort into removes, changes, adds, with removes in reverse-path order -- and everything else in forward order organise :: (AnchoredPath, Diff m) -> (AnchoredPath, Diff m) -> Ordering organise (p1, Changed _ _ ) (p2, Changed _ _) = compare p1 p2 organise (p1, Added _) (p2, Added _) = compare p1 p2 organise (p1, Removed _) (p2, Removed _) = compare p2 p1 organise (_, Removed _) _ = LT organise _ (_, Removed _) = GT organise (_, Changed _ _) _ = LT organise _ (_, Changed _ _) = GT diff :: AnchoredPath -> Diff m -> m (w (FL prim)) diff _ (Changed (SubTree _) (SubTree _)) = return (emptyGap NilFL) diff p (Removed (SubTree _)) = return $ freeGap (rmdir (anchorPath "" p) :>: NilFL) diff p (Added (SubTree _)) = return $ freeGap (adddir (anchorPath "" p) :>: NilFL) diff p (Added b'@(File _)) = do diff' <- diff p (Changed (File emptyBlob) b') return $ joinGap (:>:) (freeGap (addfile (anchorPath "" p))) diff' diff p (Removed a'@(File _)) = do diff' <- diff p (Changed a' (File emptyBlob)) return $ joinGap (+>+) diff' (freeGap (rmfile (anchorPath "" p) :>: NilFL)) diff p (Changed (File a') (File b')) = do a <- readBlob a' b <- readBlob b' let path = anchorPath "" p case ft path of TextFile | no_bin a && no_bin b -> return $ text_diff path a b _ -> return $ if a /= b then freeGap (binary path (strict a) (strict b) :>: NilFL) else emptyGap NilFL diff p (Changed a'@(File _) subtree@(SubTree _)) = do rmFileP <- diff p (Changed a' (File emptyBlob)) addDirP <- diff p (Added subtree) return $ joinGap (+>+) rmFileP addDirP diff p (Changed subtree@(SubTree _) b'@(File _)) = do rmDirP <- diff p (Removed subtree) addFileP <- diff p (Changed (File emptyBlob) b') return $ joinGap (+>+) rmDirP addFileP diff p _ = error $ "Missing case at path " ++ show p text_diff p a b | BL.null a && BL.null b = emptyGap NilFL | BL.null a = freeGap (diff_from_empty p b) | BL.null b = freeGap (diff_to_empty p a) -- What is 'a line'? One view is that a line is something that is -- /terminated/ by either a newline or end of file. Another view is -- that lines are /separated/ by newline symbols. -- -- The first view is the more "intuitive" one. The second is more -- "technical", it has the simpler definition and the highly desirable -- property that splitting a text into lines and joining them with -- newline symbols are inverse operations. The last point is the reason -- we never use the standard versions of 'unlines' for ByteString -- anywhere in darcs. -- -- The two views differ mostly when enumerating the lines of a file -- that ends with a newline symbol: here, the technical view counts one -- more (empty) line. This leads to un-intuitive (though technically -- not incorrect) results when calculating the diff for a change that -- appends an empty line to a file that already has a newline at the -- end. For instance, for a file with a single, newline-terminated line -- of text, the LCS algorithm would tell us that a *third* (empty) line -- is being added. -- -- To avoid this, we add a special case here: we strip off common -- newline symbols at the end. When we later split the result into -- lines for the diff algorithm, it never gets to see the empty -- last lines in both files and thus gives us the more intuitive result. | BLC.last a == '\n' && BLC.last b == '\n' = freeGap (line_diff p (linesB $ BLC.init a) (linesB $ BLC.init b)) | otherwise = freeGap (line_diff p (linesB a) (linesB b)) line_diff p a b = canonize da (hunk p 1 a b) diff_to_empty p x | BLC.last x == '\n' = line_diff p (init $ linesB x) [] | otherwise = line_diff p (linesB x) [B.empty] diff_from_empty p x = invert (diff_to_empty p x) no_bin = not . isFunky . strict . BL.take 4096 linesB = map strict . BLC.split '\n' strict = B.concat . BL.toChunks darcs-2.14.5/src/Darcs/Repository/Flags.hs0000644000000000000000000000732307346545000016467 0ustar0000000000000000module Darcs.Repository.Flags ( Compression (..) , RemoteDarcs (..) , remoteDarcs , Reorder (..) , Verbosity (..) , UpdateWorking (..) , UseCache (..) , DryRun (..) , UMask (..) , LookForAdds (..) , LookForReplaces (..) , DiffAlgorithm (..) , LookForMoves (..) , RunTest (..) , SetScriptsExecutable (..) , LeaveTestDir (..) , RemoteRepos (..) , SetDefault (..) , UseIndex (..) , ScanKnown (..) , CloneKind (..) , AllowConflicts (..) , ExternalMerge (..) , WorkRepo (..) , WantGuiPause (..) , WithPatchIndex (..) , WithWorkingDir (..) , ForgetParent (..) , PatchFormat (..) , IncludeBoring (..) , HooksConfig (..) , HookConfig (..) ) where import Darcs.Util.Diff ( DiffAlgorithm(..) ) import Darcs.Util.Global ( defaultRemoteDarcsCmd ) data Verbosity = Quiet | NormalVerbosity | Verbose deriving ( Eq, Show ) data Compression = NoCompression | GzipCompression deriving ( Eq, Show ) data WithPatchIndex = YesPatchIndex | NoPatchIndex deriving ( Eq, Show ) data RemoteDarcs = RemoteDarcs String | DefaultRemoteDarcs deriving ( Eq, Show ) remoteDarcs :: RemoteDarcs -> String remoteDarcs DefaultRemoteDarcs = defaultRemoteDarcsCmd remoteDarcs (RemoteDarcs x) = x data Reorder = NoReorder | Reorder deriving ( Eq ) data UpdateWorking = YesUpdateWorking | NoUpdateWorking deriving ( Eq, Show ) data UseCache = YesUseCache | NoUseCache deriving ( Eq, Show ) data DryRun = YesDryRun | NoDryRun deriving ( Eq, Show ) data UMask = YesUMask String | NoUMask deriving ( Eq, Show ) data LookForAdds = YesLookForAdds | NoLookForAdds deriving ( Eq, Show ) data LookForReplaces = YesLookForReplaces | NoLookForReplaces deriving ( Eq, Show ) data LookForMoves = YesLookForMoves | NoLookForMoves deriving ( Eq, Show ) data IncludeBoring = YesIncludeBoring | NoIncludeBoring deriving ( Eq, Show ) data RunTest = YesRunTest | NoRunTest deriving ( Eq, Show ) data SetScriptsExecutable = YesSetScriptsExecutable | NoSetScriptsExecutable deriving ( Eq, Show ) data LeaveTestDir = YesLeaveTestDir | NoLeaveTestDir deriving ( Eq, Show ) data RemoteRepos = RemoteRepos [String] deriving ( Eq, Show ) data SetDefault = YesSetDefault Bool | NoSetDefault Bool deriving ( Eq, Show ) data UseIndex = UseIndex | IgnoreIndex deriving ( Eq, Show ) data ScanKnown = ScanKnown -- ^Just files already known to darcs | ScanAll -- ^All files, i.e. look for new ones | ScanBoring -- ^All files, even boring ones deriving ( Eq, Show ) -- Various kinds of getting repositories data CloneKind = LazyClone -- ^Just copy pristine and inventories | NormalClone -- ^First do a lazy clone then copy everything | CompleteClone -- ^Same as Normal but omit telling user they can interrumpt deriving ( Eq, Show ) data AllowConflicts = NoAllowConflicts | YesAllowConflicts | YesAllowConflictsAndMark deriving ( Eq, Show ) data ExternalMerge = YesExternalMerge String | NoExternalMerge deriving ( Eq, Show ) data WorkRepo = WorkRepoDir String | WorkRepoPossibleURL String | WorkRepoCurrentDir deriving ( Eq, Show ) data WantGuiPause = YesWantGuiPause | NoWantGuiPause deriving ( Eq, Show ) data WithWorkingDir = WithWorkingDir | NoWorkingDir deriving ( Eq, Show ) data ForgetParent = YesForgetParent | NoForgetParent deriving ( Eq, Show ) data PatchFormat = PatchFormat1 | PatchFormat2 deriving ( Eq, Show ) data HooksConfig = HooksConfig { pre :: HookConfig , post :: HookConfig } data HookConfig = HookConfig { cmd :: Maybe String , prompt :: Bool } darcs-2.14.5/src/Darcs/Repository/Format.hs0000644000000000000000000002050607346545000016661 0ustar0000000000000000-- Copyright (C) 2005 David Roundy -- -- This file is licensed under the GPL, version two or later. module Darcs.Repository.Format ( RepoFormat(..) , RepoProperty(..) , identifyRepoFormat , tryIdentifyRepoFormat , createRepoFormat , writeRepoFormat , writeProblem , readProblem , transferProblem , formatHas , addToFormat , removeFromFormat ) where import Prelude () import Darcs.Prelude import Control.Monad ( mplus, (<=<) ) import qualified Data.ByteString.Char8 as BC ( split, pack, unpack, elemIndex ) import qualified Data.ByteString as B ( null, empty ) import Data.List ( partition, intercalate, (\\) ) import Data.Maybe ( isJust, mapMaybe ) import Darcs.Util.External ( fetchFilePS , Cachable( Cachable ) ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Lock ( writeBinFile ) import qualified Darcs.Repository.Flags as F ( WithWorkingDir (..), PatchFormat (..) ) import Darcs.Util.SignalHandler ( catchNonSignal ) import Darcs.Util.Exception ( catchall, prettyException ) import Darcs.Util.ByteString ( linesPS ) import Darcs.Util.Progress ( beginTedious, endTedious, finishedOneIO ) data RepoProperty = Darcs1 | Darcs2 | HashedInventory | NoWorkingDir | RebaseInProgress | UnknownFormat String deriving ( Eq ) -- | Define string constants in one place, for reuse in show/parse functions. darcs1Format, darcs2Format, hashedInventoryFormat :: String noWorkingDirFormat, rebaseInProgressFormat :: String darcs1Format = "darcs-1.0" darcs2Format = "darcs-2" hashedInventoryFormat = "hashed" noWorkingDirFormat = "no-working-dir" rebaseInProgressFormat = "rebase-in-progress" instance Show RepoProperty where show Darcs1 = darcs1Format show Darcs2 = darcs2Format show HashedInventory = hashedInventoryFormat show NoWorkingDir = noWorkingDirFormat show RebaseInProgress = rebaseInProgressFormat show (UnknownFormat f) = f readRepoProperty :: String -> RepoProperty readRepoProperty input | input == darcs1Format = Darcs1 | input == darcs2Format = Darcs2 | input == hashedInventoryFormat = HashedInventory | input == noWorkingDirFormat = NoWorkingDir | input == rebaseInProgressFormat = RebaseInProgress | otherwise = UnknownFormat input -- | Representation of the format of a repository. Each -- sublist corresponds to a line in the format file. -- Currently all lines are expected to be singleton words. newtype RepoFormat = RF [[RepoProperty]] -- | Is a given property contained within a given format? formatHas :: RepoProperty -> RepoFormat -> Bool formatHas f (RF rps) = f `elem` concat rps -- | Add a single property to an existing format. addToFormat :: RepoProperty -> RepoFormat -> RepoFormat addToFormat f (RF rps) = RF (rps ++ [[f]]) -- | Remove a single property from an existing format. removeFromFormat :: RepoProperty -> RepoFormat -> RepoFormat removeFromFormat f (RF rps) = RF (rps \\ [[f]]) instance Show RepoFormat where show (RF rf) = unlines $ map (intercalate "|" . map show) rf -- | Identify the format of the repository at the -- given location (directory, URL, or SSH path). -- Fails if we weren't able to identify the format. identifyRepoFormat :: String -> IO RepoFormat identifyRepoFormat = either fail return <=< tryIdentifyRepoFormat -- | Identify the format of the repository at the -- given location (directory, URL, or SSH path). -- Return @'Left' reason@ if it fails, where @reason@ explains why -- we weren't able to identify the format. Note that we do no verification of -- the format, which is handled by 'readProblem' or 'writeProblem' on the -- resulting 'RepoFormat'. tryIdentifyRepoFormat :: String -> IO (Either String RepoFormat) tryIdentifyRepoFormat repo = do let k = "Identifying repository " ++ repo beginTedious k finishedOneIO k "format" formatInfo <- (fetchFilePS (repoPath "format") Cachable) `catchall` (return B.empty) -- We use a workaround for servers that don't return a 404 on nonexistent -- files (we trivially check for something that looks like a HTML/XML tag). format <- if (B.null formatInfo || isJust (BC.elemIndex '<' formatInfo)) then do finishedOneIO k "inventory" missingInvErr <- checkFile (repoPath "inventory") case missingInvErr of Nothing -> return . Right $ RF [[Darcs1]] Just e -> return . Left $ makeErrorMsg e else return . Right $ readFormat formatInfo endTedious k return format where repoPath fileName = repo ++ "/" ++ darcsdir ++ "/" ++ fileName readFormat = RF . map (map (readRepoProperty . BC.unpack)) . splitFormat -- split into lines, then split each non-empty line on '|' splitFormat = map (BC.split '|') . filter (not . B.null) . linesPS checkFile path = (fetchFilePS path Cachable >> return Nothing) `catchNonSignal` (return . Just . prettyException) makeErrorMsg e = unlines [ "Not a repository: " ++ repo ++ " (" ++ e ++ ")" , "" , "HINT: Do you have the right URI for the repository?" ] -- | Write the repo format to the given file. writeRepoFormat :: RepoFormat -> FilePath -> IO () writeRepoFormat rf loc = writeBinFile loc $ BC.pack $ show rf -- note: this assumes show returns ascii -- | Create a repo format. The first argument is whether to use the old (darcs-1) -- format; the second says whether the repo has a working tree. createRepoFormat :: F.PatchFormat -> F.WithWorkingDir -> RepoFormat createRepoFormat fmt wwd = RF $ (HashedInventory : flags2wd wwd) : flags2format fmt where flags2format F.PatchFormat1 = [] flags2format F.PatchFormat2 = [[Darcs2]] flags2wd F.NoWorkingDir = [NoWorkingDir] flags2wd F.WithWorkingDir = [] -- | @'writeProblem' source@ returns 'Just' an error message if we cannot write -- to a repo in format @source@, or 'Nothing' if there's no such problem. writeProblem :: RepoFormat -> Maybe String writeProblem target = readProblem target `mplus` findProblems target wp where wp [] = impossible wp x = case partition isKnown x of (_, []) -> Nothing (_, unknowns) -> Just . unwords $ "Can't write repository: unknown formats:" : map show unknowns -- | @'transferProblem' source target@ returns 'Just' an error message if we -- cannot transfer patches from a repo in format @source@ to a repo in format -- @target@, or 'Nothing' if there are no such problem. transferProblem :: RepoFormat -> RepoFormat -> Maybe String transferProblem source target | formatHas Darcs2 source /= formatHas Darcs2 target = Just "Cannot mix darcs-2 repositories with older formats" | formatHas RebaseInProgress source = -- we could support this, by applying an appropriate filter to the patches -- as we pull them. Just "Cannot transfer patches from a repository where a rebase is in progress" | otherwise = readProblem source `mplus` writeProblem target -- | @'readProblem' source@ returns 'Just' an error message if we cannot read -- from a repo in format @source@, or 'Nothing' if there's no such problem. readProblem :: RepoFormat -> Maybe String readProblem source | formatHas Darcs1 source && formatHas Darcs2 source = Just "Invalid repositoryformat: format 2 is incompatible with format 1" readProblem source = findProblems source rp where rp x | any isKnown x = Nothing rp [] = impossible rp x = Just . unwords $ "Can't read repository: unknown formats:" : map show x -- |'findProblems' applies a function that maps format-entries to an optional -- error message, to each repoformat entry. Returning any errors. findProblems :: RepoFormat -> ([RepoProperty] -> Maybe String) -> Maybe String findProblems (RF ks) formatHasProblem = case mapMaybe formatHasProblem ks of [] -> Nothing xs -> Just $ unlines xs -- | Does this version of darcs know how to handle this property? isKnown :: RepoProperty -> Bool isKnown p = p `elem` knownProperties where knownProperties :: [RepoProperty] knownProperties = [ Darcs1 , Darcs2 , HashedInventory , NoWorkingDir , RebaseInProgress ] darcs-2.14.5/src/Darcs/Repository/Hashed.hs0000644000000000000000000014075707346545000016640 0ustar0000000000000000-- Copyright (C) 2006-2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. module Darcs.Repository.Hashed ( inventoriesDir , inventoriesDirPath , pristineDir , pristineDirPath , patchesDir , patchesDirPath , hashedInventory , hashedInventoryPath , revertTentativeChanges , revertRepositoryChanges , finalizeTentativeChanges , cleanPristine , filterDirContents , cleanInventories , cleanPatches , copyPristine , copyPartialsPristine , applyToTentativePristine , applyToTentativePristineCwd , addToTentativeInventory , readRepo , readRepoHashed , readTentativeRepo , writeAndReadPatch , writeTentativeInventory , copyHashedInventory , readHashedPristineRoot , pokePristineHash , peekPristineHash , listInventories , listInventoriesLocal , listInventoriesRepoDir , listPatchesLocalBucketed , writePatchIfNecessary , diffHashLists , withRecorded , withTentative , tentativelyAddPatch , tentativelyRemovePatches , tentativelyRemovePatches_ , tentativelyAddPatch_ , tentativelyAddPatches_ , tentativelyReplacePatches , finalizeRepositoryChanges , unrevertUrl , createPristineDirectoryTree , createPartialsPristineDirectoryTree , reorderInventory , cleanRepository , UpdatePristine(..) , repoXor ) where import Prelude () import Darcs.Prelude import Control.Arrow ( (&&&) ) import Control.Exception ( catch, IOException ) import Darcs.Util.Exception ( catchall ) import Control.Monad ( when, unless, void ) import Data.Maybe import Data.List( foldl' ) import qualified Data.ByteString as B ( empty, readFile, append ) import qualified Data.ByteString.Char8 as BC ( unpack, pack ) import qualified Data.Set as Set import Darcs.Util.Hash( encodeBase16, Hash(..), SHA1, sha1Xor, sha1zero ) import Darcs.Util.Prompt ( promptYorn ) import Darcs.Util.Tree( treeHash, Tree ) import Darcs.Util.Tree.Hashed( hashedTreeIO, readDarcsHashedNosize, readDarcsHashed, writeDarcsHashed, decodeDarcsHash, decodeDarcsSize ) import Darcs.Util.SignalHandler ( withSignalsBlocked ) import System.Directory ( createDirectoryIfMissing, getDirectoryContents , doesFileExist, doesDirectoryExist ) import System.FilePath.Posix( () ) import System.IO.Unsafe ( unsafeInterleaveIO ) import System.IO ( stderr, hPutStrLn ) import Darcs.Util.External ( copyFileOrUrl , cloneFile , fetchFilePS , gzFetchFilePS , Cachable( Uncachable ) ) import Darcs.Repository.Flags ( Compression, RemoteDarcs, remoteDarcs , Verbosity(..), UpdateWorking (..), WithWorkingDir (WithWorkingDir) ) import Darcs.Repository.Format ( RepoProperty( HashedInventory ), formatHas ) import Darcs.Repository.Pending ( readPending , pendingName , tentativelyRemoveFromPending , finalizePending , setTentativePending , prepend ) import Darcs.Repository.PatchIndex ( createOrUpdatePatchIndexDisk, doesPatchIndexExist ) import Darcs.Repository.State ( readRecorded, updateIndex ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Lock ( writeBinFile , writeDocBinFile , writeAtomicFilePS , appendDocBinFile , removeFileMayNotExist ) import Darcs.Patch.Set ( PatchSet(..), Tagged(..) , SealedPatchSet, Origin , patchSet2RL ) import Darcs.Patch.Show ( ShowPatch, ShowPatchFor(..) ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, Hopefully, patchInfoAndPatch, info , extractHash, createHashed, hopefully ) import Darcs.Patch ( IsRepoType, RepoPatch, showPatch, apply , description , commuteRL , readPatch , effect , invert ) import Darcs.Patch.Apply ( Apply, ApplyState ) import Darcs.Patch.Bundle ( scanBundle , makeBundleN ) import Darcs.Patch.Named.Wrapped ( namedIsInternal ) import Darcs.Patch.Read ( ReadPatch ) import Darcs.Patch.Depends ( removeFromPatchSet, slightlyOptimizePatchset , mergeThem, splitOnTag ) import Darcs.Patch.Info ( PatchInfo, displayPatchInfo, isTag, makePatchname ) import Darcs.Util.Path ( FilePathLike, ioAbsoluteOrRemote, toPath , AbsolutePath, toFilePath ) import Darcs.Repository.Cache ( Cache(..), fetchFileUsingCache, speculateFilesUsingCache, writeFileUsingCache, HashedDir(..), hashedDir, peekInCache, bucketFolder ) import Darcs.Repository.HashedIO ( copyHashed, copyPartialsHashed, cleanHashdir ) import Darcs.Repository.Inventory import Darcs.Repository.InternalTypes ( Repository , repoCache , repoFormat , repoLocation , withRepoLocation , coerceT ) import qualified Darcs.Repository.Old as Old ( readOldRepo, oldRepoFailMsg ) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Patch.Witnesses.Ordered ( (+<+), FL(..), RL(..), mapRL, foldFL_M , (:>)(..), lengthFL, filterOutFLFL , reverseFL, reverseRL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), seal, unseal, mapSeal ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Util.ByteString ( gzReadFilePS ) import Darcs.Util.Printer.Color ( showDoc ) import Darcs.Util.Printer ( Doc, hcat, ($$), renderString, renderPS, text, putDocLn, (<+>) ) import Darcs.Util.Progress ( beginTedious, endTedious, debugMessage, finishedOneIO ) import Darcs.Patch.Progress (progressFL) import Darcs.Util.Workaround ( renameFile ) import Darcs.Repository.Prefs ( globalCacheDir ) makeDarcsdirPath :: String -> String makeDarcsdirPath name = darcsdir name -- TODO rename xyzPath to xyzLocal to make it clear that it is -- relative to the local darcsdir -- Location of the (one and only) head inventory. hashedInventory, hashedInventoryPath :: String hashedInventory = "hashed_inventory" hashedInventoryPath = makeDarcsdirPath hashedInventory -- Location of the (one and only) tentative head inventory. tentativeHashedInventory, tentativeHashedInventoryPath :: String tentativeHashedInventory = "tentative_hashed_inventory" tentativeHashedInventoryPath = makeDarcsdirPath tentativeHashedInventory -- Location of parent inventories. inventoriesDir, inventoriesDirPath :: String inventoriesDir = "inventories" inventoriesDirPath = makeDarcsdirPath inventoriesDir -- Location of pristine trees. pristineDir, tentativePristinePath, pristineDirPath :: String tentativePristinePath = makeDarcsdirPath "tentative_pristine" pristineDir = "pristine.hashed" pristineDirPath = makeDarcsdirPath pristineDir -- Location of patches. patchesDir, patchesDirPath :: String patchesDir = "patches" patchesDirPath = makeDarcsdirPath patchesDir -- | The way patchfiles, inventories, and pristine trees are stored. -- 'PlainLayout' means all files are in the same directory. 'BucketedLayout' -- means we create a second level of subdirectories, such that all files whose -- hash starts with the same two letters are in the same directory. data DirLayout = PlainLayout | BucketedLayout -- | 'applyToHashedPristine' takes a root hash, a patch @p@ and attempts to -- apply the patch to the 'Tree' identified by @h@. If we encounter an old, -- size-prefixed pristine, we first convert it to the non-size-prefixed format, -- then apply the patch. applyToHashedPristine :: (Apply p, ApplyState p ~ Tree) => String -> p wX wY -> IO String applyToHashedPristine h p = applyOrConvertOldPristineAndApply where applyOrConvertOldPristineAndApply = tryApply hash `catch` \(_ :: IOException) -> handleOldPristineAndApply hash = decodeDarcsHash $ BC.pack h failOnMalformedRoot (SHA256 _) = return () failOnMalformedRoot root = fail $ "Cannot handle hash: " ++ show root hash2root = BC.unpack . encodeBase16 tryApply :: Hash -> IO String tryApply root = do failOnMalformedRoot root -- Read a non-size-prefixed pristine, failing if we encounter one. tree <- readDarcsHashedNosize pristineDirPath root (_, updatedTree) <- hashedTreeIO (apply p) tree pristineDirPath return . hash2root $ treeHash updatedTree warn = "WARNING: Doing a one-time conversion of pristine format.\n" ++ "This may take a while. The new format is backwards-compatible." handleOldPristineAndApply = do hPutStrLn stderr warn inv <- gzReadFilePS hashedInventoryPath let oldroot = BC.pack $ peekPristineHash inv oldrootSizeandHash = (decodeDarcsSize &&& decodeDarcsHash) oldroot -- Read the old size-prefixed pristine tree old <- readDarcsHashed pristineDirPath oldrootSizeandHash -- Write out the pristine tree as a non-size-prefixed pristine. root <- writeDarcsHashed old pristineDirPath let newroot = hash2root root -- Write out the new inventory. writeDocBinFile hashedInventoryPath $ pokePristineHash newroot inv cleanHashdir (Ca []) HashedPristineDir [newroot] hPutStrLn stderr "Pristine conversion done..." -- Retry applying the patch, which should now succeed. tryApply root -- |revertTentativeChanges swaps the tentative and "real" hashed inventory -- files, and then updates the tentative pristine with the "real" inventory -- hash. revertTentativeChanges :: IO () revertTentativeChanges = do cloneFile hashedInventoryPath tentativeHashedInventoryPath i <- gzReadFilePS hashedInventoryPath writeBinFile tentativePristinePath $ B.append pristineName (BC.pack (peekPristineHash i)) -- |finalizeTentativeChanges trys to atomically swap the tentative -- inventory/pristine pointers with the "real" pointers; it first re-reads the -- inventory to optimize it, presumably to take account of any new tags, and -- then writes out the new tentative inventory, and finally does the atomic -- swap. In general, we can't clean the pristine cache at the same time, since -- a simultaneous get might be in progress. finalizeTentativeChanges :: (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wT -> Compression -> IO () finalizeTentativeChanges r compr = do debugMessage "Optimizing the inventory..." -- Read the tentative patches ps <- readTentativeRepo r "." writeTentativeInventory (repoCache r) compr ps i <- gzReadFilePS tentativeHashedInventoryPath p <- gzReadFilePS tentativePristinePath -- Write out the "optimised" tentative inventory. writeDocBinFile tentativeHashedInventoryPath $ pokePristineHash (peekPristineHash p) i -- Atomically swap. renameFile tentativeHashedInventoryPath hashedInventoryPath -- |readHashedPristineRoot attempts to read the pristine hash from the current -- inventory, returning Nothing if it cannot do so. readHashedPristineRoot :: Repository rt p wR wU wT -> IO (Maybe String) readHashedPristineRoot r = withRepoLocation r $ do i <- (Just <$> gzReadFilePS hashedInventoryPath) `catch` (\(_ :: IOException) -> return Nothing) return $ peekPristineHash <$> i -- |cleanPristine removes any obsolete (unreferenced) entries in the pristine -- cache. cleanPristine :: Repository rt p wR wU wT -> IO () cleanPristine r = withRepoLocation r $ do debugMessage "Cleaning out the pristine cache..." i <- gzReadFilePS hashedInventoryPath cleanHashdir (repoCache r) HashedPristineDir [peekPristineHash i] -- |filterDirContents returns the contents of the directory @d@ -- except files whose names begin with '.' (directories . and .., -- hidden files) and files whose names are filtered by the function @f@, if -- @dir@ is empty, no paths are returned. filterDirContents :: FilePath -> (FilePath -> Bool) -> IO [FilePath] filterDirContents d f = do let realPath = makeDarcsdirPath d exists <- doesDirectoryExist realPath if exists then filter (\x -> head x /= '.' && f x) <$> getDirectoryContents realPath else return [] -- | Set difference between two lists of hashes. diffHashLists :: [String] -> [String] -> [String] diffHashLists xs ys = from_set $ (to_set xs) `Set.difference` (to_set ys) where to_set = Set.fromList . map BC.pack from_set = map BC.unpack . Set.toList -- |cleanInventories removes any obsolete (unreferenced) files in the -- inventories directory. cleanInventories :: Repository rt p wR wU wT -> IO () cleanInventories _ = do debugMessage "Cleaning out inventories..." hs <- listInventoriesLocal fs <- filterDirContents inventoriesDir (const True) mapM_ (removeFileMayNotExist . (inventoriesDirPath )) (diffHashLists fs hs) -- FIXME this is ugly, these files should be directly under _darcs -- since they are not hashed. And 'unrevert' isn't even a real patch but -- a patch bundle. -- |specialPatches list of special patch files that may exist in the directory -- _darcs/patches/. specialPatches :: [FilePath] specialPatches = ["unrevert", "pending", "pending.tentative"] -- |cleanPatches removes any obsolete (unreferenced) files in the -- patches directory. cleanPatches :: Repository rt p wR wU wT -> IO () cleanPatches _ = do debugMessage "Cleaning out patches..." hs <- listPatchesLocal PlainLayout darcsdir darcsdir fs <- filterDirContents patchesDir (`notElem` specialPatches) mapM_ (removeFileMayNotExist . (patchesDirPath )) (diffHashLists fs hs) -- |addToSpecificInventory adds a patch to a specific inventory file, and -- returns the FilePath whichs corresponds to the written-out patch. addToSpecificInventory :: RepoPatch p => String -> Cache -> Compression -> PatchInfoAnd rt p wX wY -> IO FilePath addToSpecificInventory invPath c compr p = do let invFile = makeDarcsdirPath invPath hash <- snd <$> writePatchIfNecessary c compr p appendDocBinFile invFile $ showInventoryEntry (info p, hash) return $ patchesDirPath getValidHash hash -- | Warning: this allows to add any arbitrary patch! Used by convert import. addToTentativeInventory :: RepoPatch p => Cache -> Compression -> PatchInfoAnd rt p wX wY -> IO FilePath addToTentativeInventory = addToSpecificInventory tentativeHashedInventory -- | Attempt to remove an FL of patches from the tentative inventory. -- This is used for commands that wish to modify already-recorded patches. -- -- Precondition: it must be possible to remove the patches, i.e. -- -- * the patches are in the repository -- -- * any necessary commutations will succeed removeFromTentativeInventory :: (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wT -> Compression -> FL (PatchInfoAnd rt p) wX wT -> IO () removeFromTentativeInventory repo compr to_remove = do debugMessage $ "Start removeFromTentativeInventory" allpatches <- readTentativeRepo repo "." remaining <- case removeFromPatchSet to_remove allpatches of Nothing -> bug "Hashed.removeFromTentativeInventory: precondition violated" Just r -> return r writeTentativeInventory (repoCache repo) compr remaining debugMessage $ "Done removeFromTentativeInventory" -- |writeHashFile takes a Doc and writes it as a hash-named file, returning the -- filename that the contents were written to. writeHashFile :: Cache -> Compression -> HashedDir -> Doc -> IO String writeHashFile c compr subdir d = do debugMessage $ "Writing hash file to " ++ hashedDir subdir writeFileUsingCache c compr subdir $ renderPS d -- |readRepo returns the "current" repo patchset. readRepoHashed :: (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wT -> String -> IO (PatchSet rt p Origin wR) readRepoHashed = readRepoUsingSpecificInventory hashedInventory -- |readRepo returns the tentative repo patchset. readTentativeRepo :: (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wT -> String -> IO (PatchSet rt p Origin wT) readTentativeRepo = readRepoUsingSpecificInventory tentativeHashedInventory -- |readRepoUsingSpecificInventory uses the inventory at @invPath@ to read the -- repository @repo@. readRepoUsingSpecificInventory :: (IsRepoType rt, RepoPatch p) => String -> Repository rt p wR wU wT -> String -> IO (PatchSet rt p Origin wS) readRepoUsingSpecificInventory invPath repo dir = do realdir <- toPath <$> ioAbsoluteOrRemote dir Sealed ps <- readRepoPrivate (repoCache repo) realdir invPath `catch` \e -> do hPutStrLn stderr ("Invalid repository: " ++ realdir) ioError e return $ unsafeCoerceP ps where readRepoPrivate :: (IsRepoType rt, RepoPatch p) => Cache -> FilePath -> FilePath -> IO (SealedPatchSet rt p Origin) readRepoPrivate cache d iname = do inventory <- readInventoryPrivate (d darcsdir iname) readRepoFromInventoryList cache inventory -- | Read a 'PatchSet' from the repository (assumed to be located at the -- current working directory) by following the chain of 'Inventory's, starting -- with the given one. The 'Cache' parameter is used to locate patches and parent -- inventories, since not all of them need be present inside the current repo. readRepoFromInventoryList :: (IsRepoType rt, RepoPatch p) => Cache -> Inventory -> IO (SealedPatchSet rt p Origin) readRepoFromInventoryList cache = parseInv where parseInv :: (IsRepoType rt, RepoPatch p) => Inventory -> IO (SealedPatchSet rt p Origin) parseInv (Inventory Nothing ris) = mapSeal (PatchSet NilRL) <$> read_patches (reverse ris) parseInv (Inventory (Just h) []) = -- TODO could be more tolerant and create a larger PatchSet bug $ "bad inventory " ++ getValidHash h ++ " (no tag) in parseInv!" parseInv (Inventory (Just h) (t : ris)) = do Sealed ts <- unseal seal <$> unsafeInterleaveIO (read_ts t h) Sealed ps <- unseal seal <$> unsafeInterleaveIO (read_patches $ reverse ris) return $ seal $ PatchSet ts ps read_patches :: (IsRepoType rt, RepoPatch p) => [InventoryEntry] -> IO (Sealed (RL (PatchInfoAnd rt p) wX)) read_patches [] = return $ seal NilRL read_patches allis@((i1, h1) : is1) = lift2Sealed (\p rest -> rest :<: i1 `patchInfoAndPatch` p) (rp is1) (createValidHashed h1 (const $ speculateAndParse h1 allis i1)) where rp :: (IsRepoType rt, RepoPatch p) => [InventoryEntry] -> IO (Sealed (RL (PatchInfoAnd rt p) wX)) rp [] = return $ seal NilRL rp [(i, h), (il, hl)] = lift2Sealed (\p rest -> rest :<: i `patchInfoAndPatch` p) (rp [(il, hl)]) (createValidHashed h (const $ speculateAndParse h (reverse allis) i)) rp ((i, h) : is) = lift2Sealed (\p rest -> rest :<: i `patchInfoAndPatch` p) (rp is) (createValidHashed h (parse i)) lift2Sealed :: (forall wY wZ . q wY wZ -> p wX wY -> r wX wZ) -> IO (Sealed (p wX)) -> (forall wB . IO (Sealed (q wB))) -> IO (Sealed (r wX)) lift2Sealed f iox ioy = do Sealed x <- unseal seal <$> unsafeInterleaveIO iox Sealed y <- unseal seal <$> unsafeInterleaveIO ioy return $ seal $ f y x speculateAndParse h is i = speculate h is >> parse i h speculate :: PatchHash -> [InventoryEntry] -> IO () speculate h is = do already_got_one <- peekInCache cache HashedPatchesDir (getValidHash h) unless already_got_one $ speculateFilesUsingCache cache HashedPatchesDir (map (getValidHash . snd) is) parse :: ReadPatch p => PatchInfo -> PatchHash -> IO (Sealed (p wX)) parse i h = do debugMessage ("Reading patch file: "++ showDoc (displayPatchInfo i)) (fn, ps) <- fetchFileUsingCache cache HashedPatchesDir (getValidHash h) case readPatch ps of Just p -> return p Nothing -> fail $ unlines [ "Couldn't parse file " ++ fn , "which is patch" , renderString $ displayPatchInfo i ] read_ts :: (IsRepoType rt, RepoPatch p) => InventoryEntry -> InventoryHash -> IO (Sealed (RL (Tagged rt p) Origin)) read_ts tag0 h0 = do contents <- unsafeInterleaveIO $ readTaggedInventoryFromHash (getValidHash h0) let is = reverse $ case contents of (Inventory (Just _) (_ : ris0)) -> ris0 (Inventory Nothing ris0) -> ris0 (Inventory (Just _) []) -> bug "inventory without tag!" Sealed ts <- unseal seal <$> unsafeInterleaveIO (case contents of (Inventory (Just h') (t' : _)) -> read_ts t' h' (Inventory (Just _) []) -> bug "inventory without tag!" (Inventory Nothing _) -> return $ seal NilRL) Sealed ps <- unseal seal <$> unsafeInterleaveIO (read_patches is) Sealed tag00 <- read_tag tag0 return $ seal $ ts :<: Tagged tag00 (Just (getValidHash h0)) ps read_tag :: (IsRepoType rt, RepoPatch p) => InventoryEntry -> IO (Sealed (PatchInfoAnd rt p wX)) read_tag (i, h) = mapSeal (patchInfoAndPatch i) <$> createValidHashed h (parse i) readTaggedInventoryFromHash :: String -> IO Inventory readTaggedInventoryFromHash invHash = do (fileName, pristineAndInventory) <- fetchFileUsingCache cache HashedInventoriesDir invHash case parseInventory pristineAndInventory of Just r -> return r Nothing -> fail $ unwords ["parse error in file", fileName] -- | Read an inventory from a file. Fails with an error message if -- file is not there or cannot be parsed. readInventoryPrivate :: FilePath -> IO Inventory readInventoryPrivate path = do inv <- skipPristineHash <$> gzFetchFilePS path Uncachable case parseInventory inv of Just r -> return r Nothing -> fail $ unwords ["parse error in file", path] -- |copyRepo copies the hashed inventory of @repo@ to the repository located at -- @remote@. copyHashedInventory :: Repository rt p wR wU wT -> RemoteDarcs -> String -> IO () copyHashedInventory outrepo rdarcs inloc | remote <- remoteDarcs rdarcs = do let outloc = repoLocation outrepo createDirectoryIfMissing False (outloc ++ "/" ++ inventoriesDirPath) copyFileOrUrl remote (inloc hashedInventoryPath) (outloc hashedInventoryPath) Uncachable -- no need to copy anything but hashed_inventory! debugMessage "Done copying hashed inventory." -- |writeAndReadPatch makes a patch lazy, by writing it out to disk (thus -- forcing it), and then re-reads the patch lazily. writeAndReadPatch :: (IsRepoType rt, RepoPatch p) => Cache -> Compression -> PatchInfoAnd rt p wX wY -> IO (PatchInfoAnd rt p wX wY) writeAndReadPatch c compr p = do (i, h) <- writePatchIfNecessary c compr p unsafeInterleaveIO $ readp h i where parse i h = do debugMessage ("Rereading patch file: "++ showDoc (displayPatchInfo i)) (fn, ps) <- fetchFileUsingCache c HashedPatchesDir (getValidHash h) case readPatch ps of Just x -> return x Nothing -> fail $ unlines [ "Couldn't parse patch file " ++ fn , "which is" , renderString $ displayPatchInfo i] readp h i = do Sealed x <- createValidHashed h (parse i) return . patchInfoAndPatch i $ unsafeCoerceP x createValidHashed :: PatchHash -> (PatchHash -> IO (Sealed (a wX))) -> IO (Sealed (Darcs.Patch.PatchInfoAnd.Hopefully a wX)) createValidHashed h f = createHashed (getValidHash h) (f . mkValidHash) -- | writeTentativeInventory writes @patchSet@ as the tentative inventory. writeTentativeInventory :: RepoPatch p => Cache -> Compression -> PatchSet rt p Origin wX -> IO () writeTentativeInventory cache compr patchSet = do debugMessage "in writeTentativeInventory..." createDirectoryIfMissing False inventoriesDirPath beginTedious tediousName hsh <- writeInventoryPrivate $ slightlyOptimizePatchset patchSet endTedious tediousName debugMessage "still in writeTentativeInventory..." case hsh of Nothing -> writeBinFile (makeDarcsdirPath tentativeHashedInventory) B.empty Just h -> do content <- snd <$> fetchFileUsingCache cache HashedInventoriesDir h writeAtomicFilePS (makeDarcsdirPath tentativeHashedInventory) content where tediousName = "Writing inventory" writeInventoryPrivate :: RepoPatch p => PatchSet rt p Origin wX -> IO (Maybe String) writeInventoryPrivate (PatchSet NilRL NilRL) = return Nothing writeInventoryPrivate (PatchSet NilRL ps) = do inventory <- sequence $ mapRL (writePatchIfNecessary cache compr) ps let inventorylist = showInventoryPatches (reverse inventory) hash <- writeHashFile cache compr HashedInventoriesDir inventorylist return $ Just hash writeInventoryPrivate (PatchSet xs@(_ :<: Tagged t _ _) x) = do resthash <- write_ts xs finishedOneIO tediousName $ fromMaybe "" resthash inventory <- sequence $ mapRL (writePatchIfNecessary cache compr) (NilRL :<: t +<+ x) let inventorylist = hcat (map showInventoryEntry $ reverse inventory) inventorycontents = case resthash of Just h -> text ("Starting with inventory:\n" ++ h) $$ inventorylist Nothing -> inventorylist hash <- writeHashFile cache compr HashedInventoriesDir inventorycontents return $ Just hash where -- | write_ts writes out a tagged patchset. If it has already been -- written, we'll have the hash, so we can immediately return it. write_ts :: RepoPatch p => RL (Tagged rt p) Origin wX -> IO (Maybe String) write_ts (_ :<: Tagged _ (Just h) _) = return (Just h) write_ts (tts :<: Tagged _ Nothing pps) = writeInventoryPrivate $ PatchSet tts pps write_ts NilRL = return Nothing -- |writeHashIfNecessary writes the patch and returns the resulting info/hash, -- if it has not already been written. If it has been written, we have the hash -- in the PatchInfoAnd, so we extract and return the info/hash. writePatchIfNecessary :: RepoPatch p => Cache -> Compression -> PatchInfoAnd rt p wX wY -> IO InventoryEntry writePatchIfNecessary c compr hp = infohp `seq` case extractHash hp of Right h -> return (infohp, mkValidHash h) Left p -> do h <- writeHashFile c compr HashedPatchesDir (showPatch ForStorage p) return (infohp, mkValidHash h) where infohp = info hp -- |listInventoriesWith returns a list of the inventories hashes. -- The first argument is to choose directory format. -- The first argument can be readInventoryPrivate or readInventoryLocalPrivate. -- The second argument specifies whether the files are expected -- to be stored in plain or in bucketed format. -- The third argument is the directory of the parent inventory files. -- The fourth argument is the directory of the head inventory file. listInventoriesWith :: (FilePath -> IO Inventory) -> DirLayout -> String -> String -> IO [String] listInventoriesWith readInv dirformat baseDir startDir = do mbStartingWithInv <- getStartingWithHash startDir hashedInventory followStartingWiths mbStartingWithInv where getStartingWithHash dir file = inventoryParent <$> readInv (dir file) invDir = baseDir inventoriesDir nextDir dir = case dirformat of BucketedLayout -> invDir bucketFolder dir PlainLayout -> invDir followStartingWiths Nothing = return [] followStartingWiths (Just hash) = do let startingWith = getValidHash hash mbNextInv <- getStartingWithHash (nextDir startingWith) startingWith (startingWith :) <$> followStartingWiths mbNextInv -- |listInventories returns a list of the inventories hashes. -- This function attempts to retrieve missing inventory files. listInventories :: IO [String] listInventories = listInventoriesWith readInventoryPrivate PlainLayout darcsdir darcsdir -- | Read the given inventory file if it exist, otherwise return an empty -- inventory. Used when we expect that some inventory files may be missing. readInventoryLocalPrivate :: FilePath -> IO Inventory readInventoryLocalPrivate path = do b <- doesFileExist path if b then readInventoryPrivate path else return emptyInventory -- | Return inventories hashes by following the head inventory. -- This function does not attempt to retrieve missing inventory files. listInventoriesLocal :: IO [String] listInventoriesLocal = listInventoriesWith readInventoryLocalPrivate PlainLayout darcsdir darcsdir -- |listInventoriesRepoDir returns a list of the inventories hashes. -- The argument @repoDir@ is the directory of the repository from which -- we are going to read the head inventory file. -- The rest of hashed files are read from the global cache. listInventoriesRepoDir :: String -> IO [String] listInventoriesRepoDir repoDir = do gCacheDir' <- globalCacheDir let gCacheInvDir = fromJust gCacheDir' listInventoriesWith readInventoryLocalPrivate BucketedLayout gCacheInvDir (repoDir darcsdir) -- | Return a list of the patch filenames, extracted from inventory -- files, by starting with the head inventory and then following the -- chain of parent inventories. -- -- This function does not attempt to download missing inventory files. -- -- * The first argument specifies whether the files are expected -- to be stored in plain or in bucketed format. -- * The second argument is the directory of the parent inventory. -- * The third argument is the directory of the head inventory. listPatchesLocal :: DirLayout -> String -> String -> IO [String] listPatchesLocal dirformat baseDir startDir = do inventory <- readInventoryPrivate (startDir hashedInventory) followStartingWiths (inventoryParent inventory) (inventoryPatchNames inventory) where invDir = baseDir inventoriesDir nextDir dir = case dirformat of BucketedLayout -> invDir bucketFolder dir PlainLayout -> invDir followStartingWiths Nothing patches = return patches followStartingWiths (Just hash) patches = do let startingWith = getValidHash hash inv <- readInventoryLocalPrivate (nextDir startingWith startingWith) (patches++) <$> followStartingWiths (inventoryParent inv) (inventoryPatchNames inv) -- |listPatchesLocalBucketed is similar to listPatchesLocal, but -- it read the inventory directory under @darcsDir@ in bucketed format. listPatchesLocalBucketed :: String -> String -> IO [String] listPatchesLocalBucketed = listPatchesLocal BucketedLayout -- | copyPristine copies a pristine tree into the current pristine dir, -- and possibly copies a clean working copy. -- The target is read from the passed-in dir/inventory name combination. copyPristine :: Cache -> String -> String -> WithWorkingDir -> IO () copyPristine cache dir iname wwd = do i <- fetchFilePS (dir ++ "/" ++ iname) Uncachable debugMessage $ "Copying hashed pristine tree: " ++ peekPristineHash i let tediousName = "Copying pristine" beginTedious tediousName copyHashed tediousName cache wwd $ peekPristineHash i endTedious tediousName -- |copyPartialsPristine copies the pristine entries for a given list of -- filepaths. copyPartialsPristine :: FilePathLike fp => Cache -> String -> String -> [fp] -> IO () copyPartialsPristine c d iname fps = do i <- fetchFilePS (d ++ "/" ++ iname) Uncachable copyPartialsHashed c (peekPristineHash i) fps unrevertUrl :: Repository rt p wR wU wT -> String unrevertUrl r = repoLocation r ++ "/"++darcsdir++"/patches/unrevert" tentativelyAddPatch :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> Compression -> Verbosity -> UpdateWorking -> PatchInfoAnd rt p wT wY -> IO (Repository rt p wR wU wY) tentativelyAddPatch = tentativelyAddPatch_ UpdatePristine data UpdatePristine = UpdatePristine | DontUpdatePristine | DontUpdatePristineNorRevert deriving Eq tentativelyAddPatches_ :: (RepoPatch p, ApplyState p ~ Tree) => UpdatePristine -> Repository rt p wR wU wT -> Compression -> Verbosity -> UpdateWorking -> FL (PatchInfoAnd rt p) wT wY -> IO (Repository rt p wR wU wY) tentativelyAddPatches_ up r c v uw ps = foldFL_M (\r' p -> tentativelyAddPatch_ up r' c v uw p) r ps -- TODO re-add a safety catch for --dry-run? Maybe using a global, like dryRun -- :: Bool, with dryRun = unsafePerformIO $ readIORef ... tentativelyAddPatch_ :: (RepoPatch p, ApplyState p ~ Tree) => UpdatePristine -> Repository rt p wR wU wT -> Compression -> Verbosity -> UpdateWorking -> PatchInfoAnd rt p wT wY -> IO (Repository rt p wR wU wY) tentativelyAddPatch_ up r compr verb uw p = withRepoLocation r $ do void $ addToTentativeInventory (repoCache r) compr p when (up == UpdatePristine) $ do debugMessage "Applying to pristine cache..." applyToTentativePristine r verb p debugMessage "Updating pending..." tentativelyRemoveFromPending r uw p return (coerceT r) -- |applyToTentativePristine applies a patch @p@ to the tentative pristine -- tree, and updates the tentative pristine hash applyToTentativePristine :: (ApplyState q ~ Tree, Apply q, ShowPatch q) => Repository rt p wR wU wT -> Verbosity -> q wT wY -> IO () applyToTentativePristine r verb p = withRepoLocation r $ do when (verb == Verbose) $ putDocLn $ text "Applying to pristine..." <+> description p applyToTentativePristineCwd p applyToTentativePristineCwd :: (ApplyState p ~ Tree, Apply p) => p wX wY -> IO () applyToTentativePristineCwd p = do tentativePristine <- gzReadFilePS tentativePristinePath -- Extract the pristine hash from the tentativePristine file, using -- peekPristineHash (this is valid since we normally just extract the hash from the -- first line of an inventory file; we can pass in a one-line file that -- just contains said hash). let tentativePristineHash = peekPristineHash tentativePristine newPristineHash <- applyToHashedPristine tentativePristineHash p writeDocBinFile tentativePristinePath $ pokePristineHash newPristineHash tentativePristine tentativelyRemovePatches :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> Compression -> UpdateWorking -> FL (PatchInfoAnd rt p) wX wT -> IO (Repository rt p wR wU wX) tentativelyRemovePatches = tentativelyRemovePatches_ UpdatePristine tentativelyRemovePatches_ :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => UpdatePristine -> Repository rt p wR wU wT -> Compression -> UpdateWorking -> FL (PatchInfoAnd rt p) wX wT -> IO (Repository rt p wR wU wX) tentativelyRemovePatches_ up r compr uw ps = withRepoLocation r $ do when (up == UpdatePristine) $ do debugMessage "Adding changes to pending..." prepend r uw $ effect ps unless (up == DontUpdatePristineNorRevert) $ removeFromUnrevertContext r ps debugMessage "Removing changes from tentative inventory..." if formatHas HashedInventory (repoFormat r) then do removeFromTentativeInventory r compr ps when (up == UpdatePristine) $ applyToTentativePristineCwd $ progressFL "Applying inverse to pristine" $ invert ps else fail Old.oldRepoFailMsg return (coerceT r) -- FIXME this is a rather weird API. If called with a patch that isn't already -- in the repo, it fails with an obscure error from 'commuteToEnd'. It also -- ends up redoing the work that the caller has already done - if it has -- already commuted these patches to the end, it must also know the commuted -- versions of the other patches in the repo. -- |Given a sequence of patches anchored at the end of the current repository, -- actually pull them to the end of the repository by removing any patches -- with the same name and then adding the passed in sequence. -- Typically callers will have obtained the passed in sequence using -- 'findCommon' and friends. tentativelyReplacePatches :: forall rt p wR wU wT wX . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> Compression -> UpdateWorking -> Verbosity -> FL (PatchInfoAnd rt p) wX wT -> IO () tentativelyReplacePatches repository compr uw verb ps = do let ps' = filterOutFLFL (namedIsInternal . hopefully) ps repository' <- tentativelyRemovePatches_ DontUpdatePristineNorRevert repository compr uw ps' mapAdd repository' ps' where mapAdd :: Repository rt p wM wL wI -> FL (PatchInfoAnd rt p) wI wJ -> IO () mapAdd _ NilFL = return () mapAdd r (a:>:as) = do r' <- tentativelyAddPatch_ DontUpdatePristine r compr verb uw a mapAdd r' as -- The type here should rather be -- ... -> Repo rt p wR wU wT -> IO (Repo rt p wT wU wT) -- In other words: we set the recorded state to the tentative state. finalizeRepositoryChanges :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> UpdateWorking -> Compression -> IO () finalizeRepositoryChanges r updateWorking compr | formatHas HashedInventory (repoFormat r) = withRepoLocation r $ do debugMessage "Finalizing changes..." withSignalsBlocked $ do finalizeTentativeChanges r compr recordedState <- readRecorded r finalizePending r updateWorking recordedState debugMessage "Done finalizing changes..." ps <- readRepo r doesPatchIndexExist (repoLocation r) >>= (`when` createOrUpdatePatchIndexDisk r ps) updateIndex r | otherwise = fail Old.oldRepoFailMsg -- TODO: rename this and document the transaction protocol (revert/finalize) -- clearly. -- |Slightly confusingly named: as well as throwing away any tentative -- changes, revertRepositoryChanges also re-initialises the tentative state. -- It's therefore used before makign any changes to the repo. -- So the type should rather be -- -- > ... -> Repo rt p wR wU wT -> IO (Repo rt p wR wU wR) revertRepositoryChanges :: RepoPatch p => Repository rt p wR wU wT -> UpdateWorking -> IO () revertRepositoryChanges r uw | formatHas HashedInventory (repoFormat r) = withRepoLocation r $ do removeFileMayNotExist (pendingName ++ ".tentative") Sealed x <- readPending r setTentativePending r uw x when (uw == NoUpdateWorking) $ removeFileMayNotExist pendingName revertTentativeChanges | otherwise = fail Old.oldRepoFailMsg removeFromUnrevertContext :: forall rt p wR wU wT wX . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> FL (PatchInfoAnd rt p) wX wT -> IO () removeFromUnrevertContext r ps = do Sealed bundle <- unrevert_patch_bundle `catchall` return (seal (PatchSet NilRL NilRL)) remove_from_unrevert_context_ bundle where unrevert_impossible = do confirmed <- promptYorn "This operation will make unrevert impossible!\nProceed?" if confirmed then removeFileMayNotExist (unrevertUrl r) else fail "Cancelled." unrevert_patch_bundle :: IO (SealedPatchSet rt p Origin) unrevert_patch_bundle = do pf <- B.readFile (unrevertUrl r) case scanBundle pf of Right foo -> return foo Left err -> fail $ "Couldn't parse unrevert patch:\n" ++ err remove_from_unrevert_context_ :: PatchSet rt p Origin wZ -> IO () remove_from_unrevert_context_ (PatchSet NilRL NilRL) = return () remove_from_unrevert_context_ bundle = do debugMessage "Adjusting the context of the unrevert changes..." debugMessage $ "Removing "++ show (lengthFL ps) ++ " patches in removeFromUnrevertContext!" ref <- readTentativeRepo r (repoLocation r) let withSinglet :: Sealed (FL ppp wXxx) -> (forall wYyy . ppp wXxx wYyy -> IO ()) -> IO () withSinglet (Sealed (x :>: NilFL)) j = j x withSinglet _ _ = return () withSinglet (mergeThem ref bundle) $ \h_us -> case commuteRL (reverseFL ps :> h_us) of Nothing -> unrevert_impossible Just (us' :> _) -> case removeFromPatchSet ps ref of Nothing -> unrevert_impossible Just common -> do debugMessage "Have now found the new context..." bundle' <- makeBundleN Nothing common (hopefully us':>:NilFL) writeDocBinFile (unrevertUrl r) bundle' debugMessage "Done adjusting the context of the unrevert changes!" cleanRepository :: Repository rt p wR wU wT -> IO () cleanRepository r = cleanPristine r >> cleanInventories r >> cleanPatches r -- | grab the pristine hash of _darcs/hash_inventory, and retrieve whole pristine tree, -- possibly writing a clean working copy in the process. createPristineDirectoryTree :: Repository rt p wR wU wT -> FilePath -> WithWorkingDir -> IO () createPristineDirectoryTree r reldir wwd | formatHas HashedInventory (repoFormat r) = do createDirectoryIfMissing True reldir withCurrentDirectory reldir $ copyPristine (repoCache r) (repoLocation r) hashedInventoryPath wwd | otherwise = fail Old.oldRepoFailMsg -- fp below really should be FileName -- | Used by the commands dist and diff createPartialsPristineDirectoryTree :: (FilePathLike fp) => Repository rt p wR wU wT -> [fp] -> FilePath -> IO () createPartialsPristineDirectoryTree r prefs dir | formatHas HashedInventory (repoFormat r) = do createDirectoryIfMissing True dir withCurrentDirectory dir $ copyPartialsPristine (repoCache r) (repoLocation r) hashedInventoryPath prefs | otherwise = fail Old.oldRepoFailMsg withRecorded :: Repository rt p wR wU wT -> ((AbsolutePath -> IO a) -> IO a) -> (AbsolutePath -> IO a) -> IO a withRecorded repository mk_dir f = mk_dir $ \d -> do createPristineDirectoryTree repository (toFilePath d) WithWorkingDir f d withTentative :: forall rt p a wR wU wT. Repository rt p wR wU wT -> ((AbsolutePath -> IO a) -> IO a) -> (AbsolutePath -> IO a) -> IO a withTentative r mk_dir f | formatHas HashedInventory (repoFormat r) = mk_dir $ \d -> do copyPristine (repoCache r) (repoLocation r) (darcsdir++"/tentative_pristine") WithWorkingDir f d | otherwise = fail Old.oldRepoFailMsg -- | Writes out a fresh copy of the inventory that minimizes the -- amount of inventory that need be downloaded when people pull from -- the repository. -- -- Specifically, it breaks up the inventory on the most recent tag. -- This speeds up most commands when run remotely, both because a -- smaller file needs to be transfered (only the most recent -- inventory). It also gives a guarantee that all the patches prior -- to a given tag are included in that tag, so less commutation and -- history traversal is needed. This latter issue can become very -- important in large repositories. reorderInventory :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wR -> Compression -> UpdateWorking -> Verbosity -> IO () reorderInventory repository compr uw verb = do debugMessage "Reordering the inventory." PatchSet _ ps <- misplacedPatches `fmap` readRepo repository tentativelyReplacePatches repository compr uw verb $ reverseRL ps finalizeTentativeChanges repository compr debugMessage "Done reordering the inventory." -- | Returns the patches that make the most recent tag dirty. misplacedPatches :: forall rt p wS wX . RepoPatch p => PatchSet rt p wS wX -> PatchSet rt p wS wX misplacedPatches ps = -- Filter the repository keeping only with the tags, ordered from the -- most recent. case filter isTag $ mapRL info $ patchSet2RL ps of [] -> ps (lt:_) -> -- Take the most recent tag, and split the repository in, -- the clean PatchSet "up to" the tag (ts), and a RL of -- patches after the tag (r). case splitOnTag lt ps of Just (PatchSet ts xs :> r) -> PatchSet ts (xs+<+r) _ -> impossible -- Because the tag is in ps. -- @todo: we should not have to open the result of HashedRepo and -- seal it. Instead, update this function to work with type witnesses -- by fixing DarcsRepo to match HashedRepo in the handling of -- Repository state. readRepo :: (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wT -> IO (PatchSet rt p Origin wR) readRepo r | formatHas HashedInventory (repoFormat r) = readRepoHashed r (repoLocation r) | otherwise = do Sealed ps <- Old.readOldRepo (repoLocation r) return $ unsafeCoerceP ps -- | XOR of all hashes of the patches' metadata. -- It enables to quickly see whether two repositories -- have the same patches, independently of their order. -- It relies on the assumption that the same patch cannot -- be present twice in a repository. -- This checksum is not cryptographically secure, -- see http://robotics.stanford.edu/~xb/crypto06b/ . repoXor :: (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wR -> IO SHA1 repoXor repo = do hashes <- mapRL (makePatchname . info) . patchSet2RL <$> readRepo repo return $ foldl' sha1Xor sha1zero hashes darcs-2.14.5/src/Darcs/Repository/HashedIO.hs0000644000000000000000000003576207346545000017067 0ustar0000000000000000-- Copyright (C) 2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. {-# OPTIONS_GHC -fno-warn-missing-methods #-} {-# LANGUAGE MultiParamTypeClasses #-} module Darcs.Repository.HashedIO ( copyHashed, copyPartialsHashed, cleanHashdir, getHashedFiles, pathsAndContents ) where import Prelude () import Darcs.Prelude import Darcs.Util.Global ( darcsdir ) import qualified Data.Set as Set import System.Directory ( getDirectoryContents, createDirectoryIfMissing ) import Control.Monad.State ( StateT, runStateT, modify, get, put, gets, lift, evalStateT ) import Control.Monad ( when, void, unless ) import Data.Maybe ( isJust ) import System.IO.Unsafe ( unsafeInterleaveIO ) import Darcs.Repository.Cache ( Cache(..), fetchFileUsingCache, writeFileUsingCache, peekInCache, speculateFileUsingCache, okayHash, cleanCachesWithHint, HashedDir(..), hashedDir ) import Darcs.Patch.ApplyMonad ( ApplyMonad(..), ApplyMonadTree(..) ) import Darcs.Repository.Flags ( Compression( .. ), WithWorkingDir (..) ) import Darcs.Util.Lock ( writeAtomicFilePS, removeFileMayNotExist ) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Progress ( debugMessage, tediousSize, finishedOneIO ) import Darcs.Util.Path ( FileName , normPath , fp2fn , fn2fp , fn2ps , ps2fn , breakOnDir , ownName , superName , FilePathLike , toFilePath , isMaliciousSubPath ) import Darcs.Util.ByteString ( linesPS, unlinesPS ) import qualified Data.ByteString as B (ByteString, length, empty) import qualified Data.ByteString.Char8 as BC (unpack, pack) import Darcs.Util.Tree.Hashed( readDarcsHashedDir, darcsLocation, decodeDarcsHash, decodeDarcsSize ) import Darcs.Util.Tree( ItemType(..), Tree ) -- | @readHashFile c subdir hash@ reads the file with hash @hash@ in dir subdir, -- fetching it from 'Cache' @c@ if needed. readHashFile :: Cache -> HashedDir -> String -> IO (String,B.ByteString) readHashFile c subdir hash = do debugMessage $ "Reading hash file "++hash++" from "++hashedDir subdir++"/" r <- fetchFileUsingCache c subdir hash debugMessage $ "Result of reading hash file: " ++ show r return r data HashDir = HashDir { cache :: !Cache, rootHash :: !String } type HashedIO = StateT HashDir IO mWithCurrentDirectory :: FileName -> HashedIO a -> HashedIO a mWithCurrentDirectory fn j | fn' == fp2fn "" = j | otherwise = case breakOnDir fn' of Nothing -> do c <- readroot case geta D fn' c of Nothing -> fail "dir doesn't exist in mWithCurrentDirectory..." Just h -> do (h',x) <- withh h j writeroot $ seta D fn' h' c return x Just (d,fn'') -> do c <- readroot case geta D d c of Nothing -> fail "dir doesn't exist..." Just h -> do (h',x) <- withh h $ mWithCurrentDirectory fn'' j writeroot $ seta D d h' c return x where fn' = normPath fn mInCurrentDirectory :: FileName -> HashedIO a -> HashedIO a mInCurrentDirectory fn j | fn' == fp2fn "" = j | otherwise = case breakOnDir fn' of Nothing -> do c <- readroot case geta D fn' c of Nothing -> fail "dir doesn't exist mInCurrentDirectory..." Just h -> inh h j Just (d,fn'') -> do c <- readroot case geta D d c of Nothing -> fail "dir doesn't exist..." Just h -> inh h $ mInCurrentDirectory fn'' j where fn' = normPath fn instance ApplyMonad Tree HashedIO where type ApplyMonadBase HashedIO = IO instance ApplyMonadTree HashedIO where mDoesDirectoryExist fn = do thing <- identifyThing fn case thing of Just (D,_) -> return True _ -> return False mReadFilePS fn = mInCurrentDirectory (superName fn) $ do c <- readroot case geta F (ownName fn) c of Nothing -> fail $ " file don't exist... "++ fn2fp fn Just h -> readhash h mCreateDirectory fn = do h <- writeHashFile B.empty exists <- isJust `fmap` identifyThing fn when exists $ fail "can't mCreateDirectory over an existing object." makeThing fn (D,h) mRename o n = do nexists <- isJust `fmap` identifyThing n when nexists $ fail "mRename failed..." mx <- identifyThing o -- for backwards compatibility accept rename of nonexistent files. case mx of Nothing -> return () Just x -> do rmThing o makeThing n x mRemoveDirectory = rmThing mRemoveFile f = do x <- mReadFilePS f when (B.length x /= 0) $ fail $ "Cannot remove non-empty file "++fn2fp f rmThing f identifyThing :: FileName -> HashedIO (Maybe (ObjType,String)) identifyThing fn | fn' == fp2fn "" = do h <- gets rootHash return $ Just (D, h) | otherwise = case breakOnDir fn' of Nothing -> getany fn' `fmap` readroot Just (d,fn'') -> do c <- readroot case geta D d c of Nothing -> return Nothing Just h -> inh h $ identifyThing fn'' where fn' = normPath fn makeThing :: FileName -> (ObjType,String) -> HashedIO () makeThing fn (o,h) = mWithCurrentDirectory (superName $ normPath fn) $ seta o (ownName $ normPath fn) h `fmap` readroot >>= writeroot rmThing :: FileName -> HashedIO () rmThing fn = mWithCurrentDirectory (superName $ normPath fn) $ do c <- readroot let c' = filter (\(_,x,_)->x/= ownName (normPath fn)) c if length c' == length c - 1 then writeroot c' else fail "obj doesn't exist in rmThing" readhash :: String -> HashedIO B.ByteString readhash h = do c <- gets cache z <- lift $ unsafeInterleaveIO $ readHashFile c HashedPristineDir h let (_,out) = z return out withh :: String -> HashedIO a -> HashedIO (String,a) withh h j = do hd <- get put $ hd { rootHash = h } x <- j h' <- gets rootHash put hd return (h',x) inh :: String -> HashedIO a -> HashedIO a inh h j = snd `fmap` withh h j readroot :: HashedIO [(ObjType, FileName, String)] readroot = do haveitalready <- peekroot cc <- gets rootHash >>= readdir unless haveitalready $ speculate cc return cc where speculate :: [(a,b,String)] -> HashedIO () speculate c = do cac <- gets cache mapM_ (\(_,_,z) -> lift $ speculateFileUsingCache cac HashedPristineDir z) c peekroot :: HashedIO Bool peekroot = do HashDir c h <- get lift $ peekInCache c HashedPristineDir h writeroot :: [(ObjType, FileName, String)] -> HashedIO () writeroot c = do h <- writedir c modify $ \hd -> hd { rootHash = h } data ObjType = F | D deriving Eq -- | @geta objtype name stuff@ tries to get an object of type @objtype@ named @name@ -- in @stuff@. geta :: ObjType -> FileName -> [(ObjType, FileName, String)] -> Maybe String geta o f c = do (o',h) <- getany f c if o == o' then Just h else Nothing getany :: FileName -> [(ObjType, FileName, String)] -> Maybe (ObjType,String) getany _ [] = Nothing getany f ((o,f',h):_) | f == f' = Just (o,h) getany f (_:r) = getany f r seta :: ObjType -> FileName -> String -> [(ObjType, FileName, String)] -> [(ObjType, FileName, String)] seta o f h [] = [(o,f,h)] seta o f h ((_,f',_):r) | f == f' = (o,f,h):r seta o f h (x:xs) = x : seta o f h xs readdir :: String -> HashedIO [(ObjType, FileName, String)] readdir hash = do x <- readhash hash lift $ debugMessage $ show x let r = (parsed . linesPS) x lift $ debugMessage $ unlines $ map (\(_,fn,_) -> "DEBUG readdir " ++ hash ++ " entry: " ++ show fn) r return r where parsed (t:n:h:rest) | t == dir = (D, ps2fn n, BC.unpack h) : parsed rest | t == file = (F, ps2fn n, BC.unpack h) : parsed rest parsed _ = [] dir :: B.ByteString dir = BC.pack "directory:" file :: B.ByteString file = BC.pack "file:" writedir :: [(ObjType, FileName, String)] -> HashedIO String writedir c = do lift $ debugMessage $ unlines $ map (\(_,fn,_) -> "DEBUG writedir entry: " ++ show fn) c writeHashFile cps where cps = unlinesPS $ concatMap wr c ++ [B.empty] wr (o,d,h) = [showO o,fn2ps d,BC.pack h] showO D = dir showO F = file writeHashFile :: B.ByteString -> HashedIO String writeHashFile ps = do c <- gets cache -- pristine files are always compressed lift $ writeFileUsingCache c GzipCompression HashedPristineDir ps -- | Grab a whole pristine tree from a hash, and, if asked, -- write files in the working copy. copyHashed :: String -> Cache -> WithWorkingDir -> String -> IO () copyHashed k c wwd z = void . runStateT cph $ HashDir { cache = c, rootHash = z } where cph = do cc <- readroot lift $ tediousSize k (length cc) mapM_ cp cc cp (F,n,h) = do ps <- readhash h lift $ finishedOneIO k (fn2fp n) lift $ debugMessage $ "DEBUG copyHashed " ++ show n case wwd of WithWorkingDir -> lift $ writeAtomicFilePS (fn2fp n) ps NoWorkingDir -> ps `seq` return () -- force evaluation of ps to actually copy hashed file cp (D,n,h) = if isMaliciousSubPath (fn2fp n) then fail ("Caught malicious path: " ++ fn2fp n) else do lift $ finishedOneIO k (fn2fp n) case wwd of WithWorkingDir -> do lift $ createDirectoryIfMissing False (fn2fp n) lift $ withCurrentDirectory (fn2fp n) $ copyHashed k c WithWorkingDir h NoWorkingDir -> lift $ copyHashed k c NoWorkingDir h -- | Returns a list of pairs (FilePath, (strict) ByteString) of -- the pristine tree starting with the hash @root@. -- @path@ should be either "." or end with "/" -- Separator "/" is used since this function is used to generate -- zip archives from pristine trees. pathsAndContents :: FilePath -> Cache -> String -> IO [(FilePath,B.ByteString)] pathsAndContents path c root = evalStateT cph HashDir { cache = c, rootHash = root } where cph = do cc <- readroot pacs <- concat <$> mapM cp cc let current = if path == "." then [] else [(path ++ "/" , B.empty)] return $ current ++ pacs cp (F,n,h) = do ps <- readhash h let p = (if path == "." then "" else path ++ "/") ++ fn2fp n return [(p,ps)] cp (D,n,h) = do let p = (if path == "." then "" else path) ++ fn2fp n ++ "/" lift $ pathsAndContents p c h copyPartialsHashed :: FilePathLike fp => Cache -> String -> [fp] -> IO () copyPartialsHashed c root = mapM_ (copyPartialHashed c root) copyPartialHashed :: FilePathLike fp => Cache -> String -> fp -> IO () copyPartialHashed c root ff = do createDirectoryIfMissing True (basename $ toFilePath ff) void $ runStateT (cp $ fp2fn $ toFilePath ff) HashDir { cache = c, rootHash = root } where basename = reverse . dropWhile ('/' /=) . dropWhile ('/' ==) . reverse cp f = do mt <- identifyThing f case mt of Just (D,h) -> do lift $ createDirectoryIfMissing True (fn2fp f) lift $ withCurrentDirectory (fn2fp f) $ copyHashed "" c WithWorkingDir h Just (F,h) -> do ps <- readhash h lift $ writeAtomicFilePS (fn2fp f) ps Nothing -> return () cleanHashdir :: Cache -> HashedDir -> [String] -> IO () cleanHashdir c dir_ hashroots = do -- we'll remove obsolete bits of "dir" debugMessage $ "Cleaning out " ++ hashedDir dir_ ++ "..." let hashdir = darcsdir ++ "/" ++ hashedDir dir_ ++ "/" hs <- set <$> getHashedFiles hashdir hashroots fs <- set . filter okayHash <$> getDirectoryContents hashdir mapM_ (removeFileMayNotExist . (hashdir++)) (unset $ fs `Set.difference` hs) -- and also clean out any global caches. debugMessage "Cleaning out any global caches..." cleanCachesWithHint c dir_ (unset $ fs `Set.difference` hs) where set = Set.fromList . map BC.pack unset = map BC.unpack . Set.toList -- | getHashedFiles returns all hash files targeted by files in hashroots in -- the hashdir directory. getHashedFiles :: String -> [String] -> IO [String] getHashedFiles hashdir hashroots = do let listone h = do let size = decodeDarcsSize $ BC.pack h hash = decodeDarcsHash $ BC.pack h x <- readDarcsHashedDir hashdir (size, hash) let subs = [ fst $ darcsLocation "" (s, h') | (TreeType, _, s, h') <- x ] hashes = h : [ fst $ darcsLocation "" (s, h') | (_, _, s, h') <- x ] (hashes++) . concat <$> mapM listone subs concat <$> mapM listone hashroots darcs-2.14.5/src/Darcs/Repository/Identify.hs0000644000000000000000000002164307346545000017207 0ustar0000000000000000{-| License : GPL-2 A set of functions to identify and find Darcs repositories from a given @URL@ or a given filesystem path. -} module Darcs.Repository.Identify ( maybeIdentifyRepository , identifyRepository , identifyRepositoryFor , IdentifyRepo(..) , findRepository , amInRepository , amNotInRepository , amInHashedRepository , seekRepo , findAllReposInDir ) where import Prelude () import Darcs.Prelude import Control.Monad ( forM ) import Darcs.Repository.Format ( tryIdentifyRepoFormat , readProblem , transferProblem ) import System.Directory ( doesDirectoryExist , setCurrentDirectory , createDirectoryIfMissing , doesFileExist , getDirectoryContents ) import System.FilePath.Posix ( () ) import System.IO.Error ( catchIOError ) import Data.Maybe ( fromMaybe ) import Darcs.Repository.Old ( oldRepoFailMsg ) import Darcs.Repository.Flags ( UseCache(..), WorkRepo (..) ) import Darcs.Util.Path ( toFilePath , ioAbsoluteOrRemote , toPath ) import Darcs.Util.Exception ( catchall ) import Darcs.Util.URL ( isValidLocalPath ) import Darcs.Util.Workaround ( getCurrentDirectory ) import Darcs.Repository.Prefs ( getCaches ) import Darcs.Repository.InternalTypes( Repository , PristineType(..) , mkRepo , repoFormat , repoPristineType ) import Darcs.Util.Global ( darcsdir ) import System.Mem( performGC ) -- | The status of a given directory: is it a darcs repository? data IdentifyRepo rt p wR wU wT = BadRepository String -- ^ looks like a repository with some error | NonRepository String -- ^ safest guess | GoodRepository (Repository rt p wR wU wT) -- | Tries to identify the repository in a given directory maybeIdentifyRepository :: UseCache -> String -> IO (IdentifyRepo rt p wR wU wT) maybeIdentifyRepository useCache "." = do darcs <- doesDirectoryExist darcsdir if not darcs then return (NonRepository $ "Missing " ++ darcsdir ++ " directory") else do repoFormatOrError <- tryIdentifyRepoFormat "." here <- toPath `fmap` ioAbsoluteOrRemote "." case repoFormatOrError of Left err -> return $ NonRepository err Right rf -> case readProblem rf of Just err -> return $ BadRepository err Nothing -> do pris <- identifyPristine cs <- getCaches useCache here return $ GoodRepository $ mkRepo here rf pris cs maybeIdentifyRepository useCache url' = do url <- toPath `fmap` ioAbsoluteOrRemote url' repoFormatOrError <- tryIdentifyRepoFormat url case repoFormatOrError of Left e -> return $ NonRepository e Right rf -> case readProblem rf of Just err -> return $ BadRepository err Nothing -> do cs <- getCaches useCache url return $ GoodRepository $ mkRepo url rf NoPristine cs identifyPristine :: IO PristineType identifyPristine = do pristine <- doesDirectoryExist $ darcsdir++"/pristine" current <- doesDirectoryExist $ darcsdir++"/current" hashinv <- doesFileExist $ darcsdir++"/hashed_inventory" case (pristine || current, hashinv) of (False, False) -> return NoPristine (True, False) -> return PlainPristine (False, True ) -> return HashedPristine _ -> fail "Multiple pristine trees." -- | identifyRepository identifies the repo at 'url'. Warning: -- you have to know what kind of patches are found in that repo. identifyRepository :: forall rt p wR wU wT. UseCache -> String -> IO (Repository rt p wR wU wT) identifyRepository useCache url = do er <- maybeIdentifyRepository useCache url case er of BadRepository s -> fail s NonRepository s -> fail s GoodRepository r -> return r -- | @identifyRepositoryFor repo url@ identifies (and returns) the repo at 'url', -- but fails if it is not compatible for reading from and writing to. identifyRepositoryFor :: forall rt p wR wU wT vR vU vT. Repository rt p wR wU wT -> UseCache -> String -> IO (Repository rt p vR vU vT) identifyRepositoryFor source useCache url = do target <- identifyRepository useCache url case transferProblem (repoFormat target) (repoFormat source) of Just e -> fail $ "Incompatibility with repository " ++ url ++ ":\n" ++ e Nothing -> return target amInRepository :: WorkRepo -> IO (Either String ()) amInRepository (WorkRepoDir d) = do setCurrentDirectory d status <- maybeIdentifyRepository YesUseCache "." case status of GoodRepository _ -> return (Right ()) BadRepository e -> return (Left $ "While " ++ d ++ " looks like a repository directory, we have a problem with it:\n" ++ e) NonRepository _ -> return (Left "You need to be in a repository directory to run this command.") `catchIOError` \e -> return (Left (show e)) amInRepository _ = fromMaybe (Left "You need to be in a repository directory to run this command.") <$> seekRepo amInHashedRepository :: WorkRepo -> IO (Either String ()) amInHashedRepository wd = do inrepo <- amInRepository wd case inrepo of Right _ -> do pristine <- identifyPristine case pristine of HashedPristine -> return (Right ()) _ -> return (Left oldRepoFailMsg) left -> return left -- | hunt upwards for the darcs repository -- This keeps changing up one parent directory, testing at each -- step if the current directory is a repository or not. $ -- The result is: -- Nothing, if no repository found -- Just (Left errorMessage), if bad repository found -- Just (Right ()), if good repository found. -- WARNING this changes the current directory for good if matchFn succeeds seekRepo :: IO (Maybe (Either String ())) seekRepo = getCurrentDirectory >>= helper where helper startpwd = do status <- maybeIdentifyRepository YesUseCache "." case status of GoodRepository _ -> return . Just $ Right () BadRepository e -> return . Just $ Left e NonRepository _ -> do cd <- toFilePath `fmap` getCurrentDirectory setCurrentDirectory ".." cd' <- toFilePath `fmap` getCurrentDirectory if cd' /= cd then helper startpwd else do setCurrentDirectory startpwd return Nothing -- The performGC in this function is a workaround for a library/GHC bug, -- http://hackage.haskell.org/trac/ghc/ticket/2924 -- (doesn't seem to be a -- problem on fast machines, but virtual ones trip this from time to time) amNotInRepository :: WorkRepo -> IO (Either String ()) amNotInRepository (WorkRepoDir d) = do createDirectoryIfMissing False d `catchall` (performGC >> createDirectoryIfMissing False d) -- note that the above could always fail setCurrentDirectory d amNotInRepository WorkRepoCurrentDir amNotInRepository _ = do status <- maybeIdentifyRepository YesUseCache "." case status of GoodRepository _ -> return (Left "You may not run this command in a repository.") BadRepository e -> return (Left $ "You may not run this command in a repository.\nBy the way, we have a problem with it:\n" ++ e) NonRepository _ -> return (Right ()) findRepository :: WorkRepo -> IO (Either String ()) findRepository workrepo = case workrepo of WorkRepoPossibleURL d | isValidLocalPath d -> do setCurrentDirectory d findRepository WorkRepoCurrentDir WorkRepoDir d -> do setCurrentDirectory d findRepository WorkRepoCurrentDir _ -> fromMaybe (Right ()) <$> seekRepo `catchIOError` \e -> return (Left (show e)) -- | @findAllReposInDir topDir@ returns all paths to repositories under @topDir@. findAllReposInDir :: FilePath -> IO [FilePath] findAllReposInDir topDir = do isDir <- doesDirectoryExist topDir if isDir then do status <- maybeIdentifyRepository NoUseCache topDir case status of GoodRepository repo | HashedPristine <- repoPristineType repo -> return [topDir] | otherwise -> return [] -- old fashioned or broken repo _ -> getRecursiveDarcsRepos' topDir else return [] where getRecursiveDarcsRepos' d = do names <- getDirectoryContents d let properNames = filter (\x -> head x /= '.') names paths <- forM properNames $ \name -> do let path = d name findAllReposInDir path return (concat paths) darcs-2.14.5/src/Darcs/Repository/InternalTypes.hs0000644000000000000000000000727607346545000020243 0ustar0000000000000000-- Copyright (C) 2006-2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. module Darcs.Repository.InternalTypes ( Repository, PristineType(..) , repoCache, modifyCache , repoPatchType , repoFormat , repoLocation , withRepoLocation , repoPristineType , coerceR , coerceU , coerceT , mkRepo ) where import Prelude () import Darcs.Prelude import Data.Coerce ( coerce ) import Data.List ( nub, sortBy ) import Darcs.Repository.Cache ( Cache (..) , compareByLocality ) import Darcs.Repository.Format ( RepoFormat ) import Darcs.Patch ( RepoType ) import Darcs.Patch.Type ( PatchType(..) ) import Darcs.Util.File ( withCurrentDirectory ) data PristineType = NoPristine | PlainPristine | HashedPristine deriving ( Show, Eq ) -- |A @Repository@ is a token representing the state of a repository on disk. -- It is parameterized by the patch type in the repository, and witnesses for -- the recorded state of the repository (i.e. what darcs get would retrieve), -- the unrecorded state (what's in the working directory now), -- and the tentative state, which represents work in progress that will -- eventually become the new recorded state unless something goes wrong. data Repository (rt :: RepoType) (p :: * -> * -> *) wRecordedstate wUnrecordedstate wTentativestate = Repo !String !RepoFormat !PristineType Cache deriving ( Show ) repoLocation :: Repository rt p wR wU wT -> String repoLocation (Repo loc _ _ _) = loc withRepoLocation :: Repository rt p wR wU wT -> IO a -> IO a withRepoLocation repo = withCurrentDirectory (repoLocation repo) repoFormat :: Repository rt p wR wU wT -> RepoFormat repoFormat (Repo _ fmt _ _) = fmt repoPristineType :: Repository rt p wR wU wT -> PristineType repoPristineType (Repo _ _ pr _) = pr repoCache :: Repository rt p wR wU wT -> Cache repoCache (Repo _ _ _ c) = c -- | 'modifyCache' @repository function@ modifies the cache of -- @repository@ with @function@, remove duplicates and sort the results with 'compareByLocality'. modifyCache :: forall rt p wR wU wT . Repository rt p wR wU wT -> (Cache -> Cache) -> Repository rt p wR wU wT modifyCache (Repo dir rf pristine cache) f = Repo dir rf pristine $ cmap ( sortBy compareByLocality . nub ) $ f cache where cmap g (Ca c) = Ca (g c) repoPatchType :: Repository rt p wR wU wT -> PatchType rt p repoPatchType _ = PatchType coerceR :: Repository rt p wR wU wT -> Repository rt p wR' wU wT coerceR = coerce coerceU :: Repository rt p wR wU wT -> Repository rt p wR wU' wT coerceU = coerce coerceT :: Repository rt p wR wU wT -> Repository rt p wR wU wT' coerceT = coerce mkRepo :: String -> RepoFormat -> PristineType -> Cache -> Repository rt p wR wU wT mkRepo = Repo darcs-2.14.5/src/Darcs/Repository/Inventory.hs0000644000000000000000000001513307346545000017426 0ustar0000000000000000module Darcs.Repository.Inventory ( Inventory(..) , HeadInventory , InventoryEntry , ValidHash(..) , InventoryHash , PatchHash , PristineHash , inventoryPatchNames , parseInventory , showInventory , showInventoryPatches , showInventoryEntry , emptyInventory , pokePristineHash , peekPristineHash , skipPristineHash , pristineName -- properties , prop_inventoryParseShow , prop_peekPokePristineHash , prop_skipPokePristineHash ) where import Prelude () import Darcs.Prelude hiding ( take ) import Control.Applicative ( optional, many ) import Control.Monad ( guard ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import Darcs.Patch.Info ( PatchInfo, showPatchInfo, readPatchInfo ) import Darcs.Patch.ReadMonads ( ParserM, parseStrictly, string, skipSpace, take, takeTillChar ) import Darcs.Patch.Show ( ShowPatchFor(..) ) import Darcs.Repository.Cache ( okayHash ) import Darcs.Util.Hash ( sha256sum ) import Darcs.Util.Printer ( Doc, (<+>), ($$), hcat, text, invisiblePS, packedString, renderPS ) -- * Hash validation -- TODO the ValidHash class and the newtypes for the various hashes -- really don't belong here. They should be moved to D.R.Cache or -- perhaps a separate module. Also, the validation should be extended -- see D.R.Cache.checkHash. class ValidHash a where getValidHash :: a -> String mkValidHash :: String -> a newtype InventoryHash = InventoryHash String deriving (Eq, Show) instance ValidHash InventoryHash where getValidHash (InventoryHash h) = h mkValidHash s | okayHash s = InventoryHash s | otherwise = error "Bad inventory hash!" newtype PatchHash = PatchHash String deriving (Eq, Show) instance ValidHash PatchHash where getValidHash (PatchHash h) = h mkValidHash s | okayHash s = PatchHash s | otherwise = error "Bad patch hash!" newtype PristineHash = PristineHash String deriving (Eq, Show) instance ValidHash PristineHash where getValidHash (PristineHash h) = h mkValidHash s | okayHash s = PristineHash s | otherwise = error "Bad pristine hash!" -- * Inventories -- Note: this type and the commented out parser combinators for it -- aren't actually used (except for testing). They are left here to -- serve as documentation for the API we would like to use but won't -- because of efficiency: we want to be able to access the pristine -- hash with forcing a complete parse of the head inventory. Thus we -- retain the lower-level peek/poke/skip API for the pristine hash. type HeadInventory = (PristineHash, Inventory) data Inventory = Inventory { inventoryParent :: Maybe InventoryHash , inventoryPatches :: [InventoryEntry] } deriving (Eq, Show) -- The 'String' is the (hashed) patch filename. type InventoryEntry = (PatchInfo, PatchHash) inventoryPatchNames :: Inventory -> [String] inventoryPatchNames = map (getValidHash . snd) . inventoryPatches emptyInventory :: Inventory emptyInventory = Inventory Nothing [] -- * Parsing {- parseHeadInventory :: B.ByteString -> Maybe HeadInventory parseHeadInventory = fmap fst . parse pHeadInv -} parseInventory :: B.ByteString -> Maybe Inventory parseInventory = fmap fst . parseStrictly pInv {- pHeadInv :: ParserM m => m HeadInventory pHeadInv = (,) <$> pInvPristine <*> pInv pInvPristine :: ParserM m => m ValidHash pInvPristine = do string pristineName skipSpace pHash -} pInv :: ParserM m => m Inventory pInv = Inventory <$> pInvParent <*> pInvPatches pInvParent :: ParserM m => m (Maybe InventoryHash) pInvParent = optional $ do string parentName skipSpace pHash pHash :: (ParserM m, ValidHash h) => m h pHash = do hash <- BC.unpack <$> pLine guard (okayHash hash) return (mkValidHash hash) pLine :: ParserM m => m B.ByteString pLine = takeTillChar '\n' <* take 1 pInvPatches :: ParserM m => m [InventoryEntry] pInvPatches = many pInvEntry pInvEntry :: ParserM m => m InventoryEntry pInvEntry = do info <- readPatchInfo skipSpace string hashName skipSpace hash <- pHash return (info, hash) -- * Showing showInventory :: Inventory -> Doc showInventory inv = showParent (inventoryParent inv) <> showInventoryPatches (inventoryPatches inv) showInventoryPatches :: [InventoryEntry] -> Doc showInventoryPatches = hcat . map showInventoryEntry showInventoryEntry :: InventoryEntry -> Doc showInventoryEntry (pinf, hash) = showPatchInfo ForStorage pinf $$ packedString hashName <+> text (getValidHash hash) <> packedString newline showParent :: Maybe InventoryHash -> Doc showParent (Just (InventoryHash hash)) = packedString parentName $$ text hash <> packedString newline showParent Nothing = mempty -- * Accessing the pristine hash -- | Replace the pristine hash at the start of a raw, unparsed 'HeadInventory' -- or add it if none is present. pokePristineHash :: String -> B.ByteString -> Doc pokePristineHash h inv = invisiblePS pristineName <> text h $$ invisiblePS (skipPristineHash inv) takeHash :: B.ByteString -> Maybe (String, B.ByteString) takeHash input = do let (hline,rest) = BC.breakSubstring newline input let hash = BC.unpack hline guard $ okayHash hash return (hash, rest) peekPristineHash :: B.ByteString -> String peekPristineHash inv = case tryDropPristineName inv of Just rest -> case takeHash rest of Just (h, _) -> h Nothing -> error $ "Bad hash in inventory!" Nothing -> sha256sum B.empty -- |skipPristineHash drops the 'pristine: HASH' prefix line, if present. skipPristineHash :: B.ByteString -> B.ByteString skipPristineHash ps = case tryDropPristineName ps of Just rest -> B.drop 1 $ BC.dropWhile (/= '\n') rest Nothing -> ps tryDropPristineName :: B.ByteString -> Maybe B.ByteString tryDropPristineName input = if prefix == pristineName then Just rest else Nothing where (prefix, rest) = B.splitAt (B.length pristineName) input -- * Key phrases pristineName :: B.ByteString pristineName = BC.pack "pristine:" parentName :: B.ByteString parentName = BC.pack "Starting with inventory:" hashName :: B.ByteString hashName = BC.pack "hash:" newline :: B.ByteString newline = BC.pack "\n" -- * Properties prop_inventoryParseShow :: Inventory -> Bool prop_inventoryParseShow inv = Just inv == parseInventory (renderPS (showInventory inv)) prop_peekPokePristineHash :: (PristineHash, B.ByteString) -> Bool prop_peekPokePristineHash (PristineHash hash, raw) = hash == peekPristineHash (renderPS (pokePristineHash hash raw)) prop_skipPokePristineHash :: (PristineHash, B.ByteString) -> Bool prop_skipPokePristineHash (PristineHash hash, raw) = raw == skipPristineHash (renderPS (pokePristineHash hash raw)) darcs-2.14.5/src/Darcs/Repository/Job.hs0000644000000000000000000003235207346545000016145 0ustar0000000000000000-- Copyright (C) 2002-2004,2007-2008 David Roundy -- Copyright (C) 2005 Juliusz Chroboczek -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE ForeignFunctionInterface #-} module Darcs.Repository.Job ( RepoJob(..) , IsPrimV1(..) , withRepoLock , withOldRepoLock , withRepoLockCanFail , withRepository , withRepositoryLocation , checkRepoIsNoRebase , withUMaskFlag ) where import Prelude () import Darcs.Prelude import Darcs.Util.Global ( darcsdir ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.V1 ( RepoPatchV1 ) import Darcs.Patch.V2 ( RepoPatchV2 ) import qualified Darcs.Patch.V1.Prim as V1 ( Prim(..) ) import qualified Darcs.Patch.V2.Prim as V2 ( Prim(..) ) import Darcs.Patch.Prim ( PrimOf ) import Darcs.Patch.Prim.V1 ( Prim ) import Darcs.Patch.RepoPatch ( RepoPatch ) import Darcs.Patch.RepoType ( RepoType(..), SRepoType(..), IsRepoType , RebaseType(..), SRebaseType(..), IsRebaseType , singletonRepoType ) import Darcs.Repository.Flags ( UseCache(..), UpdateWorking(..), DryRun(..), UMask (..) ) import Darcs.Repository.Format ( RepoProperty( Darcs2 , RebaseInProgress , HashedInventory ) , formatHas , writeProblem ) import Darcs.Repository.Identify ( identifyRepository ) import Darcs.Repository.Hashed( revertRepositoryChanges ) import Darcs.Repository.InternalTypes ( Repository , repoFormat , repoLocation ) import Darcs.Repository.Rebase ( RebaseJobFlags , startRebaseJob , rebaseJob ) import qualified Darcs.Repository.Rebase as Rebase ( maybeDisplaySuspendedStatus ) import Darcs.Util.Lock ( withLock, withLockCanFail ) import Darcs.Util.Progress ( debugMessage ) import Control.Monad ( when ) import Control.Exception ( bracket_, finally ) import Data.Coerce ( coerce ) import Data.List ( intercalate ) import Foreign.C.String ( CString, withCString ) import Foreign.C.Error ( throwErrno ) import Foreign.C.Types ( CInt(..) ) import Darcs.Util.Tree ( Tree ) getUMask :: UMask -> Maybe String getUMask (YesUMask s) = Just s getUMask NoUMask = Nothing withUMaskFlag :: UMask -> IO a -> IO a withUMaskFlag = maybe id withUMask . getUMask foreign import ccall unsafe "umask.h set_umask" set_umask :: CString -> IO CInt foreign import ccall unsafe "umask.h reset_umask" reset_umask :: CInt -> IO CInt withUMask :: String -> IO a -> IO a withUMask umask job = do rc <- withCString umask set_umask when (rc < 0) (throwErrno "Couldn't set umask") bracket_ (return ()) (reset_umask rc) job -- |A @RepoJob@ wraps up an action to be performed with a repository. Because repositories -- can contain different types of patches, such actions typically need to be polymorphic -- in the kind of patch they work on. @RepoJob@ is used to wrap up the polymorphism, -- and the various functions that act on a @RepoJob@ are responsible for instantiating -- the underlying action with the appropriate patch type. data RepoJob a -- = RepoJob (forall p wR wU . RepoPatch p => Repository p wR wU wR -> IO a) -- TODO: Unbind Tree from RepoJob, possibly renaming existing RepoJob = -- |The most common @RepoJob@; the underlying action can accept any patch type that -- a darcs repository may use. RepoJob (forall rt p wR wU . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wR -> IO a) -- |A job that only works on darcs 1 patches | V1Job (forall wR wU . Repository ('RepoType 'NoRebase) (RepoPatchV1 V1.Prim) wR wU wR -> IO a) -- |A job that only works on darcs 2 patches | V2Job (forall rt wR wU . IsRepoType rt => Repository rt (RepoPatchV2 V2.Prim) wR wU wR -> IO a) -- |A job that works on any repository where the patch type @p@ has 'PrimOf' @p@ = 'Prim'. -- -- This was added to support darcsden, which inspects the internals of V1 prim patches. -- -- In future this should be replaced with a more abstract inspection API as part of 'PrimPatch'. | PrimV1Job (forall rt p wR wU . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree, IsPrimV1 (PrimOf p)) => Repository rt p wR wU wR -> IO a) -- A job that works on normal darcs repositories, but will want access to the rebase patch if it exists. | RebaseAwareJob RebaseJobFlags (forall rt p wR wU . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wR -> IO a) | RebaseJob RebaseJobFlags (forall p wR wU . (RepoPatch p, ApplyState p ~ Tree) => Repository ('RepoType 'IsRebase) p wR wU wR -> IO a) | StartRebaseJob RebaseJobFlags (forall p wR wU . (RepoPatch p, ApplyState p ~ Tree) => Repository ('RepoType 'IsRebase) p wR wU wR -> IO a) onRepoJob :: RepoJob a -> (forall rt p wR wU . (RepoPatch p, ApplyState p ~ Tree) => (Repository rt p wR wU wR -> IO a) -> Repository rt p wR wU wR -> IO a) -> RepoJob a onRepoJob (RepoJob job) f = RepoJob (f job) onRepoJob (V1Job job) f = V1Job (f job) onRepoJob (V2Job job) f = V2Job (f job) onRepoJob (PrimV1Job job) f = PrimV1Job (f job) onRepoJob (RebaseAwareJob flags job) f = RebaseAwareJob flags (f job) onRepoJob (RebaseJob flags job) f = RebaseJob flags (f job) onRepoJob (StartRebaseJob flags job) f = StartRebaseJob flags (f job) -- | apply a given RepoJob to a repository in the current working directory withRepository :: UseCache -> RepoJob a -> IO a withRepository useCache = withRepositoryLocation useCache "." -- | This is just an internal type to Darcs.Repository.Job for -- calling runJob in a strongly-typed way data RepoPatchType p where RepoV1 :: RepoPatchType (RepoPatchV1 V1.Prim) RepoV2 :: RepoPatchType (RepoPatchV2 V2.Prim) -- | This type allows us to check multiple patch types against the -- constraints required by most repository jobs data IsTree p where IsTree :: (ApplyState p ~ Tree) => IsTree p checkTree :: RepoPatchType p -> IsTree p checkTree RepoV1 = IsTree checkTree RepoV2 = IsTree class ApplyState p ~ Tree => IsPrimV1 p where toPrimV1 :: p wX wY -> Prim wX wY instance IsPrimV1 V1.Prim where toPrimV1 = V1.unPrim instance IsPrimV1 V2.Prim where toPrimV1 = V2.unPrim -- | This type allows us to check multiple patch types against the -- constraints required by 'PrimV1Job' data UsesPrimV1 p where UsesPrimV1 :: (ApplyState p ~ Tree, IsPrimV1 (PrimOf p)) => UsesPrimV1 p checkPrimV1 :: RepoPatchType p -> UsesPrimV1 p checkPrimV1 RepoV1 = UsesPrimV1 checkPrimV1 RepoV2 = UsesPrimV1 -- | apply a given RepoJob to a repository in a given url withRepositoryLocation :: UseCache -> String -> RepoJob a -> IO a withRepositoryLocation useCache url repojob = do repo <- identifyRepository useCache url let rf = repoFormat repo startRebase = case repojob of StartRebaseJob {} -> True _ -> False -- in order to pass SRepoType and RepoPatchType at different types, we need a polymorphic -- function that we call in two different ways, rather than directly varying the argument. runJob1 :: IsRebaseType rebaseType => SRebaseType rebaseType -> Repository rtDummy pDummy wR wU wR -> RepoJob a -> IO a runJob1 isRebase = if formatHas Darcs2 rf then runJob RepoV2 (SRepoType isRebase) else runJob RepoV1 (SRepoType isRebase) runJob2 :: Repository rtDummy pDummy wR wU wR -> RepoJob a -> IO a runJob2 = if startRebase || formatHas RebaseInProgress rf then runJob1 SIsRebase else runJob1 SNoRebase runJob2 repo repojob runJob :: forall rt p rtDummy pDummy wR wU a . (IsRepoType rt, RepoPatch p) => RepoPatchType p -> SRepoType rt -> Repository rtDummy pDummy wR wU wR -> RepoJob a -> IO a runJob patchType (SRepoType isRebase) repo repojob = do -- The actual type the repository should have is only known when -- when this function is called, so we need to "cast" it to its proper type let therepo = coerce repo :: Repository rt p wR wU wR patchTypeString :: String patchTypeString = case patchType of RepoV2 -> "darcs-2" RepoV1 -> "darcs-1" repoAttributes :: [String] repoAttributes = case isRebase of SIsRebase -> ["rebase"] SNoRebase -> [] repoAttributesString :: String repoAttributesString = case repoAttributes of [] -> "" _ -> " " ++ intercalate "+" repoAttributes debugMessage $ "Identified " ++ patchTypeString ++ repoAttributesString ++ " repo: " ++ repoLocation repo case repojob of RepoJob job -> case checkTree patchType of IsTree -> job therepo `finally` Rebase.maybeDisplaySuspendedStatus isRebase therepo PrimV1Job job -> case checkPrimV1 patchType of UsesPrimV1 -> do job therepo `finally` Rebase.maybeDisplaySuspendedStatus isRebase therepo V2Job job -> case (patchType, isRebase) of (RepoV2, SNoRebase) -> job therepo (RepoV1, _ ) -> fail $ "This repository contains darcs v1 patches," ++ " but the command requires darcs v2 patches." (RepoV2, SIsRebase) -> fail "This command is not supported while a rebase is in progress." V1Job job -> case (patchType, isRebase) of (RepoV1, SNoRebase) -> job therepo (RepoV2, _ ) -> fail $ "This repository contains darcs v2 patches," ++ " but the command requires darcs v1 patches." (RepoV1, SIsRebase) -> fail "This command is not supported while a rebase is in progress." RebaseAwareJob flags job -> case (checkTree patchType, isRebase) of (IsTree, SNoRebase) -> job therepo (IsTree, SIsRebase) -> rebaseJob job therepo flags RebaseJob flags job -> case (checkTree patchType, isRebase) of (_ , SNoRebase) -> fail "No rebase in progress. Try 'darcs rebase suspend' first." (IsTree, SIsRebase) -> rebaseJob job therepo flags StartRebaseJob flags job -> case (checkTree patchType, isRebase) of (_ , SNoRebase) -> impossible (IsTree, SIsRebase) -> startRebaseJob job therepo flags -- | apply a given RepoJob to a repository in the current working directory, -- taking a lock withRepoLock :: DryRun -> UseCache -> UpdateWorking -> UMask -> RepoJob a -> IO a withRepoLock dry useCache uw um repojob = withRepository useCache $ onRepoJob repojob $ \job repository -> do maybe (return ()) fail $ writeProblem (repoFormat repository) let name = "./"++darcsdir++"/lock" withUMaskFlag um $ if dry == YesDryRun then job repository else withLock name (revertRepositoryChanges repository uw >> job repository) -- | run a lock-taking job in an old-fashion repository. -- only used by `darcs optimize upgrade`. withOldRepoLock :: RepoJob a -> IO a withOldRepoLock repojob = withRepository NoUseCache $ onRepoJob repojob $ \job repository -> do let name = "./"++darcsdir++"/lock" withLock name $ job repository -- | Apply a given RepoJob to a repository in the current working directory, -- taking a lock. If lock not takeable, do nothing. If old-fashioned -- repository, do nothing. The job must not touch pending or pending.tentative, -- because there is no call to revertRepositoryChanges. This entry point is -- currently only used for attemptCreatePatchIndex. withRepoLockCanFail :: UseCache -> RepoJob () -> IO () withRepoLockCanFail useCache repojob = withRepository useCache $ onRepoJob repojob $ \job repository -> let rf = repoFormat repository in if formatHas HashedInventory rf then do maybe (return ()) fail $ writeProblem rf let name = "./"++darcsdir++"/lock" eitherDone <- withLockCanFail name (job repository) case eitherDone of Left _ -> debugMessage "Lock could not be obtained, not doing the job." Right _ -> return () else debugMessage "Not doing the job because this is an old-fashioned repository." -- | If the 'RepoType' of the given repo indicates that we have 'NoRebase', -- then 'Just' the repo with the refined type, else 'Nothing'. -- NB The amount of types we have to import to make this simple check is ridiculous! checkRepoIsNoRebase :: forall rt p wR wU wT. IsRepoType rt => Repository rt p wR wU wT -> Maybe (Repository ('RepoType 'NoRebase) p wR wU wT) checkRepoIsNoRebase repo = case singletonRepoType :: SRepoType rt of SRepoType SNoRebase -> Just repo SRepoType SIsRebase -> Nothing darcs-2.14.5/src/Darcs/Repository/Match.hs0000644000000000000000000000624707346545000016473 0ustar0000000000000000-- Copyright (C) 2004-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Repository.Match ( getNonrangeMatch , getOnePatchset ) where import Prelude () import Darcs.Prelude import Control.Exception ( throw ) import Darcs.Patch.Match ( getNonrangeMatchS , nonrangeMatcherIsTag , getMatchingTag , matchAPatchset , nonrangeMatcher , applyNInv , hasIndexRange , MatchFlag(..) ) import Darcs.Patch.Bundle ( scanContextFile ) import Darcs.Patch.ApplyMonad ( ApplyMonad(..) ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch ( RepoPatch, IsRepoType ) import Darcs.Patch.Set ( PatchSet(..), SealedPatchSet, Origin ) import Darcs.Patch.Witnesses.Sealed ( seal ) import Darcs.Repository.Flags ( WithWorkingDir (WithWorkingDir) ) import Darcs.Repository.ApplyPatches ( DefaultIO, runDefault ) import Darcs.Repository.InternalTypes ( Repository ) import Darcs.Repository.Hashed ( readRepo, createPristineDirectoryTree ) import Darcs.Util.Tree ( Tree ) import Darcs.Util.Path ( toFilePath ) getNonrangeMatch :: (ApplyMonad (ApplyState p) DefaultIO, IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> [MatchFlag] -> IO () getNonrangeMatch r = withRecordedMatch r . getMatch where getMatch fs = case hasIndexRange fs of Just (n, m) | n == m -> applyNInv (n-1) | otherwise -> throw $ userError "Index range is not allowed for this command." _ -> getNonrangeMatchS fs getOnePatchset :: (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wT -> [MatchFlag] -> IO (SealedPatchSet rt p Origin) getOnePatchset repository fs = case nonrangeMatcher fs of Just m -> do ps <- readRepo repository if nonrangeMatcherIsTag fs then return $ getMatchingTag m ps else return $ matchAPatchset m ps Nothing -> seal `fmap` (scanContextFile . toFilePath . context_f $ fs) where context_f [] = bug "Couldn't match_nonrange_patchset" context_f (Context f:_) = f context_f (_:xs) = context_f xs withRecordedMatch :: (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wT -> (PatchSet rt p Origin wR -> DefaultIO ()) -> IO () withRecordedMatch r job = do createPristineDirectoryTree r "." WithWorkingDir readRepo r >>= runDefault . job darcs-2.14.5/src/Darcs/Repository/Merge.hs0000644000000000000000000002576307346545000016502 0ustar0000000000000000-- Copyright (C) 2002-2004,2007-2008 David Roundy -- Copyright (C) 2005 Juliusz Chroboczek -- Copyright (C) 2009 Petr Rockai -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Repository.Merge ( tentativelyMergePatches , considerMergeToWorking , announceMergeConflicts ) where import Prelude () import Darcs.Prelude import Control.Monad ( when, unless ) import Data.List.Ordered ( nubSort ) import System.Exit ( exitSuccess ) import Darcs.Util.Tree( Tree ) import Darcs.Util.External ( backupByCopying ) import Darcs.Patch ( RepoPatch, IsRepoType, PrimOf, merge, listTouchedFiles , fromPrims, effect, WrappedNamed , listConflictedFiles ) import Darcs.Patch.Prim ( PrimPatch ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.Depends( merge2FL ) import Darcs.Patch.Named.Wrapped ( activecontents, anonymous, namedIsInternal ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, n2pia, hopefully ) import Darcs.Patch.Progress( progressFL ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (:\/:)(..), (:/\:)(..), (+>+), mapFL_FL, concatFL, filterOutFLFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), seal ) import Darcs.Repository.Flags ( UseIndex , ScanKnown , AllowConflicts (..) , Reorder (..) , UpdateWorking (..) , ExternalMerge (..) , Verbosity (..) , Compression (..) , WantGuiPause (..) , DiffAlgorithm (..) , UseCache(..) , LookForMoves(..) , LookForReplaces(..) ) import Darcs.Repository.Hashed ( tentativelyAddPatches_ , applyToTentativePristine , tentativelyRemovePatches_ , UpdatePristine(..) ) import Darcs.Repository.Identify ( identifyRepository ) import Darcs.Repository.InternalTypes ( Repository ) import Darcs.Repository.Pending ( setTentativePending, readPending ) import Darcs.Repository.Resolution ( standardResolution, externalResolution ) import Darcs.Repository.State ( unrecordedChanges, readUnrecorded ) import Darcs.Util.Prompt ( promptYorn ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Progress( debugMessage ) import Darcs.Util.Printer.Color (fancyPrinters) import Darcs.Util.Printer ( text, ($$), redText, putDocLnWith, ($$) ) data MakeChanges = MakeChanges | DontMakeChanges deriving ( Eq ) tentativelyMergePatches_ :: forall rt p wR wU wT wY wX . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => MakeChanges -> Repository rt p wR wU wT -> String -> AllowConflicts -> UpdateWorking -> ExternalMerge -> WantGuiPause -> Compression -> Verbosity -> Reorder -> ( UseIndex, ScanKnown, DiffAlgorithm ) -> FL (PatchInfoAnd rt p) wX wT -> FL (PatchInfoAnd rt p) wX wY -> IO (Sealed (FL (PrimOf p) wU)) tentativelyMergePatches_ mc r cmd allowConflicts updateWorking externalMerge wantGuiPause compression verbosity reorder diffingOpts@(_, _, dflag) us them = do (them_merged :/\: us_merged) <- return $ merge2FL (progressFL "Merging us" us) (progressFL "Merging them" them) pend <- unrecordedChanges diffingOpts NoLookForMoves NoLookForReplaces r Nothing anonpend <- n2pia `fmap` anonymous (fromPrims pend) pend' :/\: pw <- return $ merge (them_merged :\/: anonpend :>: NilFL) let pwprim = concatFL $ progressFL "Examining patches for conflicts" $ mapFL_FL (activecontents . hopefully) pw Sealed standard_resolved_pw <- return $ standardResolution pwprim debugMessage "Checking for conflicts..." when (allowConflicts == YesAllowConflictsAndMark) $ mapM_ backupByCopying $ listTouchedFiles standard_resolved_pw debugMessage "Announcing conflicts..." have_conflicts <- announceMergeConflicts cmd allowConflicts externalMerge standard_resolved_pw debugMessage "Checking for unrecorded conflicts..." have_unrecorded_conflicts <- checkUnrecordedConflicts updateWorking $ mapFL_FL hopefully them_merged debugMessage "Reading working directory..." working <- readUnrecorded r Nothing debugMessage "Working out conflicts in actual working directory..." let haveConflicts = have_conflicts || have_unrecorded_conflicts Sealed pw_resolution <- case (externalMerge , haveConflicts) of (NoExternalMerge, _) -> return $ if allowConflicts == YesAllowConflicts then seal NilFL else seal standard_resolved_pw (_, False) -> return $ seal standard_resolved_pw (YesExternalMerge c, True) -> externalResolution dflag working c wantGuiPause (effect us +>+ pend) (effect them) pwprim debugMessage "Applying patches to the local directories..." when (mc == MakeChanges) $ do -- these two cases result in the same trees (that's the idea of -- merging), so we only operate on the set of patches and do the -- adaption of pristine and pending in the common code below r' <- case reorder of NoReorder -> do tentativelyAddPatches_ DontUpdatePristine r compression verbosity updateWorking them_merged Reorder -> do -- we do not actually remove any effect in the end, so -- it would be wrong to update the unrevert bundle or -- the working tree or pending r1 <- tentativelyRemovePatches_ DontUpdatePristineNorRevert r compression NoUpdateWorking (filterOutFLFL (namedIsInternal . hopefully) us) r2 <- tentativelyAddPatches_ DontUpdatePristine r1 compression verbosity NoUpdateWorking them tentativelyAddPatches_ DontUpdatePristine r2 compression verbosity NoUpdateWorking (filterOutFLFL (namedIsInternal . hopefully) us_merged) -- must use the original r, not the updated one here: applyToTentativePristine r verbosity them_merged setTentativePending r' updateWorking (effect pend' +>+ pw_resolution) return $ seal (effect pwprim +>+ pw_resolution) tentativelyMergePatches :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> String -> AllowConflicts -> UpdateWorking -> ExternalMerge -> WantGuiPause -> Compression -> Verbosity -> Reorder -> ( UseIndex, ScanKnown, DiffAlgorithm ) -> FL (PatchInfoAnd rt p) wX wT -> FL (PatchInfoAnd rt p) wX wY -> IO (Sealed (FL (PrimOf p) wU)) tentativelyMergePatches = tentativelyMergePatches_ MakeChanges considerMergeToWorking :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> String -> AllowConflicts -> UpdateWorking -> ExternalMerge -> WantGuiPause -> Compression -> Verbosity -> Reorder -> ( UseIndex, ScanKnown, DiffAlgorithm ) -> FL (PatchInfoAnd rt p) wX wT -> FL (PatchInfoAnd rt p) wX wY -> IO (Sealed (FL (PrimOf p) wU)) considerMergeToWorking = tentativelyMergePatches_ DontMakeChanges announceMergeConflicts :: (PrimPatch p) => String -> AllowConflicts -> ExternalMerge -> FL p wX wY -> IO Bool announceMergeConflicts cmd allowConflicts externalMerge resolved_pw = case nubSort $ listTouchedFiles resolved_pw of [] -> return False cfs -> if allowConflicts `elem` [YesAllowConflicts,YesAllowConflictsAndMark] || externalMerge /= NoExternalMerge then do putDocLnWith fancyPrinters $ redText "We have conflicts in the following files:" $$ text (unlines cfs) return True else do putDocLnWith fancyPrinters $ redText "There are conflicts in the following files:" $$ text (unlines cfs) fail $ "Refusing to "++cmd++" patches leading to conflicts.\n"++ "If you would rather apply the patch and mark the conflicts,\n"++ "use the --mark-conflicts or --allow-conflicts options to "++cmd++"\n"++ "These can set as defaults by adding\n"++ " "++cmd++" mark-conflicts\n"++ "to "++darcsdir++"/prefs/defaults in the target repo. " checkUnrecordedConflicts :: forall rt p wT wY. RepoPatch p => UpdateWorking -> FL (WrappedNamed rt p) wT wY -> IO Bool checkUnrecordedConflicts NoUpdateWorking _ = return False -- because we are called by `darcs convert` hence we don't care checkUnrecordedConflicts _ pc = do repository <- identifyRepository NoUseCache "." cuc repository where cuc :: Repository rt p wR wU wT -> IO Bool cuc r = do Sealed (mpend :: FL (PrimOf p) wT wX) <- readPending r :: IO (Sealed (FL (PrimOf p) wT)) case mpend of NilFL -> return False pend -> case merge (fromPrims_ pend :\/: fromPrims_ (concatFL $ mapFL_FL effect pc)) of _ :/\: pend' -> case listConflictedFiles pend' of [] -> return False fs -> do putStrLn ("You have conflicting local changes to:\n" ++ unwords fs) confirmed <- promptYorn "Proceed?" unless confirmed $ do putStrLn "Cancelled." exitSuccess return True fromPrims_ :: FL (PrimOf p) wA wB -> FL p wA wB fromPrims_ = fromPrims darcs-2.14.5/src/Darcs/Repository/Old.hs0000644000000000000000000001766307346545000016161 0ustar0000000000000000-- Copyright (C) 2002-2005,2007-2008 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Repository.Old ( readOldRepo, oldRepoFailMsg ) where import Prelude () import Darcs.Prelude import Darcs.Util.Progress ( debugMessage, beginTedious, endTedious, finishedOneIO ) import Darcs.Util.Path ( ioAbsoluteOrRemote, toPath ) import System.IO ( hPutStrLn, stderr ) import System.IO.Unsafe ( unsafeInterleaveIO ) import System.FilePath.Posix ( () ) import Darcs.Patch.PatchInfoAnd ( Hopefully, PatchInfoAnd, patchInfoAndPatch, actually, unavailable ) import qualified Data.ByteString as B ( ByteString, null ) import qualified Data.ByteString.Char8 as BC ( break, pack, unpack ) import Darcs.Patch ( RepoPatch, IsRepoType, WrappedNamed, readPatch ) import Darcs.Patch.ReadMonads as RM ( parseStrictly ) import Darcs.Patch.Witnesses.Ordered ( RL(..) ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), seal, unseal, mapSeal ) import Darcs.Patch.Info ( PatchInfo(..), makePatchname, readPatchInfo, displayPatchInfo ) import Darcs.Patch.Set ( PatchSet(..), Tagged(..), SealedPatchSet, Origin ) import Darcs.Util.External ( gzFetchFilePS , Cachable(..) ) import Darcs.Util.Printer ( renderString ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Hash ( sha1PS ) import Darcs.Util.IsoDate ( readUTCDateOldFashioned, showIsoDateTime ) import Control.Exception ( catch, IOException ) readOldRepo :: (IsRepoType rt, RepoPatch p) => String -> IO (SealedPatchSet rt p Origin) readOldRepo repo_dir = do realdir <- toPath `fmap` ioAbsoluteOrRemote repo_dir let task = "Reading inventory of repository "++repo_dir beginTedious task readRepoPrivate task realdir "inventory" `catch` (\e -> do hPutStrLn stderr ("Invalid repository: " ++ realdir) ioError e) readRepoPrivate :: (IsRepoType rt, RepoPatch p) => String -> FilePath -> FilePath -> IO (SealedPatchSet rt p Origin) readRepoPrivate task repo_dir inventory_name = do inventory <- gzFetchFilePS (repo_dir darcsdir inventory_name) Uncachable finishedOneIO task inventory_name let parse inf = parse2 inf $ repo_dir darcsdir "patches" makeFilename inf (mt, is) = case BC.break ('\n' ==) inventory of (swt,pistr) | swt == BC.pack "Starting with tag:" -> case readPatchInfos pistr of (t:ids) -> (Just t,reverse ids) [] -> bug "bad inventory in readRepoPrivate" _ -> (Nothing, reverse $ readPatchInfos inventory) Sealed ts <- unseal seal `fmap` unsafeInterleaveIO (read_ts parse mt) Sealed ps <- unseal seal `fmap` unsafeInterleaveIO (read_patches parse is) return $ seal (PatchSet ts ps) where read_ts :: RepoPatch p => (forall wB . PatchInfo -> IO (Sealed (PatchInfoAnd rt p wB))) -> Maybe PatchInfo -> IO (Sealed (RL (Tagged rt p) Origin)) read_ts _ Nothing = do endTedious task return $ seal NilRL read_ts parse (Just tag0) = do debugMessage $ "Looking for inventory for:\n"++ renderString (displayPatchInfo tag0) i <- unsafeInterleaveIO $ do x <- gzFetchFilePS (repo_dir darcsdir "inventories" makeFilename tag0) Uncachable finishedOneIO task (renderString (displayPatchInfo tag0)) return x let (mt, is) = case BC.break ('\n' ==) i of (swt,pistr) | swt == BC.pack "Starting with tag:" -> case readPatchInfos pistr of (t:ids) -> (Just t,reverse ids) [] -> bug "bad inventory in readRepoPrivate" _ -> (Nothing, reverse $ readPatchInfos i) Sealed ts <- fmap (unseal seal) $ unsafeInterleaveIO $ read_ts parse mt Sealed ps <- unseal seal `fmap` unsafeInterleaveIO (read_patches parse is) Sealed tag00 <- parse tag0 `catch` \(e :: IOException) -> return $ seal $ patchInfoAndPatch tag0 $ unavailable $ show e return $ seal $ ts :<: Tagged tag00 Nothing ps parse2 :: (IsRepoType rt, RepoPatch p) => PatchInfo -> FilePath -> IO (Sealed (PatchInfoAnd rt p wX)) parse2 i fn = do ps <- unsafeInterleaveIO $ gzFetchFilePS fn Cachable return $ patchInfoAndPatch i `mapSeal` hopefullyNoParseError (toPath fn) (readPatch ps) hopefullyNoParseError :: String -> Maybe (Sealed (WrappedNamed rt a1dr wX)) -> Sealed (Hopefully (WrappedNamed rt a1dr) wX) hopefullyNoParseError _ (Just (Sealed x)) = seal $ actually x hopefullyNoParseError s Nothing = seal $ unavailable $ "Couldn't parse file "++s read_patches :: RepoPatch p => (forall wB . PatchInfo -> IO (Sealed (PatchInfoAnd rt p wB))) -> [PatchInfo] -> IO (Sealed (RL (PatchInfoAnd rt p) wX)) read_patches _ [] = return $ seal NilRL read_patches parse (i:is) = lift2Sealed (flip (:<:)) (read_patches parse is) (parse i `catch` \(e :: IOException) -> return $ seal $ patchInfoAndPatch i $ unavailable $ show e) lift2Sealed :: (forall wY wZ . q wY wZ -> pp wY -> r wZ) -> IO (Sealed pp) -> (forall wB . IO (Sealed (q wB))) -> IO (Sealed r) lift2Sealed f iox ioy = do Sealed x <- unseal seal `fmap` unsafeInterleaveIO iox Sealed y <- unseal seal `fmap` unsafeInterleaveIO ioy return $ seal $ f y x oldRepoFailMsg :: String oldRepoFailMsg = "ERROR: repository upgrade required, try `darcs optimize upgrade`\n" ++ "See http://wiki.darcs.net/OF for more details." -- | This makes darcs-1 (non-hashed repos) filenames. -- -- The name consists of three segments: -- -- * timestamp (ISO8601-compatible yyyymmmddHHMMSS; -- note that the old-fashioned (non-hashed) format expects this date to -- be exactly as in the patch, /ignoring/ any timezone info, -- which is why we use 'readUTCDateOldFashioned' here) -- -- * SHA1 hash of the author -- -- * SHA1 hash of the patch name, author, date, log, and \"inverted\" -- flag. makeFilename :: PatchInfo -> String makeFilename pi = showIsoDateTime d++"-"++sha1_a++"-"++ (show $ makePatchname pi) ++ ".gz" where d = readUTCDateOldFashioned $ BC.unpack $ _piDate pi sha1_a = take 5 $ show $ sha1PS $ _piAuthor pi readPatchInfos :: B.ByteString -> [PatchInfo] readPatchInfos inv | B.null inv = [] readPatchInfos inv = case parseStrictly readPatchInfo inv of Just (pinfo,r) -> pinfo : readPatchInfos r _ -> [] darcs-2.14.5/src/Darcs/Repository/Packs.hs0000644000000000000000000002062607346545000016475 0ustar0000000000000000{-| License : GPL-2 Packs are an optimization that enable faster repository cloning over HTTP. A pack is actually a @tar.gz@ file that contains many files that would otherwise have to be transfered one by one (which is much slower over HTTP). Two packs are created at the same time by 'createPacks': 1. The basic pack, contains the latest recorded version of the working tree. 2. The patches pack, contains the set of patches of the repository. The paths of these files are @_darcs\/packs\/basic.tar.gz@ and @_darcs\/packs\/patches.tar.gz@. There is also @_darcs\/packs\/pristine@ which indicates the pristine hash at the moment of the creation of the packs. This last file is useful to determine whether the basic pack is in sync with the current pristine of the repository. -} module Darcs.Repository.Packs ( fetchAndUnpackBasic , fetchAndUnpackPatches , packsDir , createPacks ) where import qualified Codec.Archive.Tar as Tar import Codec.Archive.Tar.Entry ( fileEntry, toTarPath ) import Codec.Compression.GZip as GZ ( compress, decompress ) import Control.Concurrent.Async ( withAsync ) import Control.Exception ( Exception, IOException, throwIO, catch, finally ) import Control.Monad ( void, when, unless ) import System.IO.Error ( isAlreadyExistsError ) import System.IO.Unsafe ( unsafeInterleaveIO ) import qualified Data.ByteString.Lazy.Char8 as BLC import Data.List ( isPrefixOf, sort ) import Data.Maybe( catMaybes, listToMaybe ) import System.Directory ( createDirectoryIfMissing , renameFile , removeFile , doesFileExist , getModificationTime ) import System.FilePath ( () , (<.>) , takeFileName , splitPath , joinPath , takeDirectory ) import System.Posix.Files ( createLink ) import Darcs.Util.ByteString ( gzReadFilePS ) import Darcs.Util.Lock ( withTemp ) import Darcs.Util.External ( Cachable(..), fetchFileLazyPS ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Patch ( IsRepoType, RepoPatch ) import Darcs.Patch.PatchInfoAnd ( extractHash ) import Darcs.Patch.Witnesses.Ordered ( mapFL ) import Darcs.Patch.Set ( patchSet2FL ) import Darcs.Repository.InternalTypes ( Repository ) import qualified Darcs.Repository.Hashed as HashedRepo import Darcs.Repository.Hashed ( filterDirContents, readRepo, readHashedPristineRoot ) import Darcs.Repository.Format ( identifyRepoFormat, formatHas, RepoProperty ( HashedInventory ) ) import Darcs.Repository.Cache ( fetchFileUsingCache , HashedDir(..) , Cache(..) , CacheLoc(..) , WritableOrNot(..) , hashedDir , bucketFolder , CacheType(Directory) ) import Darcs.Repository.Old ( oldRepoFailMsg ) packsDir, basicPack, patchesPack :: String packsDir = "packs" basicPack = "basic.tar.gz" patchesPack = "patches.tar.gz" fetchAndUnpack :: FilePath -> HashedDir -> Cache -> FilePath -> IO () fetchAndUnpack filename dir cache remote = do unpackTar cache dir . Tar.read . GZ.decompress =<< fetchFileLazyPS (remote darcsdir packsDir filename) Uncachable fetchAndUnpackPatches :: [String] -> Cache -> FilePath -> IO () fetchAndUnpackPatches paths cache remote = -- Patches pack can miss some new patches of the repository. -- So we download pack asynchonously and alway do a complete pass -- of individual patch files. withAsync (fetchAndUnpack patchesPack HashedInventoriesDir cache remote) $ \_ -> do fetchFilesUsingCache cache HashedPatchesDir paths fetchAndUnpackBasic :: Cache -> FilePath -> IO () fetchAndUnpackBasic = fetchAndUnpack basicPack HashedPristineDir unpackTar :: Exception e => Cache -> HashedDir -> Tar.Entries e -> IO () unpackTar _ _ Tar.Done = return () unpackTar _ _ (Tar.Fail e) = throwIO e unpackTar c dir (Tar.Next e es) = case Tar.entryContent e of Tar.NormalFile bs _ -> do let p = Tar.entryPath e if "meta-" `isPrefixOf` takeFileName p then unpackTar c dir es -- just ignore them else do ex <- doesFileExist p if ex then debugMessage $ "TAR thread: exists " ++ p ++ "\nStopping TAR thread." else do if p == darcsdir "hashed_inventory" then writeFile' Nothing p bs else writeFile' (cacheDir c) p $ GZ.compress bs debugMessage $ "TAR thread: GET " ++ p unpackTar c dir es _ -> fail "Unexpected non-file tar entry" where writeFile' Nothing path content = withTemp $ \tmp -> do BLC.writeFile tmp content renameFile tmp path writeFile' (Just ca) path content = do let fileFullPath = case splitPath path of _:hDir:hFile:_ -> joinPath [ca, hDir, bucketFolder hFile, hFile] _ -> fail "Unexpected file path" createDirectoryIfMissing True $ takeDirectory path createLink fileFullPath path `catch` (\(ex :: IOException) -> do if isAlreadyExistsError ex then return () -- so much the better else -- ignore cache if we cannot link writeFile' Nothing path content) -- | Similar to @'mapM_' ('void' 'fetchFileUsingCache')@, exepts -- it stops execution if file it's going to fetch already exists. fetchFilesUsingCache :: Cache -> HashedDir -> [FilePath] -> IO () fetchFilesUsingCache cache dir = mapM_ go where go path = do ex <- doesFileExist $ darcsdir hashedDir dir path if ex then debugMessage $ "FILE thread: exists " ++ path else void $ fetchFileUsingCache cache dir path cacheDir :: Cache -> Maybe String cacheDir (Ca cs) = listToMaybe . catMaybes .flip map cs $ \x -> case x of Cache Directory Writable x' -> Just x' _ -> Nothing -- | Create packs from the current recorded version of the repository. createPacks :: (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wT -> IO () createPacks repo = flip finally (mapM_ removeFileIfExists [ darcsdir "meta-filelist-inventories" , darcsdir "meta-filelist-pristine" , basicTar <.> "part" , patchesTar <.> "part" ]) $ do rf <- identifyRepoFormat "." -- function is exposed in API so could be called on non-hashed repo unless (formatHas HashedInventory rf) $ fail oldRepoFailMsg createDirectoryIfMissing False (darcsdir packsDir) -- pristine hash Just hash <- readHashedPristineRoot repo writeFile ( darcsdir packsDir "pristine" ) hash -- pack patchesTar ps <- mapFL hashedPatchFileName . patchSet2FL <$> readRepo repo is <- map ((darcsdir "inventories") ) <$> HashedRepo.listInventories writeFile (darcsdir "meta-filelist-inventories") . unlines $ map takeFileName is -- Note: tinkering with zlib's compression parameters does not make -- any noticeable difference in generated archive size; -- switching to bzip2 would provide ~25% gain OTOH. BLC.writeFile (patchesTar <.> "part") . GZ.compress . Tar.write =<< mapM fileEntry' ((darcsdir "meta-filelist-inventories") : ps ++ reverse is) renameFile (patchesTar <.> "part") patchesTar -- pack basicTar pr <- sortByMTime =<< dirContents "pristine.hashed" writeFile (darcsdir "meta-filelist-pristine") . unlines $ map takeFileName pr BLC.writeFile (basicTar <.> "part") . GZ.compress . Tar.write =<< mapM fileEntry' ( [ darcsdir "meta-filelist-pristine" , darcsdir "hashed_inventory" ] ++ reverse pr) renameFile (basicTar <.> "part") basicTar where basicTar = darcsdir packsDir basicPack patchesTar = darcsdir packsDir patchesPack fileEntry' x = unsafeInterleaveIO $ do content <- BLC.fromChunks . return <$> gzReadFilePS x tp <- either fail return $ toTarPath False x return $ fileEntry tp content dirContents d = map ((darcsdir d) ) <$> filterDirContents d (const True) hashedPatchFileName x = case extractHash x of Left _ -> fail "unexpected unhashed patch" Right h -> darcsdir "patches" h sortByMTime xs = map snd . sort <$> mapM (\x -> (\t -> (t, x)) <$> getModificationTime x) xs removeFileIfExists x = do ex <- doesFileExist x when ex $ removeFile x darcs-2.14.5/src/Darcs/Repository/PatchIndex.hs0000644000000000000000000010037707346545000017465 0ustar0000000000000000{-# LANGUAGE NamedFieldPuns #-} {-| License : GPL-2 The patch-index stores additional information that is extracted from the PatchSet for the repository to speed up certain commands (namely @log@ and @annotate@). More precisely, for every file tracked by the repository, it stores the list of patches that touch it. When created, patch-index lives in @_darcs\/patch_index\/@, and it should be automatically maintained each time the set of patches of the repository is updated. Patch-index can also be explicitely disabled by creating a file @_darcs\/no_patch_index@. "Explicitely disabed" means that no command should attempt to automatically create the patch-index. See for more information. -} module Darcs.Repository.PatchIndex ( doesPatchIndexExist, isPatchIndexDisabled, isPatchIndexInSync, canUsePatchIndex, createPIWithInterrupt, createOrUpdatePatchIndexDisk, deletePatchIndex, attemptCreatePatchIndex, PatchFilter, maybeFilterPatches, getRelevantSubsequence, dumpPatchIndex, piTest ) where import Prelude () import Darcs.Prelude import Data.Binary ( Binary, encodeFile, decodeFileOrFail ) import Data.Word ( Word32 ) import Data.Int ( Int8 ) import Data.List ( group, mapAccumL, sort, isPrefixOf, nub, (\\) ) import Data.Maybe ( fromJust, fromMaybe, isJust ) import Data.Set (Set) import Data.Map (Map) import qualified Data.Map as M import qualified Data.Set as S import Control.Exception ( catch ) import Control.Monad ( forM_, unless, when ) import Control.Monad.State.Strict ( evalState, execState, State, gets, modify ) import System.Directory ( createDirectory, renameDirectory, doesFileExist, doesDirectoryExist ) import Darcs.Repository.Format ( formatHas, RepoProperty( HashedInventory ) ) import Darcs.Repository.InternalTypes ( Repository, repoLocation, repoFormat ) import Darcs.Patch.Witnesses.Ordered ( mapFL, RL(..), FL(..), reverseRL ) import Darcs.Patch.Witnesses.Sealed ( Sealed2(..), Sealed(..), seal, seal2, unsafeUnseal ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd(..), info ) import Darcs.Util.Lock ( withPermDir, rmRecursive ) import Darcs.Patch ( RepoPatch, listTouchedFiles ) import Darcs.Util.Path ( FileName, fp2fn, fn2fp, toFilePath ) import Darcs.Patch.Apply ( ApplyState(..) ) import Darcs.Patch.Set ( PatchSet(..), patchSet2FL, Origin, patchSet2FL ) import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Patch.Index.Types import Darcs.Patch.Index.Monad ( applyToFileMods, makePatchID ) import System.FilePath( () ) import System.IO (openFile, IOMode(WriteMode), hClose) import qualified Data.ByteString as B import Darcs.Util.Hash ( sha256sum, showAsHex ) import Darcs.Util.Tree ( Tree(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Util.SignalHandler ( catchInterrupt ) data FileIdSpan = FidSpan !FileId -- the fileid has some fixed name in the !PatchId -- span starting here !(Maybe PatchId) -- and (maybe) ending here deriving (Show,Eq,Ord) data FilePathSpan = FpSpan !FileName -- the file path has some fixed fileid in the !PatchId -- span starting here !(Maybe PatchId) -- and (maybe) ending here deriving (Show,Eq,Ord) -- | info about a given fileid, e.g.. is a file or a directory data FileInfo = FileInfo { isFile::Bool, touching::Set Word32} -- first word of patch hash deriving (Show,Eq,Ord) -- | timespans where a certain filename corresponds to a file with a given id type FileIdSpans = Map FileName [FileIdSpan] -- | timespans where a file with a certain id corresponds to given filenames type FilePathSpans = Map FileId [FilePathSpan] -- | information file with a given ID type InfoMap = Map FileId FileInfo -- | the patch-index data PatchIndex = PatchIndex { -- |all the PatchIds tracked by this patch index, with the most -- recent patch at the head of the list (note, stored in the -- reverse order to this on disk for backwards compatibility -- with an older format). pids::[PatchId], fidspans::FileIdSpans, fpspans::FilePathSpans, infom::InfoMap } -- | On-disk version of patch index -- version 1 is the one introduced in darcs 2.10 -- 2 changes the pids order to newer-to-older version :: Int8 version = 2 type PIM a = State PatchIndex a -- | 'applyPatchMods pmods pindex' applies a list of PatchMods to the given -- patch index pindex applyPatchMods :: [(PatchId, [PatchMod FileName])] -> PatchIndex -> PatchIndex applyPatchMods pmods pindex = flip execState pindex $ mapM_ goList pmods where goList :: (PatchId, [PatchMod FileName]) -> PIM () goList (pid, mods) = do modify (\pind -> pind{pids = pid:pids pind}) mapM_ (curry go pid) (nubSeq mods) -- nubSeq handles invalid patch in darcs repo: -- move with identical target name "rename darcs_patcher to darcs-patcher." nubSeq = map head . group go :: (PatchId, PatchMod FileName) -> PIM () go (pid, PCreateFile fn) = do fid <- createFidStartSpan fn pid startFpSpan fid fn pid createInfo fid True insertTouch fid pid go (pid, PCreateDir fn) = do fid <- createFidStartSpan fn pid startFpSpan fid fn pid createInfo fid False insertTouch fid pid go (pid, PTouch fn) = do fid <- lookupFid fn insertTouch fid pid go (pid, PRename oldfn newfn) = do fid <- lookupFid oldfn stopFpSpan fid pid startFpSpan fid newfn pid insertTouch fid pid stopFidSpan oldfn pid startFidSpan newfn pid fid go (pid, PRemove fn) = do fid <- lookupFid fn insertTouch fid pid stopFidSpan fn pid stopFpSpan fid pid go (_, PInvalid _) = return () -- just ignore invalid changes go (pid, PDuplicateTouch fn) = do fidm <- gets fidspans case M.lookup fn fidm of Just (FidSpan fid _ _:_) -> insertTouch fid pid Nothing -> return () Just [] -> error $ "applyPatchMods: impossible, no entry for "++show fn ++" in FileIdSpans in duplicate, empty list" -- | create new filespan for created file createFidStartSpan :: FileName -> PatchId -> PIM FileId createFidStartSpan fn pstart = do fidspans <- gets fidspans case M.lookup fn fidspans of Nothing -> do let fid = FileId fn 1 modify (\pind -> pind {fidspans=M.insert fn [FidSpan fid pstart Nothing] fidspans}) return fid Just fspans -> do let fid = FileId fn (length fspans+1) modify (\pind -> pind {fidspans=M.insert fn (FidSpan fid pstart Nothing:fspans) fidspans}) return fid -- | start new span for name fn for file fid starting with patch pid startFpSpan :: FileId -> FileName -> PatchId -> PIM () startFpSpan fid fn pstart = modify (\pind -> pind {fpspans=M.alter alt fid (fpspans pind)}) where alt Nothing = Just [FpSpan fn pstart Nothing] alt (Just spans) = Just (FpSpan fn pstart Nothing:spans) -- | stop current span for file name fn stopFpSpan :: FileId -> PatchId -> PIM () stopFpSpan fid pend = modify (\pind -> pind {fpspans=M.alter alt fid (fpspans pind)}) where alt Nothing = error $ "impossible: no span for " ++ show fid alt (Just []) = error $ "impossible: no span for " ++ show fid++", empty list" alt (Just (FpSpan fp pstart Nothing:spans)) = Just (FpSpan fp pstart (Just pend):spans) alt _ = error $ "impossible: span already ended for " ++ show fid -- | start new span for name fn for file fid starting with patch pid startFidSpan :: FileName -> PatchId -> FileId -> PIM () startFidSpan fn pstart fid = modify (\pind -> pind {fidspans=M.alter alt fn (fidspans pind)}) where alt Nothing = Just [FidSpan fid pstart Nothing] alt (Just spans) = Just (FidSpan fid pstart Nothing:spans) -- | stop current span for file name fn stopFidSpan :: FileName -> PatchId -> PIM () stopFidSpan fn pend = modify (\pind -> pind {fidspans=M.alter alt fn (fidspans pind)}) where alt Nothing = error $ "impossible: no span for " ++ show fn alt (Just []) = error $ "impossible: no span for " ++ show fn++", empty list" alt (Just (FidSpan fid pstart Nothing:spans)) = Just (FidSpan fid pstart (Just pend):spans) alt _ = error $ "impossible: span already ended for " ++ show fn -- | insert touching patchid for given file id createInfo :: FileId -> Bool -> PIM () createInfo fid isF = modify (\pind -> pind {infom=M.alter alt fid (infom pind)}) where alt Nothing = Just (FileInfo isF S.empty) alt (Just _) = Just (FileInfo isF S.empty) -- forget old false positives -- | insert touching patchid for given file id insertTouch :: FileId -> PatchId -> PIM () insertTouch fid pid = modify (\pind -> pind {infom=M.alter alt fid (infom pind)}) where alt Nothing = impossible "Fileid does not exist" alt (Just (FileInfo isF pids)) = Just (FileInfo isF (S.insert (short pid) pids)) -- | lookup current fid of filepath lookupFid :: FileName -> PIM FileId lookupFid fn = do maybeFid <- lookupFid' fn case maybeFid of Nothing -> bug $ "couldn't find " ++ fn2fp fn ++ " in patch index" Just fid -> return fid -- | lookup current fid of filepatch, returning a Maybe to allow failure lookupFid' :: FileName -> PIM (Maybe FileId) lookupFid' fn = do fidm <- gets fidspans case M.lookup fn fidm of Just (FidSpan fid _ _:_) -> return $ Just fid _ -> return Nothing -- | lookup all the file ids of a given path lookupFidf' :: FileName -> PIM [FileId] lookupFidf' fn = do fidm <- gets fidspans case M.lookup fn fidm of Just spans -> return $ map (\(FidSpan fid _ _) -> fid) spans Nothing -> error $ "lookupFidf': no entry for " ++ show fn ++ " in FileIdSpans" -- | return all fids of matching subpaths -- of the given filepath lookupFids :: FileName -> PIM [FileId] lookupFids fn = do fid_spans <- gets fidspans file_idss <- mapM (lookupFidf' . fp2fn) $ filter (isPrefixOf (fn2fp fn)) (fpSpans2filePaths' fid_spans) return $ nub $ concat file_idss -- | returns a single file id if the given path is a file -- if it is a directory, if returns all the file ids of all paths inside it, -- at any point in repository history lookupFids' :: FileName -> PIM [FileId] lookupFids' fn = do info_map <- gets infom fps_spans <- gets fpspans a <- lookupFid' fn if isJust a then do let fid = fromJust a case M.lookup fid info_map of Just (FileInfo True _) -> return [fid] Just (FileInfo False _) -> let file_names = map (\(FpSpan x _ _) -> x) (fps_spans M.! fid) in nub . concat <$> mapM lookupFids file_names Nothing -> error "lookupFids' : could not find file" else return [] -- | Creates patch index that corresponds to all patches in repo. createPatchIndexDisk :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> PatchSet rt p Origin wR -> IO () createPatchIndexDisk repository ps = do let patches = mapFL Sealed2 $ patchSet2FL ps createPatchIndexFrom repository $ patches2patchMods patches S.empty -- | convert patches to patchmods patches2patchMods :: (Apply p, PatchInspect p, ApplyState p ~ Tree) => [Sealed2 (PatchInfoAnd rt p)] -> Set FileName -> [(PatchId, [PatchMod FileName])] patches2patchMods patches fns = snd $ mapAccumL go fns patches where go filenames (Sealed2 p) = (filenames', (pid, pmods_effect ++ pmods_dup)) where pid = makePatchID . info $ p (filenames', pmods_effect) = applyToFileMods p filenames -- applyToFileMods only returns patchmods that actually modify a file, -- i.e., never duplicate patches touched pm = case pm of {PTouch f -> [f]; PRename a b -> [a,b]; PCreateDir f -> [f]; PCreateFile f -> [f]; PRemove f -> [f]; _ -> []} touched_all = map fp2fn $ listTouchedFiles p touched_effect = concatMap touched pmods_effect touched_invalid = [ f | (PInvalid f) <- pmods_effect] -- listTouchedFiles returns all files that touched by these -- patches, even if they have no effect, e.g. by duplicate patches pmods_dup = map PDuplicateTouch . S.elems $ S.difference (S.fromList touched_all) (S.fromList touched_invalid `S.union` S.fromList touched_effect) -- | return set of current filenames in patch index fpSpans2fileNames :: FilePathSpans -> Set FileName fpSpans2fileNames fpSpans = S.fromList [fn | (FpSpan fn _ Nothing:_)<- M.elems fpSpans] -- | remove all patch effects of given patches from patch index. -- assumes that the given list of patches is a suffix of the -- patches tracked by the patch-index removePidSuffix :: Map PatchId Int -> [PatchId] -> PatchIndex -> PatchIndex removePidSuffix _ [] pindex = pindex removePidSuffix pid2idx oldpids@(oldpid:_) (PatchIndex pids fidspans fpspans infom) = PatchIndex (pids \\ oldpids) (M.mapMaybe removefid fidspans) (M.mapMaybe removefp fpspans) infom -- leave hashes in infom, false positives are harmless where findIdx pid = fromMaybe (impossible "removePidSuffix") (M.lookup pid pid2idx) oldidx = findIdx oldpid from `after` idx = findIdx from > idx mto `afterM` idx | Just to <- mto, findIdx to > idx = True | otherwise = False removefid fidsps = if null fidsps' then Nothing else Just fidsps' where fidsps' = concatMap go fidsps go (FidSpan fid from mto) | from `after` oldidx && mto `afterM` oldidx = [FidSpan fid from mto] | from `after` oldidx = [FidSpan fid from Nothing] | otherwise = [] removefp fpsps = if null fpsps' then Nothing else Just fpsps' where fpsps' = concatMap go fpsps go (FpSpan fn from mto) | from `after` oldidx && mto `afterM` oldidx = [FpSpan fn from mto] | from `after` oldidx = [FpSpan fn from Nothing] | otherwise = [] -- | update the patch index to the current state of the repository updatePatchIndexDisk :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> PatchSet rt p Origin wR -> IO () updatePatchIndexDisk repo patches = do let repodir = repoLocation repo (_,_,pid2idx,pindex) <- loadPatchIndex repodir -- check that patch index is up to date let flpatches = patchSet2FL patches let pidsrepo = mapFL (makePatchID . info) flpatches (oldpids,_,len_common) = uncommon (reverse $ pids pindex) pidsrepo pindex' = removePidSuffix pid2idx oldpids pindex filenames = fpSpans2fileNames (fpspans pindex') cdir = repodir indexDir -- reread to prevent holding onto patches for too long let newpatches = drop len_common $ mapFL seal2 flpatches newpmods = patches2patchMods newpatches filenames inv_hash <- getInventoryHash repodir storePatchIndex repodir cdir inv_hash (applyPatchMods newpmods pindex') where -- return uncommon suffixes and length of common prefix of as and bs uncommon = uncommon' 0 uncommon' x (a:as) (b:bs) | a == b = uncommon' (x+1) as bs | otherwise = (a:as,b:bs,x) uncommon' x as bs = (as,bs,x) -- | 'createPatchIndexFrom repo pmods' creates a patch index from the given -- patchmods. createPatchIndexFrom :: Repository rt p wR wU wT -> [(PatchId, [PatchMod FileName])] -> IO () createPatchIndexFrom repo pmods = do inv_hash <- getInventoryHash repodir storePatchIndex repodir cdir inv_hash (applyPatchMods pmods emptyPatchIndex) where repodir = repoLocation repo cdir = repodir indexDir emptyPatchIndex = PatchIndex [] M.empty M.empty M.empty getInventoryHash :: FilePath -> IO String getInventoryHash repodir = do inv <- B.readFile (repodir darcsdir "hashed_inventory") return $ sha256sum inv -- | Load patch-index from disk along with some meta data. loadPatchIndex :: FilePath -> IO (Int8, String, Map PatchId Int, PatchIndex) loadPatchIndex repodir = do let pindex_dir = repodir indexDir (v,inv_hash) <- loadRepoState (pindex_dir repoStateFile) pids <- loadPatchIds (pindex_dir pidsFile) let pid2idx = M.fromList $ zip pids [(1::Int)..] infom <- loadInfoMap (pindex_dir touchMapFile) fidspans <- loadFidMap (pindex_dir fidMapFile) fpspans <- loadFpMap (pindex_dir fpMapFile) return (v, inv_hash, pid2idx, PatchIndex pids fidspans fpspans infom) -- | If patch-index is useful as it is now, read it. If not, create or update it, then read it. loadSafePatchIndex :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> PatchSet rt p Origin wR -- ^ PatchSet of the repository, used if we need to create the patch-index. -> IO PatchIndex loadSafePatchIndex repo ps = do let repodir = repoLocation repo can_use <- isPatchIndexInSync repo (_,_,_,pi) <- if can_use then loadPatchIndex repodir else do createOrUpdatePatchIndexDisk repo ps loadPatchIndex repodir return pi -- | Read-only. Checks if patch-index exists for this repository -- it works by checking if: -- -- 1. @_darcs\/patch_index\/@ and its corresponding files are all present -- 2. patch index version is the one handled by this version of Darcs doesPatchIndexExist :: FilePath -> IO Bool doesPatchIndexExist repodir = do filesArePresent <- and <$> mapM (doesFileExist . (pindex_dir )) [repoStateFile, pidsFile, touchMapFile, fidMapFile, fpMapFile] if filesArePresent then do v <- piVersion return (v == version) -- consider PI only of on-disk format is the current one else return False where pindex_dir = repodir indexDir piVersion = fst <$> loadRepoState (pindex_dir repoStateFile) -- | Read-only. Checks if @_darcs\/noPatchIndex@ exists, that is, if patch-index is explicitely disabled. isPatchIndexDisabled :: FilePath -> IO Bool isPatchIndexDisabled repodir = doesFileExist (repodir darcsdir noPatchIndex) -- | Create or update patch index -- -- 1. if @_darcs\/no_patch_index@ exists, delete it -- 2. if patch index exists, update it -- 3. if not, create it from scratch createOrUpdatePatchIndexDisk :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> PatchSet rt p Origin wR -> IO () createOrUpdatePatchIndexDisk repo ps = do let repodir = repoLocation repo rmRecursive (repodir darcsdir noPatchIndex) `catch` \(_ :: IOError) -> return () dpie <- doesPatchIndexExist repodir if dpie then updatePatchIndexDisk repo ps else createPatchIndexDisk repo ps -- | Read-only. Checks the two following things: -- -- 1. 'doesPatchIndexExist' -- 2. 'isPatchIndexDisabled' -- -- Then only if it exists and it is not explicitely disabled, returns @True@, else returns @False@ -- (or an error if it exists and is explicitely disabled at the same time). canUsePatchIndex :: Repository rt p wR wU wT -> IO Bool canUsePatchIndex repo = do let repodir = repoLocation repo piExists <- doesPatchIndexExist repodir piDisabled <- isPatchIndexDisabled repodir case (piExists, piDisabled) of (True, False) -> return True (False, True) -> return False (True, True) -> error "patch index exists, and patch index is disabled. run optimize enable-patch-index or disable-patch-index to rectify." (False, False) -> return False -- | Creates patch-index (ignoring whether it is explicitely disabled). -- If it is ctrl-c'ed, then aborts, delete patch-index and mark it as disabled. createPIWithInterrupt :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> PatchSet rt p Origin wR -> IO () createPIWithInterrupt repo ps = do let repodir = repoLocation repo putStrLn "Creating a patch index, please wait. To stop press Ctrl-C" (do createPatchIndexDisk repo ps putStrLn "Created patch index.") `catchInterrupt` (putStrLn "Patch Index Disabled" >> deletePatchIndex repodir) -- | Checks if patch-index exists and is in sync with repository (more precisely with @_darcs\/hashed_inventory@). -- That is, checks if patch-index can be used as it is now. isPatchIndexInSync :: Repository rt p wR wU wT -> IO Bool isPatchIndexInSync repo = do let repodir = repoLocation repo dpie <- doesPatchIndexExist repodir if dpie then do (_, inv_hash_pindex, _, _) <- loadPatchIndex repodir inv_hash <- getInventoryHash repodir return (inv_hash == inv_hash_pindex) else return False -- | Stores patch-index on disk. storePatchIndex :: FilePath -> FilePath -> String -> PatchIndex -> IO () storePatchIndex repodir cdir inv_hash (PatchIndex pids fidspans fpspans infom) = do createDirectory cdir `catch` \(_ :: IOError) -> return () tmpdir <- withPermDir (repodir "filecache-tmp") $ \dir -> do debugMessage "About to create patch index..." let tmpdir = toFilePath dir storeRepoState (tmpdir repoStateFile) inv_hash storePatchIds (tmpdir pidsFile) pids storeInfoMap (tmpdir touchMapFile) infom storeFidMap (tmpdir fidMapFile) fidspans storeFpMap (tmpdir fpMapFile) fpspans debugMessage "Patch index created" return tmpdir rmRecursive cdir `catch` \(_ :: IOError) -> return () renameDirectory tmpdir cdir decodeFile :: Binary a => FilePath -> IO a decodeFile path = do result <- decodeFileOrFail path case result of Left (offset, msg) -> fail $ "Patch index is corrupt (file "++path++" at offset "++show offset++"): "++msg++ "\nPlease remove the corrupt file and then try again." Right r -> return r storeRepoState :: FilePath -> String -> IO () storeRepoState fp inv_hash = encodeFile fp (version,inv_hash) loadRepoState :: FilePath -> IO (Int8, String) loadRepoState = decodeFile storePatchIds :: FilePath -> [PatchId] -> IO () storePatchIds = encodeFile loadPatchIds :: FilePath -> IO [PatchId] loadPatchIds = decodeFile storeFidMap :: FilePath -> FileIdSpans -> IO () storeFidMap fp fidm = encodeFile fp $ M.map (map (\(FidSpan a b c) -> (a, b, toIdxM c))) fidm where toIdxM Nothing = zero toIdxM (Just pid) = pid loadFidMap :: FilePath -> IO FileIdSpans loadFidMap fp = M.map (map (\(a,b,c) -> FidSpan a b (toPidM c))) <$> decodeFile fp where toPidM pid | pid == zero = Nothing | otherwise = Just pid storeFpMap :: FilePath -> FilePathSpans -> IO () storeFpMap fp fidm = encodeFile fp $ M.map (map (\(FpSpan a b c) -> (a, b, toIdxM c))) fidm where toIdxM Nothing = zero toIdxM (Just pid) = pid loadFpMap :: FilePath -> IO FilePathSpans loadFpMap fp = M.map (map (\(a,b,c) -> FpSpan a b (toPidM c))) <$> decodeFile fp where toPidM pid | pid == zero = Nothing | otherwise = Just pid storeInfoMap :: FilePath -> InfoMap -> IO () storeInfoMap fp infom = encodeFile fp $ M.map (\fi -> (isFile fi, touching fi)) infom loadInfoMap :: FilePath -> IO InfoMap loadInfoMap fp = M.map (\(isF,pids) -> FileInfo isF pids) <$> decodeFile fp indexDir, repoStateFile, pidsFile, fidMapFile, fpMapFile, touchMapFile, noPatchIndex :: String indexDir = darcsdir "patch_index" repoStateFile = "repo_state" pidsFile = "patch_ids" fidMapFile = "fid_map" fpMapFile = "fp_map" touchMapFile = "touch_map" noPatchIndex = "no_patch_index" -- | Deletes patch-index (@_darcs\/patch_index\/@ and its contents) and mark repository as disabled (creates @_darcs\/no_patch_index@). deletePatchIndex :: FilePath -> IO () deletePatchIndex repodir = do exists <- doesDirectoryExist indexDir when exists $ rmRecursive indexDir `catch` \(e :: IOError) -> error $ "Error: Could not delete patch index\n" ++ show e (openFile (repodir darcsdir noPatchIndex) WriteMode >>= hClose) `catch` \(e :: IOError) -> error $ "Error: Could not disable patch index\n" ++ show e dumpRepoState :: [PatchId] -> String dumpRepoState = unlines . map pid2string dumpFileIdSpans :: FileIdSpans -> String dumpFileIdSpans fidspans = unlines [fn2fp fn++" -> "++showFileId fid++" from "++pid2string from++" to "++maybe "-" pid2string mto | (fn, fids) <- M.toList fidspans, FidSpan fid from mto <- fids] dumpFilePathSpans :: FilePathSpans -> String dumpFilePathSpans fpspans = unlines [showFileId fid++" -> "++ fn2fp fn++" from "++pid2string from++" to "++maybe "-" pid2string mto | (fid, fns) <- M.toList fpspans, FpSpan fn from mto <- fns] dumpTouchingMap :: InfoMap -> String dumpTouchingMap infom = unlines [showFileId fid++(if isF then "" else "/")++" -> "++ showAsHex w32 | (fid,FileInfo isF w32s) <- M.toList infom, w32 <- S.elems w32s] -- | return set of current filepaths in patch index fpSpans2filePaths :: FilePathSpans -> InfoMap -> [FilePath] fpSpans2filePaths fpSpans infom = sort [fn2fp fn ++ (if isF then "" else "/") | (fid,FpSpan fn _ Nothing:_) <- M.toList fpSpans, let Just (FileInfo isF _) = M.lookup fid infom] -- | return set of current filepaths in patch index, for internal use fpSpans2filePaths' :: FileIdSpans -> [FilePath] fpSpans2filePaths' fidSpans = [fn2fp fp | (fp, _) <- M.toList fidSpans] -- | Checks if patch index can be created and build it with interrupt. attemptCreatePatchIndex :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> PatchSet rt p Origin wR -> IO () attemptCreatePatchIndex repo ps = do canCreate <- canCreatePI repo when canCreate $ createPIWithInterrupt repo ps -- | Checks whether a patch index can (and should) be created. If we are not in -- an old-fashioned repo, and if we haven't been told not to, then we should -- create a patch index if it doesn't already exist. canCreatePI :: Repository rt p wR wU wT -> IO Bool canCreatePI repo = (not . or) <$> sequence [ doesntHaveHashedInventory (repoFormat repo) , isPatchIndexDisabled repodir , doesPatchIndexExist repodir ] where repodir = repoLocation repo doesntHaveHashedInventory = return . not . formatHas HashedInventory -- | Returns an RL in which the order of patches matters. Useful for the @annotate@ command. -- If patch-index does not exist and is not explicitely disabled, silently create it. -- (Also, if it is out-of-sync, which should not happen, silently update it). getRelevantSubsequence :: (RepoPatch p, ApplyState p ~ Tree, a ~ PatchInfoAnd rt p) => Sealed ((RL a) wK) -- ^ Sequence of patches you want to filter -> Repository rt p wR wU wR -- ^ The repository (to attempt loading patch-index from its path) -> PatchSet rt p Origin wR -- ^ PatchSet of repository (in case we need to create patch-index) -> [FileName] -- ^ File(s) about which you want patches from given sequence -> IO (Sealed ((RL a) Origin)) -- ^ Filtered sequence of patches. getRelevantSubsequence pxes repository ps fns = do pi@(PatchIndex _ _ _ infom) <- loadSafePatchIndex repository ps let fids = map (\fn -> evalState (lookupFid fn) pi) fns pidss = map ((\(FileInfo _ a) -> a).fromJust.(`M.lookup` infom)) fids pids = S.unions pidss let flpxes = reverseRL $ unsafeUnseal pxes return.seal $ keepElems flpxes NilRL pids where keepElems :: (RepoPatch p, ApplyState p ~ Tree, a ~ PatchInfoAnd rt p) => FL a wX wY -> RL a wB wX -> S.Set Word32 -> RL a wP wQ keepElems NilFL acc _ = unsafeCoerceP acc keepElems (x:>:xs) acc pids | short (makePatchID $ info x) `S.member` pids = keepElems xs (acc:<:x) pids | otherwise = keepElems (unsafeCoerceP xs) acc pids type PatchFilter rt p = [FilePath] -> [Sealed2 (PatchInfoAnd rt p)] -> IO [Sealed2 (PatchInfoAnd rt p)] -- | If a patch index is available, returns a filter that takes a list of files and returns -- a @PatchFilter@ that only keeps patches that modify the given list of files. -- If patch-index cannot be used, return the original input. -- If patch-index does not exist and is not explicitely disabled, silently create it. -- (Also, if it is out-of-sync, which should not happen, silently update it). maybeFilterPatches :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -- ^ The repository -> PatchSet rt p Origin wR -- ^ PatchSet of patches of repository (in case patch-index needs to be created) -> PatchFilter rt p -- ^ PatchFilter ready to be used by SelectChanges. maybeFilterPatches repo ps fps ops = do usePI <- canUsePatchIndex repo if usePI then do pi@(PatchIndex _ _ _ infom) <- loadSafePatchIndex repo ps let fids = concatMap ((\fn -> evalState (lookupFids' fn) pi). fp2fn) fps npids = S.unions $ map (touching.fromJust.(`M.lookup` infom)) fids return $ filter (flip S.member npids . (\(Sealed2 (PIAP pin _)) -> short $ makePatchID pin)) ops else return ops -- | Dump information in patch index. Patch-index should be checked to exist beforehand. Read-only. dumpPatchIndex :: FilePath -> IO () dumpPatchIndex repodir = do (_,inv_hash,_,PatchIndex pids fidspans fpspans infom) <- loadPatchIndex repodir putStrLn $ unlines $ [ "Inventory hash:" ++ inv_hash , "=================" , "Repo state:" , "===========" , dumpRepoState pids , "Fileid spans:" , "=============" , dumpFileIdSpans fidspans , "Filepath spans:" , "==============" , dumpFilePathSpans fpspans , "Info Map:" , "=========" , dumpTouchingMap infom , "Files:" , "==============" ] ++ fpSpans2filePaths fpspans infom -- | Read-only sanity check on patch-index. Patch-index should be checked to exist beforehand. It may not be in sync with repository. piTest :: FilePath -> IO () piTest repodir = do (_,_,_,PatchIndex rpids fidspans fpspans infom) <- loadPatchIndex repodir let pids = reverse rpids -- test fidspans putStrLn "fidspans" putStrLn "===========" forM_ (M.toList fidspans) $ \(fn, spans) -> do let g :: FileIdSpan -> [PatchId] g (FidSpan _ x (Just y)) = [y,x] g (FidSpan _ x _) = [x] ascTs = reverse . nub . concat $ map g spans unless (isInOrder ascTs pids) (error $ "In order test failed! filename: " ++ show fn) forM_ spans $ \(FidSpan fid _ _) -> unless (M.member fid fpspans) (error $ "Valid file id test failed! fid: " ++ show fid) putStrLn "fidspans tests passed" -- test fpspans putStrLn "fpspans" putStrLn "===========" forM_ (M.toList fpspans) $ \(fid, spans) -> do let g :: FilePathSpan -> [PatchId] g (FpSpan _ x (Just y)) = [y,x] g (FpSpan _ x _) = [x] ascTs = reverse . nub . concat $ map g spans unless (isInOrder ascTs pids) (error $ "In order test failed! fileid: " ++ show fid) forM_ spans $ \(FpSpan fn _ _) -> unless (M.member fn fidspans) (error $ "Valid file name test failed! file name: " ++ show fn) let f :: FilePathSpan -> FilePathSpan -> Bool f (FpSpan _ x _) (FpSpan _ _ (Just y)) = x == y f _ _ = error "adj test of fpspans fail" unless (and $ zipWith f spans (tail spans)) (error $ "Adjcency test failed! fid: " ++ show fid) putStrLn "fpspans tests passed" -- test infomap putStrLn "infom" putStrLn "===========" putStrLn $ "Valid fid test: " ++ (show.and $ map (`M.member` fpspans) (M.keys infom)) putStrLn $ "Valid pid test: " ++ (show.flip S.isSubsetOf (S.fromList $ map short pids) . S.unions . map touching . M.elems $ infom) where isInOrder :: Eq a => [a] -> [a] -> Bool isInOrder (x:xs) (y:ys) | x == y = isInOrder xs ys | otherwise = isInOrder (x:xs) ys isInOrder [] _ = True isInOrder _ [] = False darcs-2.14.5/src/Darcs/Repository/Pending.hs0000644000000000000000000004177207346545000017025 0ustar0000000000000000-- Copyright (C) 2002-2004,2007-2008 David Roundy -- Copyright (C) 2005 Juliusz Chroboczek -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Repository.Pending ( readPending , siftForPending , tentativelyRemoveFromPending , finalizePending , makeNewPending , tentativelyAddToPending , setTentativePending , prepend -- deprecated interface: , pendingName ) where import Prelude () import Darcs.Prelude import Control.Applicative import qualified Data.ByteString as B ( empty ) import Control.Exception ( catch, IOException ) import Data.Maybe ( fromJust, fromMaybe ) import Darcs.Util.Printer ( errorDoc ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Lock ( writeDocBinFile , removeFileMayNotExist ) import Darcs.Repository.InternalTypes ( Repository, withRepoLocation ) import Darcs.Repository.Flags ( UpdateWorking (..)) import Darcs.Patch ( readPatch, RepoPatch, PrimOf, tryToShrink , primIsHunk, primIsBinary, commute, invert , primIsAddfile, primIsAdddir, commuteFLorComplain , effect, primIsSetpref, applyToTree ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd ) import Darcs.Patch.Progress (progressFL) import Darcs.Patch.Permutations ( commuteWhatWeCanFL , removeFL ) import Darcs.Patch.Prim ( tryShrinkingInverse , PrimPatch ) import Darcs.Patch.Read ( ReadPatch(..), bracketedFL ) import Darcs.Patch.ReadMonads ( ParserM ) import Darcs.Patch.Show ( ShowPatchBasic(..), ShowPatchFor(ForStorage) ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Util.Tree ( Tree ) import Darcs.Util.Exception ( catchall ) import Darcs.Util.Workaround ( renameFile ) import Darcs.Patch.Witnesses.Eq ( EqCheck(..) ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), mapSeal, seal , FlippedSeal(FlippedSeal) , flipSeal ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP, unsafeCoercePStart ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), (:>)(..), (+>+) , lengthFL, allFL, filterOutFLFL , reverseFL, mapFL ) import Darcs.Util.ByteString ( gzReadFilePS ) import Darcs.Util.Printer ( Doc, ($$), text, vcat, (<+>) ) import Darcs.Util.Progress ( debugMessage ) pendingName :: String pendingName = darcsdir ++ "/patches/pending" newSuffix, tentativeSuffix :: String newSuffix = ".new" tentativeSuffix = ".tentative" -- | Read the contents of pending. -- The return type is currently incorrect as it refers to the tentative -- state rather than the recorded state. readPending :: RepoPatch p => Repository rt p wR wU wT -> IO (Sealed (FL (PrimOf p) wT)) readPending = readPendingFile "" -- |Read the contents of tentative pending. readTentativePending :: RepoPatch p => Repository rt p wR wU wT -> IO (Sealed (FL (PrimOf p) wT)) readTentativePending = readPendingFile tentativeSuffix -- |Read the contents of tentative pending. readNewPending :: RepoPatch p => Repository rt p wR wU wT -> IO (Sealed (FL (PrimOf p) wT)) readNewPending = readPendingFile newSuffix -- |Read the pending file with the given suffix. CWD should be the repository -- directory. readPendingFile :: ReadPatch prim => String -> Repository rt p wR wU wT -> IO (Sealed (FL prim wX)) readPendingFile suffix _ = do pend <- gzReadFilePS (pendingName ++ suffix) `catchall` return B.empty return . maybe (Sealed NilFL) (mapSeal unFLM) . readPatch $ pend -- Wrapper around FL where printed format uses { } except around singletons. -- Now that the Show behaviour of FL p can be customised (using -- showFLBehavior (*)), we could instead change the general behaviour of FL Prim; -- but since the pending code can be kept nicely compartmentalised, it's nicer -- to do it this way. -- (*) bf: This function does not exist. newtype FLM p wX wY = FLM { unFLM :: FL p wX wY } instance ReadPatch p => ReadPatch (FLM p) where readPatch' = mapSeal FLM <$> readMaybeBracketedFL readPatch' '{' '}' instance ShowPatchBasic p => ShowPatchBasic (FLM p) where showPatch f = showMaybeBracketedFL (showPatch f) '{' '}' . unFLM readMaybeBracketedFL :: forall m p wX . ParserM m => (forall wY . m (Sealed (p wY))) -> Char -> Char -> m (Sealed (FL p wX)) readMaybeBracketedFL parser pre post = bracketedFL parser pre post <|> (mapSeal (:>:NilFL) <$> parser) showMaybeBracketedFL :: (forall wX wY . p wX wY -> Doc) -> Char -> Char -> FL p wA wB -> Doc showMaybeBracketedFL _ pre post NilFL = text [pre] $$ text [post] showMaybeBracketedFL printer _ _ (p :>: NilFL) = printer p showMaybeBracketedFL printer pre post ps = text [pre] $$ vcat (mapFL printer ps) $$ text [post] -- |Write the contents of tentative pending. writeTentativePending :: RepoPatch p => Repository rt p wR wU wT -> FL (PrimOf p) wT wY -> IO () writeTentativePending = writePendingFile tentativeSuffix -- |Write the contents of new pending. CWD should be the repository directory. writeNewPending :: RepoPatch p => Repository rt p wR wU wT -> FL (PrimOf p) wT wY -> IO () writeNewPending = writePendingFile newSuffix -- Write a pending file, with the given suffix. CWD should be the repository -- directory. writePendingFile :: ShowPatchBasic prim => String -> Repository rt p wR wU wT -> FL prim wX wY -> IO () writePendingFile suffix _ = writePatch name . FLM where name = pendingName ++ suffix writePatch :: ShowPatchBasic p => FilePath -> p wX wY -> IO () writePatch f p = writeDocBinFile f $ showPatch ForStorage p <> text "\n" -- | @siftForPending ps@ simplifies the candidate pending patch @ps@ -- through a combination of looking for self-cancellations -- (sequences of patches followed by their inverses), coalescing, -- and getting rid of any hunk/binary patches we can commute out -- the back -- -- The visual image of sifting can be quite helpful here. We are -- repeatedly tapping (shrinking) the patch sequence and -- shaking it (sift). Whatever falls out is the pending we want -- to keep. We do this until the sequence looks about as clean as -- we can get it siftForPending :: forall prim wX wY . PrimPatch prim => FL prim wX wY -> Sealed (FL prim wX) siftForPending simple_ps = if allFL (\p -> primIsAddfile p || primIsAdddir p) oldps then seal oldps else fromJust $ do Sealed x <- return $ sift NilFL $ reverseFL oldps return $ case tryToShrink x of ps | lengthFL ps < lengthFL oldps -> siftForPending ps | otherwise -> seal ps where oldps = fromMaybe simple_ps $ tryShrinkingInverse $ crudeSift simple_ps -- get rid of any hunk/binary patches that we can commute out the -- back (ie. we work our way backwards, pushing the patches down -- to the very end and popping them off; so in (addfile f :> hunk) -- we can nuke the hunk, but not so in (hunk :> replace) sift :: FL prim wA wB -> RL prim wC wA -> Sealed (FL prim wC) sift sofar NilRL = seal sofar sift sofar (ps:<:p) | primIsHunk p || primIsBinary p = case commuteFLorComplain (p :> sofar) of Right (sofar' :> _) -> sift sofar' ps Left _ -> sift (p:>:sofar) ps sift sofar (ps:<:p) = sift (p:>:sofar) ps -- | 'crudeSift' can be seen as a first pass approximation of 'siftForPending' -- that works without having to do any commutation. It either returns a -- sifted pending (if the input is simple enough for this crude approach) -- or has no effect. crudeSift :: forall prim wX wY . PrimPatch prim => FL prim wX wY -> FL prim wX wY crudeSift xs = if isSimple xs then filterOutFLFL ishunkbinary xs else xs where ishunkbinary :: prim wA wB -> EqCheck wA wB ishunkbinary x | primIsHunk x || primIsBinary x = unsafeCoerceP IsEq | otherwise = NotEq -- | @tentativelyRemoveFromPending p@ is used by Darcs whenever it -- adds a patch to the repository (eg. with apply or record). -- Think of it as one part of transferring patches from pending to -- somewhere else. -- -- Question (Eric Kow): how do we detect patch equivalence? tentativelyRemoveFromPending :: forall rt p wR wU wT wX wY. (RepoPatch p) => Repository rt p wR wU wT -> UpdateWorking -> PatchInfoAnd rt p wX wY -> IO () tentativelyRemoveFromPending _ NoUpdateWorking _ = return () tentativelyRemoveFromPending repo YesUpdateWorking p = do Sealed pend <- readTentativePending repo -- Question (Eric Kow): why does pending being all simple matter for -- changepref patches in p? isSimple includes changepref, so what do -- adddir/etc have to do with it? Why don't we we systematically -- crudeSift/not? let effectp = if isSimple pend then crudeSift $ effect p else effect p Sealed newpend <- return $ rmpend (progressFL "Removing from pending:" effectp) (unsafeCoercePStart pend) writeTentativePending repo (unsafeCoercePStart newpend) where -- @rmpend effect pending@ removes as much of @effect@ from @pending@ -- as possible -- -- Note that @effect@ and @pending@ must start from the same context -- This is not a bad thing to assume because @effect@ is a patch we want to -- add to the repository anyway so it'd kind of have to start from wR anyway -- -- Question (Eric Kow), ok then why not -- @PatchInfoAnd p wR wY@ in the type signature above? rmpend :: FL (PrimOf p) wA wB -> FL (PrimOf p) wA wC -> Sealed (FL (PrimOf p) wB) rmpend NilFL x = Sealed x rmpend _ NilFL = Sealed NilFL rmpend (x:>:xs) xys | Just ys <- removeFL x xys = rmpend xs ys rmpend (x:>:xs) ys = case commuteWhatWeCanFL (x:>xs) of a:>x':>b -> case rmpend a ys of Sealed ys' -> case commute (invert (x':>:b) :> ys') of Just (ys'' :> _) -> seal ys'' Nothing -> seal $ invert (x':>:b)+>+ys' -- DJR: I don't think this last case should be -- reached, but it also shouldn't lead to corruption. -- | A sequence of primitive patches (candidates for the pending patch) -- is considered simple if we can reason about their continued status as -- pending patches solely on the basis of them being hunk/binary patches. -- -- Simple here seems to mean that all patches are either hunk/binary -- patches, or patches that cannot (indirectly) depend on hunk/binary -- patches. For now, the only other kinds of patches in this category -- are changepref patches. -- -- It might be tempting to add, say, adddir patches but it's probably not a -- good idea because Darcs also inverts patches a lot in its reasoning so an -- innocent addir may be inverted to a rmdir which in turn may depend on -- a rmfile, which in turn depends on a hunk/binary. Likewise, we would -- not want to add move patches to this category for similar reasons of -- a potential dependency chain forming. isSimple :: PrimPatch prim => FL prim wX wY -> Bool isSimple = allFL isSimp where isSimp x = primIsHunk x || primIsBinary x || primIsSetpref x -- | @makeNewPending repo YesUpdateWorking pendPs@ verifies that the -- @pendPs@ could be applied to pristine if we wanted to, and if so -- writes it to disk. If it can't be applied, @pendPs@ must -- be somehow buggy, so we save it for forensics and crash. makeNewPending :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> UpdateWorking -> FL (PrimOf p) wT wY -> Tree IO -- ^recorded state of the repository, to check if pending can be applied -> IO () makeNewPending _ NoUpdateWorking _ _ = return () makeNewPending repo YesUpdateWorking origp recordedState = withRepoLocation repo $ do let newname = pendingName ++ ".new" debugMessage $ "Writing new pending: " ++ newname Sealed sfp <- return $ siftForPending origp writeNewPending repo sfp Sealed p <- readNewPending repo -- We don't ever use the resulting tree. _ <- catch (applyToTree p recordedState) $ \(err :: IOException) -> do let buggyname = pendingName ++ "_buggy" renameFile newname buggyname errorDoc $ text ("There was an attempt to write an invalid pending! " ++ show err) $$ text "If possible, please send the contents of" <+> text buggyname $$ text "along with a bug report." renameFile newname pendingName debugMessage $ "Finished writing new pending: " ++ newname -- | Replace the pending patch with the tentative pending. -- If @NoUpdateWorking@, this merely deletes the tentative pending -- without replacing the current one. -- -- Question (Eric Kow): shouldn't this also delete the tentative -- pending if @YesUpdateWorking@? I'm just puzzled by the seeming -- inconsistency of the @NoUpdateWorking@ doing deletion, but -- @YesUpdateWorking@ not bothering. finalizePending :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> UpdateWorking -> Tree IO -> IO () finalizePending repo NoUpdateWorking _ = withRepoLocation repo $ removeFileMayNotExist pendingName finalizePending repo updateWorking@YesUpdateWorking recordedState = withRepoLocation repo $ do Sealed tpend <- readTentativePending repo Sealed new_pending <- return $ siftForPending tpend makeNewPending repo updateWorking new_pending recordedState -- | @tentativelyAddToPending repo NoDryRun YesUpdateWorking pend ps@ -- appends @ps@ to the pending patch. -- -- It has no effect with @NoUpdateWorking@. -- -- This fuction is unsafe because it accepts a patch that works on the -- tentative pending and we don't currently track the state of the -- tentative pending. tentativelyAddToPending :: forall rt p wR wU wT wX wY. RepoPatch p => Repository rt p wR wU wT -> UpdateWorking -> FL (PrimOf p) wX wY -> IO () tentativelyAddToPending _ NoUpdateWorking _ = return () tentativelyAddToPending repo YesUpdateWorking patch = withRepoLocation repo $ do Sealed pend <- readTentativePending repo FlippedSeal newpend_ <- return $ newpend (unsafeCoerceP pend :: FL (PrimOf p) wA wX) patch writeTentativePending repo (unsafeCoercePStart newpend_) where newpend :: FL prim wA wB -> FL prim wB wC -> FlippedSeal (FL prim) wC newpend NilFL patch_ = flipSeal patch_ newpend p patch_ = flipSeal $ p +>+ patch_ -- | setTentativePending is basically unsafe. It overwrites the pending -- state with a new one, not related to the repository state. setTentativePending :: forall rt p wR wU wT wX wY. RepoPatch p => Repository rt p wR wU wT -> UpdateWorking -> FL (PrimOf p) wX wY -> IO () setTentativePending _ NoUpdateWorking _ = return () setTentativePending repo YesUpdateWorking patch = do Sealed prims <- return $ siftForPending patch withRepoLocation repo $ writeTentativePending repo (unsafeCoercePStart prims) -- | @prepend repo YesUpdateWorking ps@ prepends @ps@ to the pending patch -- It's used right before removing @ps@ from the repo. This ensures that -- the pending patch can still be applied on top of the recorded state. -- -- This function is basically unsafe. It overwrites the pending state -- with a new one, not related to the repository state. prepend :: forall rt p wR wU wT wX wY. RepoPatch p => Repository rt p wR wU wT -> UpdateWorking -> FL (PrimOf p) wX wY -> IO () prepend _ NoUpdateWorking _ = return () prepend repo YesUpdateWorking patch = do Sealed pend <- readTentativePending repo Sealed newpend_ <- return $ newpend (unsafeCoerceP pend) patch writeTentativePending repo (unsafeCoercePStart $ crudeSift newpend_) where newpend :: FL prim wB wC -> FL prim wA wB -> Sealed (FL prim wA) newpend NilFL patch_ = seal patch_ newpend p patch_ = seal $ patch_ +>+ p darcs-2.14.5/src/Darcs/Repository/Prefs.hs0000644000000000000000000006562607346545000016524 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Repository.Prefs ( addToPreflist , deleteSources , getPreflist , setPreflist , getGlobal , environmentHelpHome , defaultrepo , getDefaultRepoPath , addRepoSource , getPrefval , setPrefval , changePrefval , defPrefval , writeDefaultPrefs , boringRegexps , boringFileFilter , darcsdirFilter , FileType(..) , filetypeFunction , getCaches , globalCacheDir , globalPrefsDirDoc , globalPrefsDir , getMotd , showMotd , prefsUrl , prefsDirPath -- * documentation of prefs files , prefsFilesHelp ) where import Prelude () import Darcs.Prelude import Control.Exception ( catch ) import Control.Monad ( unless, when, liftM ) import Data.Char ( toUpper ) import Data.List ( nub, isPrefixOf, union, sortBy, lookup ) import Data.Maybe ( isJust, fromMaybe, mapMaybe, catMaybes, maybeToList ) import qualified Control.Exception as C import qualified Data.ByteString as B ( empty, null, hPut, ByteString ) import qualified Data.ByteString.Char8 as BC ( unpack ) import System.Directory ( getAppUserDataDirectory, doesDirectoryExist, createDirectory, doesFileExist ) import System.Environment ( getEnvironment ) import System.FilePath.Posix ( normalise, dropTrailingPathSeparator, () ) import System.IO.Error ( isDoesNotExistError ) import System.IO ( stdout, stderr ) import System.Info ( os ) import Text.Regex ( Regex, mkRegex, matchRegex ) import Darcs.Repository.Cache ( Cache(..), CacheType(..), CacheLoc(..), WritableOrNot(..), compareByLocality ) import Darcs.Util.External ( gzFetchFilePS , fetchFilePS, Cachable(..)) import Darcs.Repository.Flags( UseCache (..), DryRun (..), SetDefault (..), RemoteRepos (..) ) import Darcs.Util.Lock( readTextFile, writeTextFile ) import Darcs.Util.Exception ( catchall ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Path ( AbsolutePath, ioAbsolute, toFilePath, getCurrentDirectory ) import Darcs.Util.Printer( hPutDocLn, text ) import Darcs.Util.URL ( isValidLocalPath ) import Darcs.Util.File ( osxCacheDir, xdgCacheDir, removeFileMayNotExist ) windows,osx :: Bool windows = "mingw" `isPrefixOf` os -- GHC under Windows is compiled with mingw osx = os == "darwin" writeDefaultPrefs :: IO () writeDefaultPrefs = do setPreflist "boring" defaultBoring setPreflist "binaries" defaultBinaries setPreflist "motd" [] defaultBoring :: [String] defaultBoring = map ("# " ++) boringFileInternalHelp ++ [ "" , "### compiler and interpreter intermediate files" , "# haskell (ghc) interfaces" , "\\.hi$", "\\.hi-boot$", "\\.o-boot$" , "# object files" , "\\.o$","\\.o\\.cmd$" , "# profiling haskell" , "\\.p_hi$", "\\.p_o$" , "# haskell program coverage resp. profiling info" , "\\.tix$", "\\.prof$" , "# fortran module files" , "\\.mod$" , "# linux kernel" , "\\.ko\\.cmd$","\\.mod\\.c$" , "(^|/)\\.tmp_versions($|/)" , "# *.ko files aren't boring by default because they might" , "# be Korean translations rather than kernel modules" , "# \\.ko$" , "# python, emacs, java byte code" , "\\.py[co]$", "\\.elc$","\\.class$" , "# objects and libraries; lo and la are libtool things" , "\\.(obj|a|exe|so|lo|la)$" , "# compiled zsh configuration files" , "\\.zwc$" , "# Common LISP output files for CLISP and CMUCL" , "\\.(fas|fasl|sparcf|x86f)$" , "" , "### build and packaging systems" , "# cabal intermediates" , "\\.installed-pkg-config" , "\\.setup-config" , "# standard cabal build dir, might not be boring for everybody" , "# ^dist(/|$)" , "# autotools" , "(^|/)autom4te\\.cache($|/)", "(^|/)config\\.(log|status)$" , "# microsoft web expression, visual studio metadata directories" , "\\_vti_cnf$" , "\\_vti_pvt$" , "# gentoo tools" , "\\.revdep-rebuild.*" , "# generated dependencies" , "^\\.depend$" , "" , "### version control systems" , "# cvs" , "(^|/)CVS($|/)","\\.cvsignore$" , "# cvs, emacs locks" , "^\\.#" , "# rcs" , "(^|/)RCS($|/)", ",v$" , "# subversion" , "(^|/)\\.svn($|/)" , "# mercurial" , "(^|/)\\.hg($|/)" , "# git" , "(^|/)\\.git($|/)" , "# bzr" , "\\.bzr$" , "# sccs" , "(^|/)SCCS($|/)" , "# darcs" , "(^|/)"++darcsdir++"($|/)", "(^|/)\\.darcsrepo($|/)" , "# gnu arch" , "(^|/)(\\+|,)" , "(^|/)vssver\\.scc$" , "\\.swp$","(^|/)MT($|/)" , "(^|/)\\{arch\\}($|/)","(^|/).arch-ids($|/)" , "# bitkeeper" , "(^|/)BitKeeper($|/)","(^|/)ChangeSet($|/)" , "" , "### miscellaneous" , "# backup files" , "~$","\\.bak$","\\.BAK$" , "# patch originals and rejects" , "\\.orig$", "\\.rej$" , "# X server" , "\\..serverauth.*" , "# image spam" , "\\#", "(^|/)Thumbs\\.db$" , "# vi, emacs tags" , "(^|/)(tags|TAGS)$" , "#(^|/)\\.[^/]" , "# core dumps" , "(^|/|\\.)core$" , "# partial broken files (KIO copy operations)" , "\\.part$" , "# waf files, see http://code.google.com/p/waf/" , "(^|/)\\.waf-[[:digit:].]+-[[:digit:]]+($|/)" , "(^|/)\\.lock-wscript$" , "# mac os finder" , "(^|/)\\.DS_Store$" , "# emacs saved sessions (desktops)" , "(^|.*/)\\.emacs\\.desktop(\\.lock)?$" ] boringFileInternalHelp :: [String] boringFileInternalHelp = [ "This file contains a list of extended regular expressions, one per" , "line. A file path matching any of these expressions will be filtered" , "out during `darcs add`, or when the `--look-for-adds` flag is passed" , "to `darcs whatsnew` and `record`. The entries in " ++ globalPrefsDirDoc ++ "boring (if" , "it exists) supplement those in this file." , "" , "Blank lines, and lines beginning with an octothorpe (#) are ignored." , "See regex(7) for a description of extended regular expressions." ] darcsdirFilter :: [FilePath] -> [FilePath] darcsdirFilter = filter (not . isDarcsdir) isDarcsdir :: FilePath -> Bool isDarcsdir ('.' : '/' : f) = isDarcsdir f isDarcsdir "." = True isDarcsdir "" = True isDarcsdir ".." = True isDarcsdir "../" = True isDarcsdir fp = (darcsdir ++ "/") `isPrefixOf` fp || fp == darcsdir -- | The path of the global preference directory; @~/.darcs@ on Unix, -- and @%APPDATA%/darcs@ on Windows. globalPrefsDir :: IO (Maybe FilePath) globalPrefsDir = do env <- getEnvironment case lookup "DARCS_TESTING_PREFS_DIR" env of Just d -> return (Just d) Nothing -> Just `fmap` getAppUserDataDirectory "darcs" `catchall` return Nothing -- | The relative path of the global preference directory; @~/.darcs@ on Unix, -- and @%APPDATA%/darcs@ on Windows. This is used for online documentation. globalPrefsDirDoc :: String globalPrefsDirDoc | windows = "%APPDATA%\\darcs\\" | otherwise = "~/.darcs/" environmentHelpHome :: ([String], [String]) environmentHelpHome = ( ["HOME", "APPDATA"] , [ "Per-user preferences are set in $HOME/.darcs (on Unix) or" , "%APPDATA%/darcs (on Windows). This is also the default location of" , "the cache." ] ) getGlobal :: String -> IO [String] getGlobal f = do dir <- globalPrefsDir case dir of (Just d) -> getPreffile $ d f Nothing -> return [] globalCacheDir :: IO (Maybe FilePath) globalCacheDir | windows = (( "cache2") `fmap`) `fmap` globalPrefsDir | osx = (( "darcs") `fmap`) `fmap` osxCacheDir | otherwise = (( "darcs") `fmap`) `fmap` xdgCacheDir -- |tryMakeBoringRegexp attempts to create a Regex from a given String. The -- evaluation is forced, to ensure any malformed exceptions are thrown here, -- and not later. tryMakeBoringRegexp :: String -> IO (Maybe Regex) tryMakeBoringRegexp input = regex `C.catch` handleBadRegex where regex = C.evaluate (Just $! mkRegex input) handleBadRegex :: C.SomeException -> IO (Maybe Regex) handleBadRegex _ = hPutDocLn stderr warning >> return Nothing warning = text $ "Warning: Ignored invalid boring regex: " ++ input -- |boringRegexps returns a list of the boring regexps, from the local and -- global prefs/boring files. Any invalid regexps are filtered, preventing an -- exception in (potentially) pure code, when the regexps are used. boringRegexps :: IO [Regex] boringRegexps = do borefile <- defPrefval "boringfile" (darcsdir ++ "/prefs/boring") localBores <- getPrefLines borefile `catchall` return [] globalBores <- getGlobal "boring" liftM catMaybes $ mapM tryMakeBoringRegexp $ localBores ++ globalBores boringFileFilter :: IO ([FilePath] -> [FilePath]) boringFileFilter = filterBoringAndDarcsdir `fmap` boringRegexps where filterBoringAndDarcsdir regexps = filter (notBoring regexps . doNormalise) notBoring regexps file = not $ isDarcsdir file || any (\r -> isJust $ matchRegex r file) regexps noncomments :: [String] -> [String] noncomments = filter nonComment where nonComment "" = False nonComment ('#' : _) = False nonComment _ = True getPrefLines :: FilePath -> IO [String] getPrefLines f = removeCRsCommentsAndConflicts `fmap` readTextFile f where removeCRsCommentsAndConflicts = filter notconflict . noncomments . map stripCr startswith [] _ = True startswith (x : xs) (y : ys) = x == y && startswith xs ys startswith _ _ = False notconflict l | startswith "v v v v v v v" l = False | startswith "*************" l = False | startswith "^ ^ ^ ^ ^ ^ ^" l = False | otherwise = True stripCr "" = "" stripCr "\r" = "" stripCr (c : cs) = c : stripCr cs doNormalise :: FilePath -> FilePath doNormalise = dropTrailingPathSeparator . normalise data FileType = BinaryFile | TextFile deriving (Eq) -- | The lines that will be inserted into @_darcs/prefs/binaries@ when -- @darcs init@ is run. Hence, a list of comments, blank lines and -- regular expressions (ERE dialect). -- -- Note that while this matches .gz and .GZ, it will not match .gZ, -- i.e. it is not truly case insensitive. defaultBinaries :: [String] defaultBinaries = map ("# "++) binariesFileInternalHelp ++ [ "\\." ++ regexToMatchOrigOrUpper e ++ "$" | e <- extensions ] where regexToMatchOrigOrUpper e = "(" ++ e ++ "|" ++ map toUpper e ++ ")" extensions = [ "a" , "bmp" , "bz2" , "doc" , "elc" , "exe" , "gif" , "gz" , "iso" , "jar" , "jpe?g" , "mng" , "mpe?g" , "p[nbgp]m" , "pdf" , "png" , "pyc" , "so" , "tar" , "tgz" , "tiff?" , "z" , "zip" ] binariesFileInternalHelp :: [String] binariesFileInternalHelp = [ "This file contains a list of extended regular expressions, one per" , "line. A file path matching any of these expressions is assumed to" , "contain binary data (not text). The entries in " ++ globalPrefsDirDoc ++ "binaries (if" , "it exists) supplement those in this file." , "" , "Blank lines, and lines beginning with an octothorpe (#) are ignored." , "See regex(7) for a description of extended regular expressions." ] filetypeFunction :: IO (FilePath -> FileType) filetypeFunction = do binsfile <- defPrefval "binariesfile" (darcsdir ++ "/prefs/binaries") bins <- getPrefLines binsfile `catch` (\e -> if isDoesNotExistError e then return [] else ioError e) gbs <- getGlobal "binaries" let binaryRegexes = map mkRegex (bins ++ gbs) isBinary f = any (\r -> isJust $ matchRegex r f) binaryRegexes ftf f = if isBinary $ doNormalise f then BinaryFile else TextFile return ftf findPrefsDirectory :: IO (Maybe String) findPrefsDirectory = do inDarcsRepo <- doesDirectoryExist darcsdir return $ if inDarcsRepo then Just $ darcsdir ++ "/prefs/" else Nothing withPrefsDirectory :: (String -> IO ()) -> IO () withPrefsDirectory job = findPrefsDirectory >>= maybe (return ()) job addToPreflist :: String -> String -> IO () addToPreflist pref value = withPrefsDirectory $ \prefs -> do hasprefs <- doesDirectoryExist prefs unless hasprefs $ createDirectory prefs pl <- getPreflist pref writeTextFile (prefs ++ pref) . unlines $ union [value] pl getPreflist :: String -> IO [String] getPreflist p = findPrefsDirectory >>= maybe (return []) (\prefs -> getPreffile $ prefs ++ p) getPreffile :: FilePath -> IO [String] getPreffile f = do hasprefs <- doesFileExist f if hasprefs then getPrefLines f else return [] setPreflist :: String -> [String] -> IO () setPreflist p ls = withPrefsDirectory $ \prefs -> do haspref <- doesDirectoryExist prefs when haspref $ writeTextFile (prefs ++ p) (unlines ls) defPrefval :: String -> String -> IO String defPrefval p d = fromMaybe d `fmap` getPrefval p getPrefval :: String -> IO (Maybe String) getPrefval p = do pl <- getPreflist prefsDir return $ case map snd $ filter ((== p) . fst) $ map (break (== ' ')) pl of [val] -> case words val of [] -> Nothing _ -> Just $ tail val _ -> Nothing setPrefval :: String -> String -> IO () setPrefval p v = do pl <- getPreflist prefsDir setPreflist prefsDir $ updatePrefVal pl p v updatePrefVal :: [String] -> String -> String -> [String] updatePrefVal prefList p newVal = filter ((/= p) . fst . break (== ' ')) prefList ++ [p ++ " " ++ newVal] changePrefval :: String -> String -> String -> IO () changePrefval p f t = do pl <- getPreflist prefsDir ov <- getPrefval p let newval = maybe t (\old -> if old == f then t else old) ov setPreflist prefsDir $ updatePrefVal pl p newval fixRepoPath :: String -> IO FilePath fixRepoPath p | isValidLocalPath p = toFilePath `fmap` ioAbsolute p | otherwise = return p defaultrepo :: RemoteRepos -> AbsolutePath -> [String] -> IO [String] defaultrepo (RemoteRepos rrepos) _ [] = do case rrepos of [] -> maybeToList `fmap` getDefaultRepoPath rs -> mapM fixRepoPath rs defaultrepo _ _ r = return r getDefaultRepoPath :: IO (Maybe String) getDefaultRepoPath = do defaults <- getPreflist defaultRepoPref case defaults of [] -> return Nothing (d : _) -> Just `fmap` fixRepoPath d defaultRepoPref :: String defaultRepoPref = "defaultrepo" -- | addRepoSource adds a new entry to _darcs/prefs/repos and sets it as default -- in _darcs/prefs/defaultrepo, unless --no-set-default or --dry-run is passed, -- or it is the same repository as the current one. addRepoSource :: String -> DryRun -> RemoteRepos -> SetDefault -> IO () addRepoSource r isDryRun (RemoteRepos rrepos) setDefault = (do olddef <- getPreflist defaultRepoPref let shouldDoIt = null noSetDefault && greenLight greenLight = shouldAct && not rIsTmp && (olddef /= [r] || olddef == []) -- the nuance here is that we should only notify when the reason we're not -- setting default is the --no-set-default flag, not the various automatic -- show stoppers if shouldDoIt then setPreflist defaultRepoPref [r] else when (True `notElem` noSetDefault && greenLight) $ putStr . unlines $ setDefaultMsg addToPreflist "repos" r) `catchall` return () where shouldAct = isDryRun == NoDryRun rIsTmp = r `elem` rrepos noSetDefault = case setDefault of NoSetDefault x -> [x] _ -> [] setDefaultMsg = [ "HINT: if you want to change the default remote repository to" , " " ++ r ++ "," , " quit now and issue the same command with the --set-default " ++ "flag." ] -- | delete references to other repositories. -- Used when cloning to a ssh destination. -- Assume the current working dir is the repository. deleteSources :: IO () deleteSources = do let prefsdir = darcsdir ++ "/prefs/" removeFileMayNotExist (prefsdir ++ "sources") removeFileMayNotExist (prefsdir ++ "repos") getCaches :: UseCache -> String -> IO Cache getCaches useCache repodir = do here <- parsehs `fmap` getPreffile sourcesFile there <- (parsehs . lines . BC.unpack) `fmap` (gzFetchFilePS (repodir sourcesFile) Cachable `catchall` return B.empty) globalcachedir <- globalCacheDir let globalcache = if nocache then [] else case globalcachedir of Nothing -> [] Just d -> [Cache Directory Writable d] globalsources <- parsehs `fmap` getGlobal "sources" thisdir <- getCurrentDirectory let thisrepo = [Cache Repo Writable $ toFilePath thisdir] thatrepo = [Cache Repo NotWritable repodir] tempCache = nub $ thisrepo ++ globalcache ++ globalsources ++ here ++ thatrepo ++ filterExternalSources there return $ Ca $ sortBy compareByLocality tempCache where sourcesFile = darcsdir ++ "/prefs/sources" parsehs = mapMaybe readln . noncomments readln l | "repo:" `isPrefixOf` l = Just (Cache Repo NotWritable (drop 5 l)) | nocache = Nothing | "cache:" `isPrefixOf` l = Just (Cache Directory Writable (drop 6 l)) | "readonly:" `isPrefixOf` l = Just (Cache Directory NotWritable (drop 9 l)) | otherwise = Nothing nocache = useCache == NoUseCache filterExternalSources there = if isValidLocalPath repodir then there else filter (not . isValidLocalPath . cacheSource) there -- | Fetch and return the message of the day for a given repository. getMotd :: String -> IO B.ByteString getMotd repo = fetchFilePS motdPath (MaxAge 600) `catchall` return B.empty where motdPath = repo ++ "/" ++ darcsdir ++ "/prefs/motd" -- | Display the message of the day for a given repository, showMotd :: String -> IO () showMotd repo = do motd <- getMotd repo unless (B.null motd) $ do B.hPut stdout motd putStrLn $ replicate 22 '*' prefsUrl :: FilePath -> String prefsUrl r = r ++ "/"++darcsdir++"/prefs" prefsDir :: FilePath prefsDir = "prefs" prefsDirPath :: FilePath prefsDirPath = darcsdir prefsDir prefsFilesHelp :: [(String,String)] prefsFilesHelp = [ ("motd", unlines [ "The `_darcs/prefs/motd` file may contain a 'message of the day' which" , "will be displayed to users who clone or pull from the repository without" , "the `--quiet` option."]) , ("email", unlines [ "The `_darcs/prefs/email` file is used to provide the e-mail address for" , "your repository that others will use when they `darcs send` a patch back" , "to you. The contents of the file should simply be an e-mail address."]) , ("post", unlines [ "If `_darcs/prefs/post` exists in the target repository, `darcs send ` will" , "upload to the URL contained in that file, which may either be a `mailto:`" , "URL, or an `http://` URL. In the latter case, the patch is posted to that URL."]) , ("author", unlines [ "The `_darcs/prefs/author` file contains the email address (or name) to" , "be used as the author when patches are recorded in this repository," , "e.g. `David Roundy `. This file overrides the" , "contents of the environment variables `$DARCS_EMAIL` and `$EMAIL`."]) , ("defaults", unlines [ "Default values for darcs commands. Each line of this file has the" , "following form:" , "" , " COMMAND FLAG VALUE" , "" , "where `COMMAND` is either the name of the command to which the default" , "applies, or `ALL` to indicate that the default applies to all commands" , "accepting that flag. The `FLAG` term is the name of the long argument" , "option without the `--`, i.e. `verbose` rather than `--verbose`." , "Finally, the `VALUE` option can be omitted if the flag does not involve" , "a value. If the value has spaces in it, use single quotes, not double" , "quotes, to surround it. Each line only takes one flag. To set multiple" , "defaults for the same command (or for `ALL` commands), use multiple lines." , "" , "Note that the use of `ALL` easily can have unpredicted consequences," , "especially if commands in newer versions of darcs accepts flags that" , "they did not in previous versions. Only use safe flags with `ALL`." , "" , "For example, if your system clock is bizarre, you could instruct darcs to" , "always ignore the file modification times by adding the following line:" , "" , " ALL ignore-times" , "" , "There are some options which are meant specifically for use in" , "`_darcs/prefs/defaults`. One of them is `--disable`. As the name" , "suggests, this option will disable every command that got it as" , "argument. So, if you are afraid that you could damage your repositories" , "by inadvertent use of a command like amend, add the following line:" , "" , " amend disable" , "" , "Also, a global preferences file can be created with the name" , "`.darcs/defaults` in your home directory. Options present there will be" , "added to the repository-specific preferences if they do not conflict."]) , ("sources", unlines [ "The `_darcs/prefs/sources` file is used to indicate alternative locations" , "from which to download patches. This file contains lines such as:" , "" , " cache:/home/droundy/.cache/darcs" , " readonly:/home/otheruser/.cache/darcs" , " repo:http://darcs.net" , "" , "This would indicate that darcs should first look in" , "`/home/droundy/.cache/darcs` for patches that might be missing, and if" , "the patch is not there, it should save a copy there for future use." , "In that case, darcs will look in `/home/otheruser/.cache/darcs` to see if" , "that user might have downloaded a copy, but will not try to save a copy" , "there, of course. Finally, it will look in `http://darcs.net`. Note that" , "the `sources` file can also exist in `~/.darcs/`. Also note that the" , "sources mentioned in your `sources` file will be tried *before* the" , "repository you are pulling from. This can be useful in avoiding" , "downloading patches multiple times when you pull from a remote" , "repository to more than one local repository." , "" , "A global cache is enabled by default in your home directory. The cache" , "allows darcs to avoid re-downloading patches (for example, when doing a" , "second darcs clone of the same repository), and also allows darcs to use" , "hard links to reduce disk usage." , "" , "Note that the cache directory should reside on the same filesystem as" , "your repositories, so you may need to vary this. You can also use" , "multiple cache directories on different filesystems, if you have several" , "filesystems on which you use darcs."]) , ("boring", unlines [ "The `_darcs/prefs/boring` file may contain a list of regular expressions" , "describing files, such as object files, that you do not expect to add to" , "your project. A newly created repository has a boring file that includes" , "many common source control, backup, temporary, and compiled files." , "" , "You may want to have the boring file under version control. To do this" , "you can use darcs setpref to set the value 'boringfile' to the name of" , "your desired boring file (e.g. `darcs setpref boringfile .boring`, where" , "`.boring` is the repository path of a file that has been darcs added to" , "your repository). The boringfile preference overrides" , "`_darcs/prefs/boring`, so be sure to copy that file to the boringfile." , "" , "You can also set up a 'boring' regexps file in your home directory, named" , "`~/.darcs/boring`, which will be used with all of your darcs repositories." , "" , "Any file not already managed by darcs and whose repository path" , "matches any of the boring regular expressions is" , "considered boring. The boring file is used to filter the files provided" , "to darcs add, to allow you to use a simple `darcs add newdir newdir/*`" , "without accidentally adding a bunch of object files. It is also used" , "when the `--look-for-adds` flag is given to whatsnew or record. Note" , "that once a file has been added to darcs, it is not considered boring," , "even if it matches the boring file filter."]) , ("binaries", unlines [ "The `_darcs/prefs/binaries` file may contain a list of regular" , "expressions describing files that should be treated as binary files rather" , "than text files. Darcs automatically treats files containing characters" , "`^Z` or `NULL` within the first 4096 bytes as being binary files." , "You probably will want to have the binaries file under version control." , "To do this you can use `darcs setpref` to set the value 'binariesfile'" , "to the name of your desired binaries file" , "(e.g. `darcs setpref binariesfile ./.binaries`, where `.binaries` is a" , "file that has been darcs added to your repository). As with the boring" , "file, you can also set up a `~/.darcs/binaries` file if you like."]) , ("defaultrepo", unlines [ "Contains the URL of the default remote repository used by commands `pull`," , "`push`, `send` and `optimize relink`. Darcs edits this file automatically" , "or when the flag `--set-default` is used."]) , ("tmpdir", unlines [ "By default temporary directories are created in `/tmp`, or if that doesn't" , "exist, in `_darcs` (within the current repo). This can be overridden by" , "specifying some other directory in the file `_darcs/prefs/tmpdir` or the" , "environment variable `$DARCS_TMPDIR` or `$TMPDIR`."]) , ("prefs", unlines [ "Contains the preferences set by the command `darcs setprefs`." , "Do not edit manually."]) ] darcs-2.14.5/src/Darcs/Repository/Rebase.hs0000644000000000000000000002216707346545000016637 0ustar0000000000000000-- Copyright (C) 2009-2012 Ganesh Sittampalam -- -- BSD3 module Darcs.Repository.Rebase ( RebaseJobFlags(..) , withManualRebaseUpdate , rebaseJob , startRebaseJob , maybeDisplaySuspendedStatus ) where import Prelude () import Darcs.Prelude import Darcs.Util.Global ( darcsdir ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.CommuteFn ( commuterIdRL ) import Darcs.Patch.Commute ( selfCommuter ) import Darcs.Patch.Named.Wrapped ( WrappedNamed(..), mkRebase ) import Darcs.Patch.PatchInfoAnd ( n2pia, hopefully ) import Darcs.Patch.Rebase ( takeHeadRebase , takeAnyRebase , takeAnyRebaseAndTrailingPatches ) import Darcs.Patch.Rebase.Container ( Suspended(..), countToEdit, simplifyPushes ) import Darcs.Patch.Rebase.Fixup ( RebaseFixup(..) ) import Darcs.Patch.RepoPatch ( RepoPatch ) import Darcs.Patch.RepoType ( RepoType(..), IsRepoType(..), SRepoType(..) , RebaseType(..), SRebaseType(..) ) import Darcs.Patch.Set ( PatchSet(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (:>)(..), RL(..), reverseRL ) import Darcs.Patch.Witnesses.Sealed ( Sealed2(..), FlippedSeal(..) ) import Darcs.Repository.Flags ( Compression , UpdateWorking(..) , Verbosity ) import Darcs.Repository.Format ( RepoProperty ( RebaseInProgress ) , formatHas , addToFormat , removeFromFormat , writeRepoFormat ) import Darcs.Repository.Hashed ( tentativelyAddPatch , tentativelyAddPatch_ , tentativelyAddPatches_ , tentativelyRemovePatches , tentativelyRemovePatches_ , finalizeRepositoryChanges , revertRepositoryChanges , readTentativeRepo , readRepo , UpdatePristine(..) ) import Darcs.Repository.InternalTypes ( Repository, repoFormat, repoLocation ) import qualified Darcs.Util.Diff as D ( DiffAlgorithm(MyersDiff) ) import Darcs.Util.Printer ( ePutDocLn, text ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Tree ( Tree ) import Control.Exception ( finally ) import System.FilePath.Posix ( () ) -- | Some common flags that are needed to run rebase jobs. -- Normally flags are captured directly by the implementation of the specific -- job's function, but the rebase infrastructure needs to do work on the repository -- directly that sometimes needs these options, so they have to be passed -- as part of the job definition. data RebaseJobFlags = RebaseJobFlags { rjoCompression :: Compression , rjoVerbosity :: Verbosity , rjoUpdateWorking :: UpdateWorking } withManualRebaseUpdate :: forall rt p x wR wU wT1 wT2 . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => RebaseJobFlags -> Repository rt p wR wU wT1 -> (Repository rt p wR wU wT1 -> IO (Repository rt p wR wU wT2, FL (RebaseFixup p) wT2 wT1, x)) -> IO (Repository rt p wR wU wT2, x) withManualRebaseUpdate (RebaseJobFlags compr verb uw) r subFunc | SRepoType SIsRebase <- singletonRepoType :: SRepoType rt = do patches <- readTentativeRepo r (repoLocation r) let go :: PatchSet rt p wS wT1 -> IO (Repository rt p wR wU wT2, x) go (PatchSet _ NilRL) = bug "trying to recontext rebase without rebase patch at head (tag)" go (PatchSet _ (_ :<: q)) = case hopefully q of NormalP {} -> bug "trying to recontext rebase without a rebase patch at head (not match)" RebaseP _ s -> do r' <- tentativelyRemovePatches r compr uw (q :>: NilFL) (r'', fixups, x) <- subFunc r' q' <- n2pia <$> mkRebase (simplifyPushes D.MyersDiff fixups s) r''' <- tentativelyAddPatch r'' compr verb uw q' return (r''', x) go patches withManualRebaseUpdate _flags r subFunc = do (r', _, x) <- subFunc r return (r', x) -- got a rebase operation to run where it is required that a rebase is already in progress rebaseJob :: (RepoPatch p, ApplyState p ~ Tree) => (Repository ('RepoType 'IsRebase) p wR wU wR -> IO a) -> Repository ('RepoType 'IsRebase) p wR wU wR -> RebaseJobFlags -> IO a rebaseJob job repo flags = do repo' <- moveRebaseToEnd repo flags job repo' -- the use of finally here is because various things in job -- might cause an "expected" early exit leaving us needing -- to remove the rebase-in-progress state (e.g. when suspending, -- conflicts with recorded, user didn't specify any patches). -- It's a bit questionable/non-standard as it's doing quite a bit -- of cleanup and if there was an unexpected error then this -- may may things worse. -- The better fix would be to standardise expected early exits -- e.g. using a layer on top of IO or a common Exception type -- and then just catch those. `finally` checkSuspendedStatus repo' flags -- got a rebase operation to run where we may need to initialise the rebase state first startRebaseJob :: (RepoPatch p, ApplyState p ~ Tree) => (Repository ('RepoType 'IsRebase) p wR wU wR -> IO a) -> Repository ('RepoType 'IsRebase) p wR wU wR -> RebaseJobFlags -> IO a startRebaseJob job repo flags = do repo' <- startRebaseIfNecessary repo flags rebaseJob job repo' flags checkSuspendedStatus :: (RepoPatch p, ApplyState p ~ Tree) => Repository ('RepoType 'IsRebase) p wR wU wR -> RebaseJobFlags -> IO () checkSuspendedStatus repo flags@(RebaseJobFlags compr _verb uw) = do (_, Sealed2 ps) <- takeAnyRebase <$> readRepo repo case countToEdit ps of 0 -> do debugMessage "Removing the rebase patch file..." -- this shouldn't actually be necessary since the count should -- only go to zero after an actual rebase operation which would -- leave the patch at the end anyway, but be defensive. repo' <- moveRebaseToEnd repo flags revertRepositoryChanges repo' uw -- in theory moveRebaseToEnd could just return the commuted one, -- but since the repository has been committed and re-opened -- best to just do things carefully (rebase, _, _) <- takeHeadRebase <$> readRepo repo' repo'' <- tentativelyRemovePatches repo' compr uw (rebase :>: NilFL) finalizeRepositoryChanges repo'' uw compr writeRepoFormat (removeFromFormat RebaseInProgress (repoFormat repo)) (darcsdir "format") putStrLn "Rebase finished!" n -> ePutDocLn $ text $ "Rebase in progress: " ++ show n ++ " suspended patches" moveRebaseToEnd :: (RepoPatch p, ApplyState p ~ Tree) => Repository ('RepoType 'IsRebase) p wR wU wR -> RebaseJobFlags -> IO (Repository ('RepoType 'IsRebase) p wR wU wR) moveRebaseToEnd repo (RebaseJobFlags compr verb uw) = do allpatches <- readRepo repo case takeAnyRebaseAndTrailingPatches allpatches of FlippedSeal (_ :> NilRL) -> return repo -- already at head FlippedSeal (r :> ps) -> do Just (ps' :> r') <- return $ commuterIdRL selfCommuter (r :> ps) debugMessage "Moving rebase patch to head..." revertRepositoryChanges repo uw repo' <- tentativelyRemovePatches_ DontUpdatePristine repo compr uw (reverseRL ps) repo'' <- tentativelyRemovePatches_ DontUpdatePristine repo' compr uw (r :>: NilFL) repo''' <- tentativelyAddPatches_ DontUpdatePristine repo'' compr verb uw (reverseRL ps') repo'''' <- tentativelyAddPatch_ DontUpdatePristine repo''' compr verb uw r' finalizeRepositoryChanges repo'''' uw compr return repo'''' displaySuspendedStatus :: RepoPatch p => Repository ('RepoType 'IsRebase) p wR wU wR -> IO () displaySuspendedStatus repo = do (_, Sealed2 ps) <- takeAnyRebase <$> readRepo repo ePutDocLn $ text $ "Rebase in progress: " ++ show (countToEdit ps) ++ " suspended patches" maybeDisplaySuspendedStatus :: RepoPatch p => SRebaseType rebaseType -> Repository ('RepoType rebaseType) p wR wU wR -> IO () maybeDisplaySuspendedStatus SIsRebase repo = displaySuspendedStatus repo maybeDisplaySuspendedStatus SNoRebase _ = return () startRebaseIfNecessary :: (RepoPatch p, ApplyState p ~ Tree) => Repository ('RepoType 'IsRebase) p wR wU wT -> RebaseJobFlags -> IO (Repository ('RepoType 'IsRebase) p wR wU wT) startRebaseIfNecessary repo (RebaseJobFlags compr verb uw) = let rf = repoFormat repo in if formatHas RebaseInProgress rf then return repo else do -- TODO this isn't under the repo lock, and it should be writeRepoFormat (addToFormat RebaseInProgress rf) (darcsdir "format") debugMessage "Writing the rebase patch file..." revertRepositoryChanges repo uw mypatch <- mkRebase (Items NilFL) repo' <- tentativelyAddPatch_ UpdatePristine repo compr verb uw $ n2pia mypatch finalizeRepositoryChanges repo' uw compr return repo' darcs-2.14.5/src/Darcs/Repository/Repair.hs0000644000000000000000000002371307346545000016656 0ustar0000000000000000module Darcs.Repository.Repair ( replayRepository, checkIndex, replayRepositoryInTemp, RepositoryConsistency(..) ) where import Prelude () import Darcs.Prelude import Control.Monad ( when, unless ) import Control.Monad.Trans ( liftIO ) import Control.Exception ( catch, finally, IOException ) import Data.Maybe ( catMaybes ) import Data.List ( sort, (\\) ) import System.Directory ( createDirectoryIfMissing, getCurrentDirectory, setCurrentDirectory ) import System.FilePath ( () ) import Darcs.Util.Path( anchorPath, AbsolutePath, ioAbsolute, toFilePath ) import Darcs.Patch.PatchInfoAnd ( hopefully, PatchInfoAnd, info, winfo, WPatchInfo, unWPatchInfo, compareWPatchInfo ) import Darcs.Patch.Witnesses.Eq ( EqCheck(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), lengthFL, reverseFL, mapRL, nullFL, (:||:)(..) ) import Darcs.Patch.Witnesses.Sealed ( Sealed2(..), Sealed(..), unFreeLeft ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Repair ( Repair(applyAndTryToFix) ) import Darcs.Patch.Info ( displayPatchInfo ) import Darcs.Patch.Set ( Origin, PatchSet(..), patchSet2FL, patchSet2RL ) import Darcs.Patch ( RepoPatch, IsRepoType, PrimOf, isInconsistent ) import Darcs.Repository.Flags ( Verbosity(..), Compression, DiffAlgorithm ) import Darcs.Repository.Format ( identifyRepoFormat, RepoProperty ( HashedInventory ), formatHas ) import Darcs.Repository.Cache ( HashedDir( HashedPristineDir ) ) import Darcs.Repository.HashedIO ( cleanHashdir ) import Darcs.Repository.Hashed ( readHashedPristineRoot, writeAndReadPatch ) import Darcs.Repository.InternalTypes ( Repository, repoCache, repoLocation ) import Darcs.Repository.Prefs ( filetypeFunction ) import Darcs.Repository.Hashed ( readRepo ) import Darcs.Repository.State ( readRecorded , readIndex , readRecordedAndPending ) import Darcs.Repository.Diff( treeDiff ) import Darcs.Util.Progress ( debugMessage, beginTedious, endTedious, tediousSize, finishedOneIO ) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Exception ( catchall ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Lock( rmRecursive, withTempDir ) import Darcs.Util.Printer ( Doc, putDocLn, text ) import Darcs.Util.Printer.Color ( showDoc ) import Darcs.Util.Hash( Hash(NoHash), encodeBase16 ) import Darcs.Util.Tree( Tree, emptyTree, list, restrict, expand, itemHash, zipTrees ) import Darcs.Util.Tree.Monad( TreeIO ) import Darcs.Util.Tree.Hashed( darcsUpdateHashes, hashedTreeIO ) import Darcs.Util.Tree.Plain( readPlainTree ) import Darcs.Util.Index( updateIndex ) import qualified Data.ByteString.Char8 as BC replaceInFL :: FL (PatchInfoAnd rt a) wX wY -> [Sealed2 (WPatchInfo :||: PatchInfoAnd rt a)] -> FL (PatchInfoAnd rt a) wX wY replaceInFL orig [] = orig replaceInFL NilFL _ = impossible replaceInFL (o:>:orig) ch@(Sealed2 (o':||:c):ch_rest) | IsEq <- winfo o `compareWPatchInfo` o' = c:>:replaceInFL orig ch_rest | otherwise = o:>:replaceInFL orig ch applyAndFix :: forall rt p wR wU wT. (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> Compression -> FL (PatchInfoAnd rt p) Origin wR -> TreeIO (FL (PatchInfoAnd rt p) Origin wR, Bool) applyAndFix _ _ NilFL = return (NilFL, True) applyAndFix r compr psin = do liftIO $ beginTedious k liftIO $ tediousSize k $ lengthFL psin (repaired, ok) <- aaf psin liftIO $ endTedious k orig <- liftIO $ patchSet2FL `fmap` readRepo r return (replaceInFL orig repaired, ok) where k = "Replaying patch" aaf :: FL (PatchInfoAnd rt p) wW wZ -> TreeIO ([Sealed2 (WPatchInfo :||: PatchInfoAnd rt p)], Bool) aaf NilFL = return ([], True) aaf (p:>:ps) = do mp' <- applyAndTryToFix p case isInconsistent . hopefully $ p of Just err -> liftIO $ putDocLn err Nothing -> return () let !winfp = winfo p -- assure that 'p' can be garbage collected. liftIO $ finishedOneIO k $ showDoc $ displayPatchInfo $ unWPatchInfo winfp (ps', restok) <- aaf ps case mp' of Nothing -> return (ps', restok) Just (e,pp) -> liftIO $ do putStrLn e p' <- withCurrentDirectory (repoLocation r) $ writeAndReadPatch (repoCache r) compr pp return (Sealed2 (winfp :||: p'):ps', False) data RepositoryConsistency rt p wX = RepositoryConsistent | BrokenPristine (Tree IO) | BrokenPatches (Tree IO) (PatchSet rt p Origin wX) checkUniqueness :: (IsRepoType rt, RepoPatch p) => (Doc -> IO ()) -> (Doc -> IO ()) -> Repository rt p wR wU wT -> IO () checkUniqueness putVerbose putInfo repository = do putVerbose $ text "Checking that patch names are unique..." r <- readRepo repository case hasDuplicate $ mapRL info $ patchSet2RL r of Nothing -> return () Just pinf -> do putInfo $ text "Error! Duplicate patch name:" putInfo $ displayPatchInfo pinf fail "Duplicate patches found." hasDuplicate :: Ord a => [a] -> Maybe a hasDuplicate li = hd $ sort li where hd [_] = Nothing hd [] = Nothing hd (x1:x2:xs) | x1 == x2 = Just x1 | otherwise = hd (x2:xs) replayRepository' :: forall rt p wR wU wT . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => DiffAlgorithm -> AbsolutePath -> Repository rt p wR wU wT -> Compression -> Verbosity -> IO (RepositoryConsistency rt p wR) replayRepository' dflag whereToReplay' repo compr verbosity = do let whereToReplay = toFilePath whereToReplay' putVerbose s = when (verbosity == Verbose) $ putDocLn s putInfo s = unless (verbosity == Quiet) $ putDocLn s checkUniqueness putVerbose putInfo repo createDirectoryIfMissing False whereToReplay putVerbose $ text "Reading recorded state..." pris <- readRecorded repo `catch` \(_ :: IOException) -> return emptyTree putVerbose $ text "Applying patches..." patches <- readRepo repo debugMessage "Fixing any broken patches..." let psin = patchSet2FL patches repair = applyAndFix repo compr psin ((ps, patches_ok), newpris) <- hashedTreeIO repair emptyTree whereToReplay debugMessage "Done fixing broken patches..." let newpatches = PatchSet NilRL (reverseFL ps) debugMessage "Checking pristine against slurpy" ftf <- filetypeFunction is_same <- do Sealed diff <- unFreeLeft `fmap` treeDiff dflag ftf pris newpris :: IO (Sealed (FL (PrimOf p) wR)) return $ nullFL diff `catchall` return False -- TODO is the latter condition needed? Does a broken patch imply pristine -- difference? Why, or why not? return (if is_same && patches_ok then RepositoryConsistent else if patches_ok then BrokenPristine newpris else BrokenPatches newpris newpatches) cleanupRepositoryReplay :: Repository rt p wR wU wT -> IO () cleanupRepositoryReplay r = do let c = repoCache r rf <- identifyRepoFormat "." unless (formatHas HashedInventory rf) $ rmRecursive $ darcsdir ++ "/pristine.hashed" when (formatHas HashedInventory rf) $ do current <- readHashedPristineRoot r cleanHashdir c HashedPristineDir $ catMaybes [current] replayRepositoryInTemp :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => DiffAlgorithm -> Repository rt p wR wU wT -> Compression -> Verbosity -> IO (RepositoryConsistency rt p wR) replayRepositoryInTemp dflag r compr verb = do repodir <- getCurrentDirectory withTempDir "darcs-check" $ \tmpDir -> do setCurrentDirectory repodir replayRepository' dflag tmpDir r compr verb replayRepository :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => DiffAlgorithm -> Repository rt p wR wU wT -> Compression -> Verbosity -> (RepositoryConsistency rt p wR -> IO a) -> IO a replayRepository dflag r compr verb f = run `finally` cleanupRepositoryReplay r where run = do createDirectoryIfMissing False $ darcsdir "pristine.hashed" hashedPristine <- ioAbsolute $ darcsdir "pristine.hashed" st <- replayRepository' dflag hashedPristine r compr verb f st checkIndex :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> Bool -> IO Bool checkIndex repo quiet = do index <- updateIndex =<< readIndex repo pristine <- expand =<< readRecordedAndPending repo working <- expand =<< restrict pristine <$> readPlainTree "." working_hashed <- darcsUpdateHashes working let index_paths = [ p | (p, _) <- list index ] working_paths = [ p | (p, _) <- list working ] index_extra = index_paths \\ working_paths working_extra = working_paths \\ index_paths gethashes p (Just i1) (Just i2) = (p, itemHash i1, itemHash i2) gethashes p (Just i1) Nothing = (p, itemHash i1, NoHash) gethashes p Nothing (Just i2) = (p, NoHash, itemHash i2) gethashes p Nothing Nothing = error $ "Bad case at " ++ show p mismatches = [ miss | miss@(_, h1, h2) <- zipTrees gethashes index working_hashed, h1 /= h2 ] format paths = unlines $ map ((" " ++) . anchorPath "") paths mismatches_disp = unlines [ anchorPath "" p ++ "\n index: " ++ BC.unpack (encodeBase16 h1) ++ "\n working: " ++ BC.unpack (encodeBase16 h2) | (p, h1, h2) <- mismatches ] unless (quiet || null index_extra) $ putStrLn $ "Extra items in index!\n" ++ format index_extra unless (quiet || null working_extra) $ putStrLn $ "Missing items in index!\n" ++ format working_extra unless (quiet || null mismatches) $ putStrLn $ "Hash mismatch(es)!\n" ++ mismatches_disp return $ null index_extra && null working_extra && null mismatches darcs-2.14.5/src/Darcs/Repository/Resolution.hs0000644000000000000000000001640307346545000017575 0ustar0000000000000000-- Copyright (C) 2003,2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Repository.Resolution ( standardResolution , externalResolution , patchsetConflictResolutions ) where import Prelude () import Darcs.Prelude import System.FilePath.Posix ( () ) import System.Exit ( ExitCode( ExitSuccess ) ) import System.Directory ( setCurrentDirectory, getCurrentDirectory ) import Data.List ( zip4 ) import Control.Monad ( when ) import Darcs.Repository.Diff( treeDiff ) import Darcs.Patch ( PrimOf, PrimPatch, RepoPatch, resolveConflicts, effectOnFilePaths, invert, listConflictedFiles, commute, applyToTree, fromPrim ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Conflict ( Conflict, CommuteNoConflicts ) import Darcs.Patch.Named.Wrapped ( activecontents ) import Darcs.Patch.Prim ( PrimPatchBase ) import Darcs.Util.Path ( toFilePath, filterFilePaths ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), (:>)(..), (+>+), mapFL_FL, concatFL, reverseRL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), unFreeLeft ) import Darcs.Util.CommandLine ( parseCmd ) import Darcs.Patch.PatchInfoAnd ( hopefully ) import Darcs.Util.Prompt ( askEnter ) import Darcs.Patch.Set ( PatchSet(..), Origin ) import Darcs.Repository.Prefs ( filetypeFunction ) import Darcs.Util.Exec ( exec, Redirect(..) ) import Darcs.Util.Lock ( withTempDir ) import Darcs.Util.External ( cloneTree ) import Darcs.Repository.Flags ( WantGuiPause(..), DiffAlgorithm(..) ) import qualified Darcs.Util.Tree as Tree import Darcs.Util.Tree.Plain ( writePlainTree, readPlainTree ) --import Darcs.Util.Printer.Color ( traceDoc ) --import Darcs.Util.Printer ( greenText, ($$), Doc ) --import Darcs.Patch ( showPatch ) standardResolution :: (PrimPatchBase p, Conflict p, CommuteNoConflicts p) => FL p wX wY -> Sealed (FL (PrimOf p) wY) standardResolution = mergeList . map head . resolveConflicts mergeList :: forall prim wX . PrimPatch prim => [Sealed (FL prim wX)] -> Sealed (FL prim wX) mergeList = doml NilFL where doml :: FL prim wX wY -> [Sealed (FL prim wX)] -> Sealed (FL prim wX) doml mp (Sealed p:ps) = case commute (invert p :> mp) of Just (mp' :> _) -> doml (p +>+ mp') ps Nothing -> doml mp ps -- This shouldn't happen for "good" resolutions. doml mp [] = Sealed mp externalResolution :: forall p wX wY wZ wA. (RepoPatch p, ApplyState p ~ Tree.Tree) => DiffAlgorithm -> Tree.Tree IO -> String -- ^ external merge tool command -> WantGuiPause -- ^ tell whether we want GUI pause -> FL (PrimOf p) wX wY -> FL (PrimOf p) wX wZ -> FL p wY wA -> IO (Sealed (FL (PrimOf p) wA)) externalResolution diffa s1 c wantGuiPause p1_prim p2_prim pmerged = do -- TODO: remove the following two once we can rely on GHC 7.2 / superclass equality let p1 :: FL p wX wY = mapFL_FL fromPrim p1_prim p2 :: FL p wX wZ = mapFL_FL fromPrim p2_prim sa <- applyToTree (invert p1) s1 sm <- applyToTree pmerged s1 s2 <- applyToTree p2 sa let nms = listConflictedFiles pmerged nas = effectOnFilePaths (invert pmerged) nms n1s = effectOnFilePaths p1 nas n2s = effectOnFilePaths p2 nas ns = zip4 nas n1s n2s nms write_files tree fs = writePlainTree (Tree.filter (filterFilePaths fs) tree) "." in do former_dir <- getCurrentDirectory withTempDir "version1" $ \absd1 -> do let d1 = toFilePath absd1 write_files s1 n1s setCurrentDirectory former_dir withTempDir "ancestor" $ \absda -> do let da = toFilePath absda write_files sa nas setCurrentDirectory former_dir withTempDir "merged" $ \absdm -> do let dm = toFilePath absdm write_files sm nms setCurrentDirectory former_dir withTempDir "cleanmerged" $ \absdc -> do let dc = toFilePath absdc cloneTree dm "." setCurrentDirectory former_dir withTempDir "version2" $ \absd2 -> do let d2 = toFilePath absd2 write_files s2 n2s mapM_ (externallyResolveFile c wantGuiPause da d1 d2 dm) ns sc <- readPlainTree dc sfixed <- readPlainTree dm ftf <- filetypeFunction unFreeLeft `fmap` treeDiff diffa ftf sc sfixed externallyResolveFile :: String -- ^ external merge tool command -> WantGuiPause -- ^ tell whether we want GUI pause -> String -- ^ path to merge base -> String -- ^ path to side 1 of the merge -> String -- ^ path to side 2 of the merge -> String -- ^ path where resolved content should go -> (FilePath, FilePath, FilePath, FilePath) -> IO () externallyResolveFile c wantGuiPause da d1 d2 dm (fa, f1, f2, fm) = do putStrLn $ "Merging file "++fm++" by hand." ec <- run c [('1', d1f1), ('2', d2f2), ('a', dafa), ('o', dmfm), ('%', "%")] when (ec /= ExitSuccess) $ putStrLn $ "External merge command exited with " ++ show ec when (wantGuiPause == YesWantGuiPause) $ askEnter "Hit return to move on, ^C to abort the whole operation..." run :: String -> [(Char,String)] -> IO ExitCode run c replacements = case parseCmd replacements c of Left err -> fail $ show err Right (c2,_) -> rr c2 where rr (command:args) = do putStrLn $ "Running command '" ++ unwords (command:args) ++ "'" exec command args (Null,Null,Null) rr [] = return ExitSuccess patchsetConflictResolutions :: RepoPatch p => PatchSet rt p Origin wX -> Sealed (FL (PrimOf p) wX) patchsetConflictResolutions (PatchSet _ NilRL) = Sealed NilFL patchsetConflictResolutions (PatchSet _ xs) = --traceDoc (greenText "looking at resolutions" $$ -- (sh $ resolveConflicts $ joinPatches $ -- mapFL_FL (patchcontents . hopefully) $ reverseRL xs )) $ standardResolution $ concatFL $ mapFL_FL (activecontents . hopefully) $ reverseRL xs --where sh :: [[Sealed (FL Prim)]] -> Doc -- sh [] = greenText "no more conflicts" -- sh (x:ps) = greenText "one conflict" $$ sh1 x $$ sh ps -- sh1 :: [Sealed (FL Prim)] -> Doc -- sh1 [] = greenText "end of unravellings" -- sh1 (Sealed x:ps) = greenText "one unravelling:" $$ showPatch x $$ -- sh1 ps darcs-2.14.5/src/Darcs/Repository/State.hs0000644000000000000000000007605107346545000016517 0ustar0000000000000000{-# LANGUAGE CPP #-} -- Copyright (C) 2009 Petr Rockai -- (C) 2012 José Neder -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. module Darcs.Repository.State ( restrictSubpaths, restrictBoring, TreeFilter(..), restrictDarcsdir , maybeRestrictSubpaths -- * Diffs , unrecordedChanges, readPending -- * Trees , readRecorded, readUnrecorded, readRecordedAndPending, readWorking , readPendingAndWorking, readUnrecordedFiltered -- * Index , readIndex, updateIndex, invalidateIndex, UseIndex(..), ScanKnown(..) -- * Utilities , filterOutConflicts -- * Pending-related functions that depend on repo state , addPendingDiffToPending, addToPending ) where import Prelude () import Darcs.Prelude import Control.Monad ( when, foldM, forM ) import Control.Monad.State ( StateT, runStateT, get, put, liftIO ) import Control.Exception ( catch, IOException ) import Data.Maybe ( fromJust, isJust ) import Data.Ord ( comparing ) import Data.List ( sortBy, union, delete ) import Text.Regex( matchRegex ) import System.Directory( removeFile, doesFileExist, doesDirectoryExist, renameFile ) import System.FilePath ( () #if mingw32_HOST_OS , (<.>) #endif ) import qualified Data.ByteString as B ( ByteString, readFile, drop, writeFile, empty, concat ) import qualified Data.ByteString.Char8 as BC ( pack, unpack, split ) import qualified Data.ByteString.Lazy as BL ( toChunks ) import Darcs.Patch ( RepoPatch, PrimOf, sortCoalesceFL, fromPrims , PrimPatch, maybeApplyToTree , tokreplace, forceTokReplace, move ) import Darcs.Patch.Named.Wrapped ( anonymous ) import Darcs.Patch.Apply ( ApplyState, applyToTree, effectOnFilePaths ) import Darcs.Patch.Witnesses.Ordered ( RL(..), FL(..), (+>+) , (:>)(..), reverseRL, reverseFL , mapFL, concatFL, toFL, nullFL ) import Darcs.Patch.Witnesses.Eq ( EqCheck(IsEq, NotEq) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP, unsafeCoercePEnd ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), seal, unFreeLeft, mapSeal , freeGap, emptyGap, joinGap, FreeLeft, Gap(..) ) import Darcs.Patch.Commute ( selfCommuter, commuteFL ) import Darcs.Patch.CommuteFn ( commuterIdRL ) import Darcs.Patch.Permutations ( partitionConflictingFL, genCommuteWhatWeCanRL ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, n2pia ) import Darcs.Patch.FileHunk ( FileHunk(..), IsHunk(..) ) import Darcs.Patch.TokenReplace ( breakToTokens, defaultToks ) import Darcs.Repository.Flags ( UseIndex(..), ScanKnown(..), DiffAlgorithm(..) , UpdateWorking(..), LookForMoves(..), LookForReplaces(..) ) import Darcs.Util.Global ( darcsdir ) import Darcs.Repository.InternalTypes ( Repository, repoFormat ) import Darcs.Repository.Format(formatHas, RepoProperty(NoWorkingDir)) import qualified Darcs.Repository.Pending as Pending import Darcs.Repository.Prefs ( filetypeFunction, boringRegexps ) import Darcs.Repository.Diff ( treeDiff ) import Darcs.Util.Path ( AnchoredPath(..), anchorPath, floatPath, fn2fp , SubPath, sp2fn, filterPaths, FileName , parents, replacePrefixPath, anchoredRoot , toFilePath, simpleSubPath, normPath, floatSubPath, makeName ) import Darcs.Util.Hash( Hash( NoHash ) ) import Darcs.Util.Tree( Tree, restrict, FilterTree, expand, emptyTree, overlay, find , ItemType(..), itemType, readBlob, modifyTree, findFile, TreeItem(..) , makeBlobBS, expandPath ) import Darcs.Util.Tree.Plain( readPlainTree ) import Darcs.Util.Tree.Hashed( darcsTreeHash, readDarcsHashed, decodeDarcsHash, decodeDarcsSize ) import qualified Darcs.Util.Index as I import qualified Darcs.Util.Tree as Tree import Darcs.Util.Index ( listFileIDs, getFileID ) newtype TreeFilter m = TreeFilter { applyTreeFilter :: forall tr . FilterTree tr m => tr m -> tr m } -- | From a repository and a list of SubPath's, construct a filter that can be -- used on a Tree (recorded or unrecorded state) of this repository. This -- constructed filter will take pending into account, so the subpaths will be -- translated correctly relative to pending move patches. restrictSubpaths :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> [SubPath] -> IO (TreeFilter m) restrictSubpaths repo subpaths = do Sealed pending <- Pending.readPending repo restrictSubpathsAfter pending repo subpaths -- | Like 'restrictSubpaths' but with the pending patch passed as a parameter. -- The 'Repository' parameter is not used, we need it only to avoid -- abiguous typing of @p@. restrictSubpathsAfter :: (RepoPatch p, ApplyState p ~ Tree) => FL (PrimOf p) wT wP -> Repository rt p wR wU wT -> [SubPath] -> IO (TreeFilter m) restrictSubpathsAfter pending _repo subpaths = do let paths = map (fn2fp . sp2fn) subpaths paths' = paths `union` effectOnFilePaths pending paths anchored = map floatPath paths' restrictPaths :: FilterTree tree m => tree m -> tree m restrictPaths = Tree.filter (filterPaths anchored) return (TreeFilter restrictPaths) maybeRestrictSubpaths :: (RepoPatch p, ApplyState p ~ Tree) => FL (PrimOf p) wT wP -> Repository rt p wR wU wT -> Maybe [SubPath] -> IO (TreeFilter m) maybeRestrictSubpaths pending repo = maybe (return $ TreeFilter id) (restrictSubpathsAfter pending repo) -- |Is the given path in (or equal to) the _darcs metadata directory? inDarcsDir :: AnchoredPath -> Bool inDarcsDir (AnchoredPath (x:_)) | x == makeName darcsdir = True inDarcsDir _ = False -- | Construct a 'TreeFilter' that removes any boring files that are not also -- contained in the argument 'Tree'. -- -- The standard use case is for the argument to be the recorded state, possibly -- with further patches applied, so as not to discard any files already known -- to darcs. The result is usually applied to the full working state. restrictBoring :: Tree m -> IO (TreeFilter m) restrictBoring guide = do boring <- boringRegexps let boring' p | inDarcsDir p = False boring' p = not $ any (\rx -> isJust $ matchRegex rx p') boring where p' = anchorPath "" p restrictTree :: FilterTree t m => t m -> t m restrictTree = Tree.filter $ \p _ -> case find guide p of Nothing -> boring' p _ -> True return (TreeFilter restrictTree) -- | Construct a Tree filter that removes any darcs metadata files the -- Tree might have contained. restrictDarcsdir :: TreeFilter m restrictDarcsdir = TreeFilter $ Tree.filter $ \p _ -> not (inDarcsDir p) {- | For a repository and an optional list of paths (when 'Nothing', take everything) compute a (forward) list of prims (i.e. a patch) going from the recorded state of the repository (pristine) to the unrecorded state of the repository (the working copy + pending). When a list of paths is given, at least the files that live under any of these paths in either recorded or unrecorded will be included in the resulting patch. NB. More patches may be included in this list, eg. the full contents of the pending patch. This is usually not a problem, since selectChanges will properly filter the results anyway. This also depends on the options given: --look-for-moves: Detect pending file moves using the index. The resulting patches are added to pending and taken into consideration, when filtering the tree according to the given path list. --look-for-adds: Include files in the working state that do not exist in the recorded + pending state. --include-boring: Include even boring files. --look-for-replaces: Detect pending replace patches. Like detected moves, these are added to the pending patch. Note that, like detected moves, these are mere proposals for the user to consider or reject. --ignore-times: Disables index usage completely -- for each file, we read both the unrecorded and the recorded copy and run a diff on them. This is very inefficient, although in extremely rare cases, the index could go out of sync (file is modified, index is updated and file is modified again within a single second). Note that use of the index is also disabled when we detect moves or replaces, since this implies that the index is out of date. -} unrecordedChanges :: (RepoPatch p, ApplyState p ~ Tree) => (UseIndex, ScanKnown, DiffAlgorithm) -> LookForMoves -> LookForReplaces -> Repository rt p wR wU wT -> Maybe [SubPath] -> IO (FL (PrimOf p) wT wU) unrecordedChanges dopts lfm lfr r paths = do (pending :> working) <- readPendingAndWorking dopts lfm lfr r paths return $ sortCoalesceFL (pending +>+ working) -- Implementation note: it is important to do things in the right order: we -- first have to read the pending patch, then detect moves, then detect adds, -- then detect replaces. readPendingAndWorking :: forall rt p wR wU wT. (RepoPatch p, ApplyState p ~ Tree) => (UseIndex, ScanKnown, DiffAlgorithm) -> LookForMoves -> LookForReplaces -> Repository rt p wR wU wT -> Maybe [SubPath] -> IO ((FL (PrimOf p) :> FL (PrimOf p)) wT wU) readPendingAndWorking _ _ _ r _ | formatHas NoWorkingDir (repoFormat r) = do IsEq <- return $ workDirLessRepoWitness r return (NilFL :> NilFL) readPendingAndWorking (useidx, scan, diffalg) lfm lfr repo mbpaths = do (pending_tree, working_tree, pending) <- readPendingAndMovesAndUnrecorded repo useidx scan lfm mbpaths (pending_tree_with_replaces, Sealed replaces) <- getReplaces lfr diffalg repo pending_tree working_tree ft <- filetypeFunction wrapped_diff <- treeDiff diffalg ft pending_tree_with_replaces working_tree case unFreeLeft wrapped_diff of Sealed diff -> do return (pending +>+ unsafeCoercePEnd replaces :> unsafeCoercePEnd diff) readPendingAndMovesAndUnrecorded :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> UseIndex -> ScanKnown -> LookForMoves -> Maybe [SubPath] -> IO ( Tree IO -- pristine with (pending + moves) , Tree IO -- working , FL (PrimOf p) wT wU -- pending + moves ) readPendingAndMovesAndUnrecorded repo useidx scan lfm mbpaths = do (pending_tree, Sealed pending) <- readPending repo moves <- getMoves lfm repo mbpaths let pending' = pending +>+ moves relevant <- maybeRestrictSubpaths pending' repo mbpaths pending_tree' <- applyTreeFilter relevant <$> applyToTree moves pending_tree let useidx' = if nullFL moves then useidx else IgnoreIndex index <- applyToTree moves =<< I.updateIndex =<< applyTreeFilter relevant <$> readIndex repo working_tree <- filteredWorking useidx' scan relevant index pending_tree' return (pending_tree', working_tree, unsafeCoercePEnd pending') -- | @filteredWorking useidx scan relevant index pending_tree@ reads the -- working tree and filters it according to options and @relevant@ file paths. -- The @pending_tree@ is understood to have @relevant@ already applied and is -- used (only) if @useidx == 'IgnoreIndex'@ and @scan == 'ScanKnown'@ to act as -- a guide for filtering the working tree. -- Note that even if @useidx '==' 'IgnoreIndex'@, the index is still used -- to avoid filtering boring files that darcs knows about (see 'restrictBoring'). filteredWorking :: UseIndex -> ScanKnown -> TreeFilter IO -> Tree IO -> Tree IO -> IO (Tree IO) filteredWorking useidx scan relevant index pending_tree = do applyTreeFilter restrictDarcsdir <$> case scan of ScanKnown -> case useidx of UseIndex -> return index IgnoreIndex -> do guide <- expand pending_tree applyTreeFilter relevant . restrict guide <$> readPlainTree "." ScanAll -> do nonboring <- restrictBoring index plain <- applyTreeFilter relevant . applyTreeFilter nonboring <$> readPlainTree "." return $ case useidx of UseIndex -> plain `overlay` index IgnoreIndex -> plain ScanBoring -> do plain <- applyTreeFilter relevant <$> readPlainTree "." return $ case useidx of UseIndex -> plain `overlay` index IgnoreIndex -> plain -- | Witnesses the fact that in the absence of a working directory, we -- pretend that the working dir updates magically to the tentative state. workDirLessRepoWitness :: Repository rt p wR wU wT -> EqCheck wU wT workDirLessRepoWitness r | formatHas NoWorkingDir (repoFormat r) = unsafeCoerceP IsEq | otherwise = NotEq -- | Obtains a Tree corresponding to the "recorded" state of the repository: -- this is the same as the pristine cache, which is the same as the result of -- applying all the repository's patches to an empty directory. readRecorded :: Repository rt p wR wU wT -> IO (Tree IO) readRecorded _repo = do let h_inventory = darcsdir "hashed_inventory" hashed <- doesFileExist h_inventory if hashed then do inv <- B.readFile h_inventory let linesInv = BC.split '\n' inv case linesInv of [] -> return emptyTree (pris_line:_) -> do let hash = decodeDarcsHash $ B.drop 9 pris_line size = decodeDarcsSize $ B.drop 9 pris_line when (hash == NoHash) $ fail $ "Bad pristine root: " ++ show pris_line readDarcsHashed (darcsdir "pristine.hashed") (size, hash) else do have_pristine <- doesDirectoryExist $ darcsdir "pristine" have_current <- doesDirectoryExist $ darcsdir "current" case (have_pristine, have_current) of (True, _) -> readPlainTree $ darcsdir "pristine" (False, True) -> readPlainTree $ darcsdir "current" (_, _) -> fail "No pristine tree is available!" -- | Obtains a Tree corresponding to the "unrecorded" state of the repository: -- the modified files of the working tree plus the "pending" patch. -- The optional list of paths allows to restrict the query to a subtree. -- -- Limiting the query may be more efficient, since hashes on the uninteresting -- parts of the index do not need to go through an up-to-date check (which -- involves a relatively expensive lstat(2) per file. readUnrecorded :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> Maybe [SubPath] -> IO (Tree IO) readUnrecorded repo mbpaths = do Sealed pending <- Pending.readPending repo relevant <- maybeRestrictSubpaths pending repo mbpaths readIndex repo >>= I.updateIndex . applyTreeFilter relevant -- | A variant of 'readUnrecorded' that takes the UseIndex and ScanKnown -- options into account, similar to 'readPendingAndWorking'. We are only -- interested in the resulting tree, not the patch, so the 'DiffAlgorithm' option -- is irrelevant. readUnrecordedFiltered :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> UseIndex -> ScanKnown -> LookForMoves -> Maybe [SubPath] -> IO (Tree IO) readUnrecordedFiltered repo useidx scan lfm mbpaths = do (_, working_tree, _) <- readPendingAndMovesAndUnrecorded repo useidx scan lfm mbpaths return working_tree -- | Obtains a Tree corresponding to the complete working copy of the -- repository (modified and non-modified files). readWorking :: IO (Tree IO) readWorking = expand =<< (applyTreeFilter restrictDarcsdir <$> readPlainTree ".") -- | Obtains the recorded 'Tree' with the pending patch applied. readRecordedAndPending :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> IO (Tree IO) readRecordedAndPending repo = fst `fmap` readPending repo -- | Obtains the recorded 'Tree' with the pending patch applied, plus -- the pending patch itself. The pending patch should start at the -- recorded state (we even verify that it applies, and degrade to -- renaming pending and starting afresh if it doesn't), but we've set to -- say it starts at the tentative state. -- -- Question (Eric Kow) Is this a bug? Darcs.Repository.Pending.readPending -- says it is readPending :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> IO (Tree IO, Sealed (FL (PrimOf p) wT)) readPending repo = do pristine <- readRecorded repo Sealed pending <- Pending.readPending repo catch ((\t -> (t, seal pending)) <$> applyToTree pending pristine) $ \(err :: IOException) -> do putStrLn $ "Yikes, pending has conflicts! " ++ show err putStrLn "Stashing the buggy pending as _darcs/patches/pending_buggy" renameFile (darcsdir "patches" "pending") (darcsdir "patches" "pending_buggy") return (pristine, seal NilFL) index_file, index_invalid :: FilePath index_file = darcsdir "index" index_invalid = darcsdir "index_invalid" -- | Mark the existing index as invalid. This has to be called whenever the -- listing of pristine changes and will cause darcs to update the index next -- time it tries to read it. (NB. This is about files added and removed from -- pristine: changes to file content in either pristine or working are handled -- transparently by the index reading code.) invalidateIndex :: t -> IO () invalidateIndex _ = B.writeFile index_invalid B.empty readIndex :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> IO I.Index readIndex repo = do (invalid, exists, formatValid) <- checkIndex if not exists || invalid || not formatValid then do pris <- readRecordedAndPending repo idx <- I.updateIndexFrom index_file darcsTreeHash pris when invalid $ removeFile index_invalid return idx else I.readIndex index_file darcsTreeHash updateIndex :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> IO () updateIndex repo = do (invalid, _, _) <- checkIndex pris <- readRecordedAndPending repo _ <- I.updateIndexFrom index_file darcsTreeHash pris when invalid $ removeFile index_invalid checkIndex :: IO (Bool, Bool, Bool) checkIndex = do invalid <- doesFileExist $ index_invalid exists <- doesFileExist index_file formatValid <- if exists then I.indexFormatValid index_file else return True when (exists && not formatValid) $ do -- TODO this conditional logic (rename or delete) is mirrored in -- Darcs.Util.Index.updateIndexFrom and should be refactored #if mingw32_HOST_OS renameFile index_file (index_file <.> "old") #else removeFile index_file #endif return (invalid, exists, formatValid) -- |Remove any patches (+dependencies) from a sequence that -- conflict with the recorded or unrecorded changes in a repo filterOutConflicts :: (RepoPatch p, ApplyState p ~ Tree) => RL (PatchInfoAnd rt p) wX wT -- ^Recorded patches from repository, starting from -- same context as the patches to filter -> Repository rt p wR wU wT -- ^Repository itself, used for grabbing -- unrecorded changes -> FL (PatchInfoAnd rt p) wX wZ -- ^Patches to filter -> IO (Bool, Sealed (FL (PatchInfoAnd rt p) wX)) -- ^True iff any patches were removed, -- possibly filtered patches filterOutConflicts us repository them = do let commuter = commuterIdRL selfCommuter unrec <- fmap n2pia . anonymous . fromPrims =<< unrecordedChanges (UseIndex, ScanKnown, MyersDiff) NoLookForMoves NoLookForReplaces repository Nothing them' :> rest <- return $ partitionConflictingFL commuter them (us :<: unrec) return (check rest, Sealed them') where check :: FL p wA wB -> Bool check NilFL = False check _ = True -- | Automatically detect file moves using the index. -- TODO: This function lies about the witnesses. getMoves :: forall rt p wR wU wT wB prim. (RepoPatch p, ApplyState p ~ Tree, prim ~ PrimOf p) => LookForMoves -> Repository rt p wR wU wT -> Maybe [SubPath] -> IO (FL prim wB wB) getMoves NoLookForMoves _ _ = return NilFL getMoves YesLookForMoves repository files = mkMovesFL <$> getMovedFiles repository files where mkMovesFL [] = NilFL mkMovesFL ((a,b,_):xs) = move (anchorPath "" a) (anchorPath "" b) :>: mkMovesFL xs getMovedFiles :: Repository rt p wR wU wT -> Maybe [SubPath] -> IO [(AnchoredPath, AnchoredPath, ItemType)] getMovedFiles repo fs = do old <- sortBy (comparing snd) <$> (listFileIDs =<< readIndex repo) nonboring <- restrictBoring emptyTree let addIDs = foldM (\xs (p, it)-> do mfid <- getFileID p return $ case mfid of Nothing -> xs Just fid -> ((p, it), fid):xs) [] new <- sortBy (comparing snd) <$> (addIDs . map (\(a,b) -> (a, itemType b)) . Tree.list =<< expand =<< applyTreeFilter nonboring <$> readPlainTree ".") let match (x:xs) (y:ys) | snd x > snd y = match (x:xs) ys | snd x < snd y = match xs (y:ys) | snd (fst x) /= snd (fst y) = match xs ys | otherwise = (fst (fst x), fst (fst y), snd (fst x)):match xs ys match _ _ = [] movedfiles = match old new fmovedfiles = case fs of Nothing -> movedfiles Just subpath -> filter (\(f1, f2, _) -> any (`elem` selfiles) [f1, f2]) movedfiles where selfiles = map (floatPath . toFilePath) subpath return (resolve fmovedfiles) resolve :: [(AnchoredPath, AnchoredPath, ItemType)] -> [(AnchoredPath, AnchoredPath, ItemType)] resolve xs = fixPaths $ sortMoves $ deleteCycles xs where -- Input relation is left-and-right-unique. Makes cycle detection easier. deleteCycles [] = [] deleteCycles whole@( x@(start,_,_):rest) = if hasCycle start whole start then deleteCycles (deleteFrom start whole []) else x:deleteCycles rest where hasCycle current ((a',b',_):rest') first | a' == current = b' == first || hasCycle b' whole first | otherwise = hasCycle current rest' first hasCycle _ [] _ = False deleteFrom a (y@(a',b',_):ys) seen | a == a' = deleteFrom b' (seen++ys) [] | otherwise = deleteFrom a ys (y:seen) deleteFrom _ [] seen = seen sortMoves [] = [] sortMoves whole@(current@(_,dest,_):_) = smallest:sortMoves (delete smallest whole) where smallest = follow dest whole current follow prevDest (y@(s,d,_):ys) currentSmallest -- destination is source of another move | prevDest == s = follow d whole y -- parent of destination is also destination of a move | d `elem` parents prevDest = follow d whole y | otherwise = follow prevDest ys currentSmallest follow _ [] currentSmallest = currentSmallest -- rewrite [d/ -> e/, .., d/f -> e/h] to [d/ -> e/, .., e/f -> e/h] fixPaths [] = [] fixPaths (y@(f1,f2,t):ys) | f1 == f2 = fixPaths ys | TreeType <- t = y:fixPaths (map replacepp ys) | otherwise = y:fixPaths ys where replacepp i@(if1,if2,it) | nfst == anchoredRoot = i | otherwise = (nfst, if2, it) where nfst = replacePrefixPath f1 f2 if1 -- | Search for possible replaces between the recordedAndPending state -- and the unrecorded (or working) state. Return a Sealed FL list of -- replace patches to be applied to the recordedAndPending state. getReplaces :: forall rt p wR wU wT . (RepoPatch p, ApplyState p ~ Tree) => LookForReplaces -> DiffAlgorithm -> Repository rt p wR wU wT -> Tree IO -- ^ pending tree (including possibly detected moves) -> Tree IO -- ^ working tree -> IO (Tree IO, -- new pending tree Sealed (FL (PrimOf p) wU)) getReplaces NoLookForReplaces _ _ pending _ = return (pending, Sealed NilFL) getReplaces YesLookForReplaces diffalg _repo pending working = do ftf <- filetypeFunction Sealed changes <- unFreeLeft <$> treeDiff diffalg ftf pending working let allModifiedTokens = concat $ mapFL modifiedTokens changes replaces = rmInvalidReplaces allModifiedTokens (patches, new_pending) <- flip runStateT pending $ forM replaces $ \(f,a,b) -> doReplace defaultToks (fromJust $ simpleSubPath $ fn2fp $ normPath f) (BC.unpack a) (BC.unpack b) return (new_pending, mapSeal concatFL $ toFL patches) where modifiedTokens :: PrimOf p wX wY -> [(FileName, B.ByteString, B.ByteString)] modifiedTokens p = case isHunk p of Just (FileHunk f _ old new) -> map (\(a,b) -> (f, a, b)) (concatMap checkModified $ filter (\(a,b) -> length a == length b) -- only keep lines with same number of tokens $ zip (map breakToTokens old) (map breakToTokens new)) Nothing -> [] -- from a pair of token lists, create a pair of modified token lists checkModified = filter (\(a,b) -> a/=b) . uncurry zip rmInvalidReplaces [] = [] rmInvalidReplaces ((f,old,new):rs) | any (\(f',a,b) -> f' == f && old == a && b /= new) rs = -- inconsistency detected rmInvalidReplaces $ filter (\(f'',a',_) -> f'' /= f || a' /= old) rs rmInvalidReplaces (r:rs) = r:rmInvalidReplaces (filter (/=r) rs) doReplace toks f old new = do pend <- get mpend' <- liftIO $ maybeApplyToTree replacePatch pend case mpend' of Nothing -> getForceReplace f toks old new Just pend' -> do put pend' return $ joinGap (:>:) (freeGap replacePatch) (emptyGap NilFL) where replacePatch = tokreplace (toFilePath f) toks old new getForceReplace :: (PrimPatch prim, ApplyState prim ~ Tree) => SubPath -> String -> String -> String -> StateT (Tree IO) IO (FreeLeft (FL prim)) getForceReplace f toks old new = do let path = floatSubPath f -- the tree here is the "current" pending state tree <- get -- It would be nice if we could fuse the two traversals here, that is, -- expandPath and findFile. OTOH it is debatable whether adding a new -- effectful version of findFile to Darcs.Util.Tree is justified. expandedTree <- liftIO $ expandPath tree path content <- case findFile expandedTree path of Just blob -> liftIO $ readBlob blob Nothing -> bug $ "getForceReplace: not in tree: " ++ show path let newcontent = forceTokReplace toks (BC.pack new) (BC.pack old) (B.concat $ BL.toChunks content) tree' = modifyTree expandedTree path . Just . File $ makeBlobBS newcontent ftf <- liftIO $ filetypeFunction normaliseNewTokPatch <- liftIO $ treeDiff diffalg ftf expandedTree tree' -- make sure we can apply them to the pending state patches <- return $ joinGap (+>+) normaliseNewTokPatch $ freeGap $ tokreplace (toFilePath f) toks old new :>: NilFL mtree'' <- case unFreeLeft patches of Sealed ps -> liftIO $ maybeApplyToTree ps tree case mtree'' of Nothing -> bug "getForceReplace: unable to apply detected force replaces" Just tree'' -> do put tree'' return patches -- | Add an 'FL' of patches started from the pending state to the pending patch. -- TODO: add witnesses for pending so we can make the types precise: currently -- the passed patch can be applied in any context, not just after pending. addPendingDiffToPending :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> UpdateWorking -> FreeLeft (FL (PrimOf p)) -> IO () addPendingDiffToPending _ NoUpdateWorking _ = return () addPendingDiffToPending repo uw@YesUpdateWorking newP = do (toPend :> _) <- readPendingAndWorking (UseIndex, ScanKnown, MyersDiff) NoLookForMoves NoLookForReplaces repo Nothing invalidateIndex repo case unFreeLeft newP of (Sealed p) -> do recordedState <- readRecorded repo Pending.makeNewPending repo uw (toPend +>+ p) recordedState -- | Add an 'FL' of patches starting from the working state to the pending patch, -- including as much extra context as is necessary (context meaning -- dependencies), by commuting the patches to be added past as much of the -- changes between pending and working as is possible, and including anything -- that doesn't commute, and the patch itself in the new pending patch. addToPending :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> UpdateWorking -> FL (PrimOf p) wU wY -> IO () addToPending _ NoUpdateWorking _ = return () addToPending repo uw@YesUpdateWorking p = do (toPend :> toUnrec) <- readPendingAndWorking (UseIndex, ScanKnown, MyersDiff) NoLookForMoves NoLookForReplaces repo Nothing invalidateIndex repo case genCommuteWhatWeCanRL commuteFL (reverseFL toUnrec :> p) of (toP' :> p' :> _excessUnrec) -> do recordedState <- readRecorded repo Pending.makeNewPending repo uw (toPend +>+ reverseRL toP' +>+ p') recordedState darcs-2.14.5/src/Darcs/Repository/Test.hs0000644000000000000000000001265407346545000016355 0ustar0000000000000000-- Copyright (C) 2002-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Repository.Test ( getTest , runPosthook , runPrehook , testTentative ) where import Prelude () import Darcs.Prelude import System.Exit ( ExitCode(..) ) import System.Process ( system ) import System.IO ( hPutStrLn, stderr ) import Control.Monad ( when ) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Path ( AbsolutePath ) import Darcs.Util.Prompt ( askUser ) import Darcs.Repository.Prefs ( getPrefval ) import Darcs.Repository.Hashed ( withTentative ) import Darcs.Repository.Working ( setScriptsExecutable ) import Darcs.Repository.Flags ( LeaveTestDir(..) , Verbosity(..) , SetScriptsExecutable(..) , RunTest (..) , HookConfig (..) ) import Darcs.Repository.InternalTypes ( Repository, repoLocation ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Lock ( withTempDir , withPermDir ) getTest :: Verbosity -> IO (IO ExitCode) getTest verb = let putInfo s = when (verb /= Quiet) $ putStr s in do testline <- getPrefval "test" return $ case testline of Nothing -> return ExitSuccess Just testcode -> do putInfo "Running test...\n" runTest testcode putInfo runPosthook :: HookConfig -> Verbosity -> AbsolutePath -> IO ExitCode runPosthook (HookConfig mPostHook askPostHook) verb repodir = do ph <- getPosthook mPostHook askPostHook withCurrentDirectory repodir $ runHook verb "Posthook" ph getPosthook :: Maybe String -> Bool -> IO (Maybe String) getPosthook mPostHookCmd askPostHook = case mPostHookCmd of Nothing -> return Nothing Just command -> if askPostHook then do putStr ("\nThe following command is set to execute.\n"++ "Execute the following command now (yes or no)?\n"++ command++"\n") yorn <- askUser "" case yorn of ('y':_) -> return $ Just command _ -> putStrLn "Posthook cancelled..." >> return Nothing else return $ Just command runPrehook :: HookConfig -> Verbosity -> AbsolutePath -> IO ExitCode runPrehook (HookConfig mPreHookCmd askPreHook) verb repodir = do ph <- getPrehook mPreHookCmd askPreHook withCurrentDirectory repodir $ runHook verb "Prehook" ph getPrehook :: Maybe String -> Bool -> IO (Maybe String) getPrehook mPreHookCmd askPreHook= case mPreHookCmd of Nothing -> return Nothing Just command -> if askPreHook then do putStr ("\nThe following command is set to execute.\n"++ "Execute the following command now (yes or no)?\n"++ command++"\n") yorn <- askUser "" case yorn of ('y':_) -> return $ Just command _ -> putStrLn "Prehook cancelled..." >> return Nothing else return $ Just command runHook :: Verbosity -> String -> Maybe String -> IO ExitCode runHook _ _ Nothing = return ExitSuccess runHook verb cname (Just command) = do ec <- system command when (verb /= Quiet) $ if ec == ExitSuccess then putStrLn $ cname++" ran successfully." else hPutStrLn stderr $ cname++" failed!" return ec testTentative :: Repository rt p wR wU wT -> RunTest -> LeaveTestDir -> SetScriptsExecutable -> Verbosity -> IO ExitCode testTentative = testAny withTentative runTest :: String -> (String -> IO ()) -> IO ExitCode runTest testcode putInfo = do ec <- system testcode if ec == ExitSuccess then putInfo "Test ran successfully.\n" else putInfo "Test failed!\n" return ec testAny :: (Repository rt p wR wU wT -> ((AbsolutePath -> IO ExitCode) -> IO ExitCode) -> (AbsolutePath -> IO ExitCode) -> IO ExitCode ) -> Repository rt p wR wU wT -> RunTest -> LeaveTestDir -> SetScriptsExecutable -> Verbosity -> IO ExitCode testAny withD repository doRunTest ltd sse verb = debugMessage "Considering whether to test..." >> if doRunTest == NoRunTest then return ExitSuccess else withCurrentDirectory (repoLocation repository) $ do let putInfo = if verb == Quiet then const (return ()) else putStrLn debugMessage "About to run test if it exists." testline <- getPrefval "test" case testline of Nothing -> return ExitSuccess Just testcode -> withD repository (wd "testing") $ \_ -> do putInfo "Running test...\n" when (sse == YesSetScriptsExecutable) setScriptsExecutable runTest testcode putInfo where wd = if ltd == YesLeaveTestDir then withPermDir else withTempDir darcs-2.14.5/src/Darcs/Repository/Working.hs0000644000000000000000000000533007346545000017047 0ustar0000000000000000module Darcs.Repository.Working ( applyToWorking , setScriptsExecutable , setScriptsExecutablePatches ) where import Control.Monad ( when, unless, filterM ) import System.Directory ( doesFileExist ) import qualified Data.ByteString as B ( readFile , isPrefixOf ) import qualified Data.ByteString.Char8 as BC (pack) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Workaround ( setExecutable ) import Darcs.Util.Tree ( Tree ) import Darcs.Util.Path ( anchorPath ) import qualified Darcs.Util.Tree as Tree import Darcs.Patch ( RepoPatch, apply, listTouchedFiles ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.Prim ( PrimOf ) import Darcs.Patch.Witnesses.Ordered ( FL(..) ) import Darcs.Patch.Dummy ( DummyPatch ) import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Repository.Format ( RepoProperty( NoWorkingDir ), formatHas ) import Darcs.Repository.Flags ( Verbosity(..) ) import Darcs.Repository.InternalTypes ( Repository , repoFormat , repoLocation , coerceU ) import Darcs.Repository.ApplyPatches ( runTolerantly, runSilently ) import Darcs.Repository.State ( readWorking ) applyToWorking :: (ApplyState p ~ Tree, RepoPatch p) => Repository rt p wR wU wT -> Verbosity -> FL (PrimOf p) wU wY -> IO (Repository rt p wR wY wT) applyToWorking repo verb patch = do unless (formatHas NoWorkingDir (repoFormat repo)) $ withCurrentDirectory (repoLocation repo) $ if verb == Quiet then runSilently $ apply patch else runTolerantly $ apply patch return $ coerceU repo -- | Sets scripts in or below the current directory executable. -- A script is any file that starts with the bytes '#!'. -- This is used for --set-scripts-executable. setScriptsExecutable_ :: PatchInspect p => Maybe (p wX wY) -> IO () setScriptsExecutable_ pw = do debugMessage "Making scripts executable" tree <- readWorking paths <- case pw of Just ps -> filterM doesFileExist $ listTouchedFiles ps Nothing -> return [ anchorPath "." p | (p, Tree.File _) <- Tree.list tree ] let setExecutableIfScript f = do contents <- B.readFile f when (BC.pack "#!" `B.isPrefixOf` contents) $ do debugMessage ("Making executable: " ++ f) setExecutable f True mapM_ setExecutableIfScript paths setScriptsExecutable :: IO () setScriptsExecutable = setScriptsExecutable_ (Nothing :: Maybe (FL DummyPatch wX wY)) setScriptsExecutablePatches :: PatchInspect p => p wX wY -> IO () setScriptsExecutablePatches = setScriptsExecutable_ . Just darcs-2.14.5/src/Darcs/UI/0000755000000000000000000000000007346545000013230 5ustar0000000000000000darcs-2.14.5/src/Darcs/UI/ApplyPatches.hs0000644000000000000000000001713207346545000016165 0ustar0000000000000000module Darcs.UI.ApplyPatches ( PatchApplier(..), PatchProxy(..) , StandardPatchApplier(..) ) where import Prelude () import Darcs.Prelude import System.Exit ( ExitCode ( ExitSuccess ), exitSuccess ) import System.IO ( hClose, stdout, stderr ) import Control.Exception ( catch, fromException, SomeException, throwIO ) import Control.Monad ( when, unless ) import qualified Data.ByteString.Char8 as BC import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd ) import Darcs.Util.SignalHandler ( withSignalsBlocked ) import Darcs.UI.Commands ( putVerbose , putInfo , setEnvDarcsPatches ) import Darcs.UI.Commands.Util ( printDryRunMessageAndExit ) import Darcs.UI.CommandsAux ( checkPaths ) import Darcs.UI.Flags ( DarcsFlag, verbosity, compress, reorder, allowConflicts, externalMerge , wantGuiPause, diffingOpts, setScriptsExecutable, isInteractive, testChanges , xmlOutput, reply, getCc, getSendmailCmd, dryRun ) import qualified Darcs.UI.Options.All as O import Darcs.UI.Options ( (?) ) import Darcs.UI.Commands.Util ( testTentativeAndMaybeExit ) import Darcs.Repository.Flags ( UpdateWorking(..) ) import Darcs.Repository ( Repository , tentativelyMergePatches , finalizeRepositoryChanges , applyToWorking , invalidateIndex , setScriptsExecutablePatches ) import Darcs.Repository.Job ( RepoJob(RepoJob) ) import Darcs.Patch ( RepoPatch, RepoType, IsRepoType, description ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Witnesses.Ordered ( FL, mapFL, nullFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed) ) import Darcs.UI.External ( sendEmail ) import Darcs.Util.Lock ( withStdoutTemp, readBinFile ) import Darcs.Util.Printer ( vcat, text ) import Darcs.Util.Tree( Tree ) import GHC.Exts ( Constraint ) data PatchProxy (p :: * -> * -> *) = PatchProxy -- |This class is a hack to abstract over pull/apply and rebase pull/apply. class PatchApplier pa where type ApplierRepoTypeConstraint pa (rt :: RepoType) :: Constraint repoJob :: pa -> [DarcsFlag] -> (forall rt p wR wU . ( IsRepoType rt, ApplierRepoTypeConstraint pa rt , RepoPatch p, ApplyState p ~ Tree ) => (PatchProxy p -> Repository rt p wR wU wR -> IO ())) -> RepoJob () applyPatches :: forall rt p wR wU wT wX wZ . ( ApplierRepoTypeConstraint pa rt, IsRepoType rt , RepoPatch p, ApplyState p ~ Tree ) => pa -> PatchProxy p -> String -> [DarcsFlag] -> String -> Repository rt p wR wU wT -> FL (PatchInfoAnd rt p) wX wT -> FL (PatchInfoAnd rt p) wX wZ -> IO () data StandardPatchApplier = StandardPatchApplier instance PatchApplier StandardPatchApplier where type ApplierRepoTypeConstraint StandardPatchApplier rt = () repoJob StandardPatchApplier _opts f = RepoJob (f PatchProxy) applyPatches StandardPatchApplier PatchProxy = standardApplyPatches standardApplyPatches :: forall rt p wR wU wT wX wZ . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => String -> [DarcsFlag] -> String -> Repository rt p wR wU wT -> FL (PatchInfoAnd rt p) wX wT -> FL (PatchInfoAnd rt p) wX wZ -> IO () standardApplyPatches cmdName opts from_whom repository us' to_be_applied = do printDryRunMessageAndExit cmdName (verbosity ? opts) (O.summary ? opts) (dryRun ? opts) (xmlOutput ? opts) (isInteractive True opts) to_be_applied when (nullFL to_be_applied && reorder ? opts == O.NoReorder) $ do putStrLn $ "You don't want to " ++ cmdName ++ " any patches, so I'm exiting!" exitSuccess checkPaths opts to_be_applied redirectOutput opts from_whom $ do unless (nullFL to_be_applied) $ do putVerbose opts $ text $ "Will " ++ cmdName ++ " the following patches:" putVerbose opts . vcat $ mapFL description to_be_applied setEnvDarcsPatches to_be_applied Sealed pw <- tentativelyMergePatches repository cmdName (allowConflicts opts) YesUpdateWorking (externalMerge ? opts) (wantGuiPause opts) (compress ? opts) (verbosity ? opts) (reorder ? opts) (diffingOpts opts) us' to_be_applied invalidateIndex repository testTentativeAndMaybeExit repository (verbosity ? opts) (testChanges ? opts) (setScriptsExecutable ? opts) (isInteractive True opts) "those patches do not pass the tests." (cmdName ++ " them") Nothing withSignalsBlocked $ do finalizeRepositoryChanges repository YesUpdateWorking (compress ? opts) _ <- applyToWorking repository (verbosity ? opts) pw `catch` \(e :: SomeException) -> fail ("Error applying patch to working dir:\n" ++ show e) when (setScriptsExecutable ? opts == O.YesSetScriptsExecutable) $ setScriptsExecutablePatches pw return () case (nullFL to_be_applied, reorder ? opts == O.Reorder) of (True,True) -> putInfo opts $ text $ "Nothing to " ++ cmdName ++ ", finished reordering." (False,True) -> putInfo opts $ text $ "Finished " ++ cmdName ++ "ing and reordering." _ -> putInfo opts $ text $ "Finished " ++ cmdName ++ "ing." redirectOutput :: [DarcsFlag] -> String -> IO () -> IO () redirectOutput opts to doit = case reply ? opts of Nothing -> doit Just from -> withStdoutTemp $ \tempf -> doitAndCleanup `catch` sendit tempf from where -- TODO: I suggest people writing such code should *at least* put in some comments. -- It is unclear how this works and how the intertwined exception handlers make -- this do what the author wanted. doitAndCleanup = doit >> hClose stdout >> hClose stderr sendit :: FilePath -> String -> SomeException -> IO a sendit tempf from e | Just ExitSuccess <- fromException e = do sendSanitizedEmail opts from to "Patch applied" cc tempf throwIO e sendit tempf from e | Just (_ :: ExitCode) <- fromException e = do sendSanitizedEmail opts from to "Patch failed!" cc tempf throwIO ExitSuccess sendit tempf from e = do sendSanitizedEmail opts from to "Darcs error applying patch!" cc $ tempf ++ "\n\nCaught exception:\n"++ show e++"\n" throwIO ExitSuccess cc = getCc opts -- |sendSanitizedEmail sends a sanitized email using the given sendmailcmd -- It takes @DacrsFlag@ options a file with the mail contents, -- To:, Subject:, CC:, and mail body sendSanitizedEmail :: [DarcsFlag] -> String -> String -> String -> String -> String -> IO () sendSanitizedEmail opts from to subject cc mailtext = do scmd <- getSendmailCmd opts body <- sanitizeFile mailtext sendEmail from to subject cc scmd body -- sanitizeFile is used to clean up the stdout/stderr before sticking it in -- an email. sanitizeFile :: FilePath -> IO String sanitizeFile f = sanitize . BC.unpack <$> readBinFile f where sanitize s = wash $ remove_backspaces "" s wash ('\000':s) = "\\NUL" ++ wash s wash ('\026':s) = "\\EOF" ++ wash s wash (c:cs) = c : wash cs wash [] = [] remove_backspaces rev_sofar "" = reverse rev_sofar remove_backspaces (_:rs) ('\008':s) = remove_backspaces rs s remove_backspaces "" ('\008':s) = remove_backspaces "" s remove_backspaces rs (s:ss) = remove_backspaces (s:rs) ss darcs-2.14.5/src/Darcs/UI/Commands.hs0000644000000000000000000003105107346545000015325 0ustar0000000000000000-- Copyright (C) 2002,2003,2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE OverloadedStrings #-} module Darcs.UI.Commands ( CommandControl ( CommandData, HiddenCommand, GroupName ) , DarcsCommand ( .. ) , WrappedCommand(..) , wrappedCommandName , wrappedCommandDescription , commandAlias , commandStub , commandOptions , commandAlloptions , withStdOpts , disambiguateCommands , CommandArgs(..) , getSubcommands , extractCommands , extractAllCommands , normalCommand , hiddenCommand , commandGroup , superName , nodefaults , putInfo , putVerbose , putWarning , putVerboseWarning , abortRun , setEnvDarcsPatches , setEnvDarcsFiles , defaultRepo , amInHashedRepository , amInRepository , amNotInRepository , findRepository ) where import Prelude () import Darcs.Prelude import Prelude hiding ( (^) ) import Control.Monad ( when, unless ) import Data.List ( sort, isPrefixOf ) import Darcs.Util.Tree ( Tree ) import System.Console.GetOpt ( OptDescr ) import System.IO ( stderr ) import System.IO.Error ( catchIOError ) import System.Environment ( setEnv ) import Darcs.Patch ( listTouchedFiles ) import qualified Darcs.Patch ( summary ) import Darcs.Patch ( RepoPatch ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Info ( toXml ) import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info ) import Darcs.Patch.Witnesses.Ordered ( FL, mapFL ) import qualified Darcs.Repository as R ( amInHashedRepository, amInRepository , amNotInRepository, findRepository ) import Darcs.Repository.Prefs ( defaultrepo ) import Darcs.UI.Options ( DarcsOption, DarcsOptDescr, (^), optDescr, odesc, parseFlags, (?) ) import Darcs.UI.Options.All ( StdCmdAction, stdCmdActions, anyVerbosity, UseCache, useCache, HooksConfig, hooks , Verbosity(..), DryRun(..), dryRun ) import Darcs.UI.Flags ( DarcsFlag, remoteRepos, workRepo, quiet, verbose ) import Darcs.Util.ByteString ( decodeLocale, packStringToUTF8 ) import Darcs.Util.Path ( AbsolutePath ) import Darcs.Util.Printer ( Doc, text, (<+>), ($$), vcat , putDocLnWith, hPutDocLn, errorDoc, renderString ) import Darcs.Util.Printer.Color ( fancyPrinters ) import Darcs.Util.Progress ( debugMessage, beginTedious, endTedious, tediousSize, finishedOneIO ) extractCommands :: [CommandControl] -> [WrappedCommand] extractCommands ccl = [ cmd | CommandData cmd <- ccl ] extractHiddenCommands :: [CommandControl] -> [WrappedCommand] extractHiddenCommands ccl = [ cmd | HiddenCommand cmd <- ccl ] extractAllCommands :: [CommandControl] -> [WrappedCommand] extractAllCommands ccl = concatMap flatten (extractCommands ccl ++ extractHiddenCommands ccl) where flatten c@(WrappedCommand (DarcsCommand {})) = [c] flatten c@(WrappedCommand (SuperCommand { commandSubCommands = scs })) = c : extractAllCommands scs -- |A 'WrappedCommand' is a 'DarcsCommand' where the options type has been hidden data WrappedCommand where WrappedCommand :: DarcsCommand parsedFlags -> WrappedCommand normalCommand :: DarcsCommand parsedFlags -> CommandControl normalCommand c = CommandData (WrappedCommand c) hiddenCommand :: DarcsCommand parsedFlags -> CommandControl hiddenCommand c = HiddenCommand (WrappedCommand c) commandGroup :: String -> CommandControl commandGroup = GroupName wrappedCommandName :: WrappedCommand -> String wrappedCommandName (WrappedCommand c) = commandName c wrappedCommandDescription :: WrappedCommand -> String wrappedCommandDescription (WrappedCommand c) = commandDescription c data CommandControl = CommandData WrappedCommand | HiddenCommand WrappedCommand | GroupName String -- |A 'DarcsCommand' represents a command like add, record etc. -- The 'parsedFlags' type represents the options that are -- passed to the command's implementation data DarcsCommand parsedFlags = DarcsCommand { commandProgramName -- programs that use libdarcs can change the name here , commandName , commandHelp , commandDescription :: String , commandExtraArgs :: Int , commandExtraArgHelp :: [String] , commandCommand :: -- First 'AbsolutePath' is the repository path, -- second one is the path where darcs was executed. (AbsolutePath, AbsolutePath) -> parsedFlags -> [String] -> IO () , commandPrereq :: [DarcsFlag] -> IO (Either String ()) , commandCompleteArgs :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO [String] , commandArgdefaults :: [DarcsFlag] -> AbsolutePath -> [String] -> IO [String] , commandBasicOptions :: [DarcsOptDescr DarcsFlag] , commandAdvancedOptions :: [DarcsOptDescr DarcsFlag] , commandDefaults :: [DarcsFlag] , commandCheckOptions :: [DarcsFlag] -> [String] , commandParseOptions :: [DarcsFlag] -> parsedFlags } | SuperCommand { commandProgramName , commandName , commandHelp , commandDescription :: String , commandPrereq :: [DarcsFlag] -> IO (Either String ()) , commandSubCommands :: [CommandControl] } withStdOpts :: DarcsOption (Maybe StdCmdAction -> Bool -> Bool -> Verbosity -> Bool -> b) c -> DarcsOption (UseCache -> HooksConfig -> a) b -> DarcsOption a c withStdOpts basicOpts advancedOpts = basicOpts ^ stdCmdActions ^ anyVerbosity ^ advancedOpts ^ useCache ^ hooks commandAlloptions :: DarcsCommand pf -> ([DarcsOptDescr DarcsFlag], [DarcsOptDescr DarcsFlag]) commandAlloptions DarcsCommand { commandBasicOptions = opts1 , commandAdvancedOptions = opts2 } = ( opts1 ++ odesc stdCmdActions , odesc anyVerbosity ++ opts2 ++ odesc useCache ++ odesc hooks ) commandAlloptions SuperCommand { } = (odesc stdCmdActions, []) -- Obtain options suitable as input to System.Console.Getopt, including the -- --disable option (which is not listed explicitly in the DarcsCommand -- definitions). commandOptions :: AbsolutePath -> DarcsCommand pf -> [OptDescr DarcsFlag] commandOptions cwd = map (optDescr cwd) . uncurry (++) . commandAlloptions nodefaults :: [DarcsFlag] -> AbsolutePath -> [String] -> IO [String] nodefaults _ _ = return getSubcommands :: DarcsCommand pf -> [CommandControl] getSubcommands c@(SuperCommand {}) = commandGroup "Subcommands:" : commandSubCommands c getSubcommands _ = [] commandAlias :: String -> Maybe (DarcsCommand pf) -> DarcsCommand pf -> DarcsCommand pf commandAlias n msuper c = c { commandName = n , commandDescription = "Alias for `" ++ commandProgramName c ++ " " ++ cmdName ++ "'." , commandHelp = "The `" ++ commandProgramName c ++ " " ++ n ++ "' command is an alias for " ++ "`" ++ commandProgramName c ++ " " ++ cmdName ++ "'.\n" ++ commandHelp c } where cmdName = unwords . map commandName . maybe id (:) msuper $ [ c ] commandStub :: String -> String -> String -> DarcsCommand pf -> DarcsCommand pf commandStub n h d c = c { commandName = n , commandHelp = h , commandDescription = d , commandCommand = \_ _ _ -> putStr h } superName :: Maybe (DarcsCommand pf) -> String superName Nothing = "" superName (Just x) = commandName x ++ " " data CommandArgs where CommandOnly :: DarcsCommand parsedFlags -> CommandArgs SuperCommandOnly :: DarcsCommand parsedFlags -> CommandArgs SuperCommandSub :: DarcsCommand parsedFlags1 -> DarcsCommand parsedFlags2 -> CommandArgs -- Parses a darcs command line with potentially abbreviated commands disambiguateCommands :: [CommandControl] -> String -> [String] -> Either String (CommandArgs, [String]) disambiguateCommands allcs cmd args = do WrappedCommand c <- extract cmd allcs case (getSubcommands c, args) of ([], _) -> return (CommandOnly c, args) (_, []) -> return (SuperCommandOnly c, args) (subcs, a : as) -> case extract a subcs of Left _ -> return (SuperCommandOnly c, args) Right (WrappedCommand sc) -> return (SuperCommandSub c sc, as) extract :: String -> [CommandControl] -> Either String WrappedCommand extract cmd cs = case potentials of [] -> Left $ "No such command '" ++ cmd ++ "'\n" [c] -> Right c cs' -> Left $ unlines [ "Ambiguous command..." , "" , "The command '" ++ cmd ++ "' could mean one of:" , unwords . sort . map wrappedCommandName $ cs' ] where potentials = [c | c <- extractCommands cs, cmd `isPrefixOf` wrappedCommandName c] ++ [h | h <- extractHiddenCommands cs, cmd == wrappedCommandName h] putVerbose :: [DarcsFlag] -> Doc -> IO () putVerbose flags = when (verbose flags) . putDocLnWith fancyPrinters putInfo :: [DarcsFlag] -> Doc -> IO () putInfo flags = unless (quiet flags) . putDocLnWith fancyPrinters putWarning :: [DarcsFlag] -> Doc -> IO () putWarning flags = unless (quiet flags) . hPutDocLn stderr putVerboseWarning :: [DarcsFlag] -> Doc -> IO () putVerboseWarning flags = when (verbose flags) . hPutDocLn stderr abortRun :: [DarcsFlag] -> Doc -> IO () abortRun flags msg = if parseFlags dryRun flags == YesDryRun then putInfo flags $ "NOTE:" <+> msg else errorDoc msg -- | Set the DARCS_PATCHES and DARCS_PATCHES_XML environment variables with -- info about the given patches, for use in post-hooks. setEnvDarcsPatches :: (RepoPatch p, ApplyState p ~ Tree) => FL (PatchInfoAnd rt p) wX wY -> IO () setEnvDarcsPatches ps = do let k = "Defining set of chosen patches" debugMessage $ unlines ("setEnvDarcsPatches:" : listTouchedFiles ps) beginTedious k tediousSize k 3 finishedOneIO k "DARCS_PATCHES" setEnvCautiously "DARCS_PATCHES" (renderString $ Darcs.Patch.summary ps) finishedOneIO k "DARCS_PATCHES_XML" setEnvCautiously "DARCS_PATCHES_XML" . renderString $ text "" $$ vcat (mapFL (toXml . info) ps) $$ text "" finishedOneIO k "DARCS_FILES" setEnvCautiously "DARCS_FILES" $ unlines (listTouchedFiles ps) endTedious k -- | Set the DARCS_FILES environment variable to the files touched by the -- given patch, one per line, for use in post-hooks. setEnvDarcsFiles :: (PatchInspect p) => p wX wY -> IO () setEnvDarcsFiles ps = setEnvCautiously "DARCS_FILES" $ unlines (listTouchedFiles ps) -- | Set some environment variable to the given value, unless said value is -- longer than 10K characters, in which case do nothing. setEnvCautiously :: String -> String -> IO () setEnvCautiously e v | toobig (10 * 1024) v = return () | otherwise = setEnv e v `catchIOError` (\_ -> setEnv e (decodeLocale (packStringToUTF8 v))) where -- note: not using (length v) because we want to be more lazy than that toobig :: Int -> [a] -> Bool toobig 0 _ = True toobig _ [] = False toobig n (_ : xs) = toobig (n - 1) xs defaultRepo :: [DarcsFlag] -> AbsolutePath -> [String] -> IO [String] defaultRepo fs = defaultrepo (remoteRepos ? fs) amInHashedRepository :: [DarcsFlag] -> IO (Either String ()) amInHashedRepository fs = R.amInHashedRepository (workRepo ? fs) amInRepository :: [DarcsFlag] -> IO (Either String ()) amInRepository fs = R.amInRepository (workRepo ? fs) amNotInRepository :: [DarcsFlag] -> IO (Either String ()) amNotInRepository fs = R.amNotInRepository (workRepo ? fs) findRepository :: [DarcsFlag] -> IO (Either String ()) findRepository fs = R.findRepository (workRepo ? fs) darcs-2.14.5/src/Darcs/UI/Commands/0000755000000000000000000000000007346545000014771 5ustar0000000000000000darcs-2.14.5/src/Darcs/UI/Commands/Add.hs0000644000000000000000000003100307346545000016012 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | -- Module : Darcs.UI.Commands.Add -- Copyright : 2002-2004 David Roundy -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.UI.Commands.Add ( add ) where import Prelude () import Darcs.Prelude import Control.Exception ( catch, IOException ) import Control.Monad ( when, unless ) import Data.List ( (\\), nub ) import Data.List.Ordered ( nubSort ) import Data.Maybe ( isNothing, maybeToList ) import Darcs.Util.Printer ( text ) import Darcs.Util.Tree ( Tree, findTree, expand ) import Darcs.Util.Path ( floatPath, anchorPath, parents , SubPath, toFilePath, AbsolutePath ) import System.FilePath.Posix ( takeDirectory ) import System.Posix.Files ( isRegularFile, isDirectory, isSymbolicLink ) import System.Directory ( getPermissions, readable ) import qualified System.FilePath.Windows as WindowsFilePath import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, putInfo, putWarning, putVerboseWarning , nodefaults, amInHashedRepository) import Darcs.UI.Commands.Util.Tree ( treeHas, treeHasDir, treeHasAnycase ) import Darcs.UI.Commands.Util ( expandDirs, doesDirectoryReallyExist ) import Darcs.UI.Completion ( unknownFileArgs ) import Darcs.UI.Flags ( DarcsFlag , includeBoring, allowCaseDifferingFilenames, allowWindowsReservedFilenames, useCache, dryRun, umask , fixSubPaths, quiet ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking(..) ) import Darcs.Patch ( PrimPatch, applyToTree, addfile, adddir ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Repository.State ( readRecordedAndPending, updateIndex ) import Darcs.Repository ( withRepoLock , RepoJob(..) , addToPending ) import Darcs.Repository.Prefs ( darcsdirFilter, boringFileFilter ) import Darcs.Util.File ( getFileStatus ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (+>+), nullFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), Gap(..), FreeLeft, unFreeLeft ) addDescription :: String addDescription = "Add new files to version control." addHelp :: String addHelp = "Generally the working tree contains both files that should be version\n" ++ "controlled (such as source code) and files that Darcs should ignore\n" ++ "(such as executables compiled from the source code). The `darcs add`\n" ++ "command is used to tell Darcs which files to version control.\n" ++ "\n" ++ "When an existing project is first imported into a Darcs repository, it\n" ++ "is common to run `darcs add -r *` or `darcs record -l` to add all\n" ++ "initial source files into darcs.\n"++ "\n" ++ "Adding symbolic links (symlinks) is not supported.\n\n" addHelp' :: String addHelp' = "Darcs will ignore all files and folders that look \"boring\". The\n" ++ "`--boring` option overrides this behaviour.\n" ++ "\n" ++ "Darcs will not add file if another file in the same folder has the\n" ++ "same name, except for case. The `--case-ok` option overrides this\n" ++ "behaviour. Windows and OS X usually use filesystems that do not allow\n" ++ "files a folder to have the same name except for case (for example,\n" ++ "`ReadMe` and `README`). If `--case-ok` is used, the repository might be\n" ++ "unusable on those systems!\n\n" add :: DarcsCommand [DarcsFlag] add = DarcsCommand { commandProgramName = "darcs" , commandName = "add" , commandHelp = addHelp ++ addHelp' , commandDescription = addDescription , commandExtraArgs = -1 , commandExtraArgHelp = [ " ..." ] , commandCommand = addCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = unknownFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc addAdvancedOpts , commandBasicOptions = odesc addBasicOpts , commandDefaults = defaultFlags addOpts , commandCheckOptions = ocheck addOpts , commandParseOptions = onormalise addOpts } where addBasicOpts = O.includeBoring ^ O.allowProblematicFilenames ^ O.recursive ^ O.repoDir ^ O.dryRun addAdvancedOpts = O.umask addOpts = withStdOpts addBasicOpts addAdvancedOpts addCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () addCmd paths opts args | null args = putStrLn $ "Nothing specified, nothing added." ++ "Maybe you wanted to say `darcs add --recursive .'?" | otherwise = do fs <- fixSubPaths paths args case fs of [] -> fail "No valid arguments were given" _ -> addFiles opts fs addFiles :: [DarcsFlag] -- ^ Command options -> [SubPath] -> IO () addFiles opts origfiles = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do -- TODO do not expand here, and use findM/findIO or such later -- (needs adding to hashed-storage first though) cur <- expand =<< readRecordedAndPending repository let parlist = getParents cur (map toFilePath origfiles) flist' <- if parseFlags O.recursive opts then expandDirs (includeBoring opts) origfiles else return origfiles let flist = nubSort (parlist ++ toFilePath `map` flist') nboring <- if includeBoring opts then return darcsdirFilter else boringFileFilter mapM_ (putWarning opts . text . ((msgSkipping msgs ++ " boring file ")++)) $ flist \\ nboring flist Sealed ps <- fmap unFreeLeft $ addp msgs opts cur $ nboring flist -- TODO whether we fail or not depends on verbosity BAD BAD BAD when (nullFL ps && not (null origfiles) && not (quiet opts)) $ fail "No files were added" unless gotDryRun $ do addToPending repository YesUpdateWorking ps updateIndex repository where gotDryRun = dryRun ? opts == O.YesDryRun msgs | gotDryRun = dryRunMessages | otherwise = normalMessages addp :: forall prim . (PrimPatch prim, ApplyState prim ~ Tree) => AddMessages -> [DarcsFlag] -> Tree IO -> [FilePath] -> IO (FreeLeft (FL prim)) addp msgs opts cur0 files = do (ps, dups) <- foldr (\f rest cur accPS accDups -> do addResult <- addp' cur f case addResult of -- If a single file fails to add, stop further processing. (_, Nothing, Nothing) -> return ([], []) (cur', mp, mdup) -> rest cur' (maybeToList mp ++ accPS) (maybeToList mdup ++ accDups)) (\_ ps dups -> return (reverse ps, dups)) files cur0 [] [] let uniq_dups = nub dups caseMsg = if gotAllowCaseOnly then ":" else ";\nnote that to ensure portability we don't allow\n" ++ "files that differ only in case. Use --case-ok to override this:" unless (null dups) $ do dupMsg <- case uniq_dups of [f] -> do isDir <- doesDirectoryReallyExist f if isDir then return $ "The following directory " ++ msgIs msgs ++ " already in the repository" else return $ "The following file " ++ msgIs msgs ++ " already in the repository" fs -> do areDirs <- mapM doesDirectoryReallyExist fs if and areDirs then return $ "The following directories " ++ msgAre msgs ++ " already in the repository" else (if or areDirs then return $ "The following files and directories " ++ msgAre msgs ++ " already in the repository" else return $ "The following files " ++ msgAre msgs ++ " already in the repository") putWarning opts . text $ "WARNING: Some files were not added because they are already in the repository." putVerboseWarning opts . text $ dupMsg ++ caseMsg mapM_ (putVerboseWarning opts . text) uniq_dups return $ foldr (joinGap (+>+)) (emptyGap NilFL) ps where addp' :: Tree IO -> FilePath -> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe FilePath) addp' cur f = do already_has <- (if gotAllowCaseOnly then treeHas else treeHasAnycase) cur f mstatus <- getFileStatus f case (already_has, is_badfilename, mstatus) of (True, _, _) -> return (cur, Nothing, Just f) (_, True, _) -> do putWarning opts . text $ "The filename " ++ f ++ " is invalid under Windows.\n" ++ "Use --reserved-ok to allow it." return add_failure (_, _, Just s) | isDirectory s -> trypatch $ freeGap (adddir f :>: NilFL) | isRegularFile s -> trypatch $ freeGap (addfile f :>: NilFL) | isSymbolicLink s -> do putWarning opts . text $ "Sorry, file " ++ f ++ " is a symbolic link, which is unsupported by darcs." return add_failure _ -> do putWarning opts . text $ "File "++ f ++" does not exist!" return add_failure where is_badfilename = not (gotAllowWindowsReserved || WindowsFilePath.isValid f) add_failure = (cur, Nothing, Nothing) trypatch :: FreeLeft (FL prim) -> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe FilePath) trypatch p = do perms <- getPermissions f if not $ readable perms then do putWarning opts . text $ msgSkipping msgs ++ " '" ++ f ++ "': permission denied " return (cur, Nothing, Nothing) else trypatch' p trypatch' p = do Sealed p' <- return $ unFreeLeft p ok <- treeHasDir cur parentdir if ok then do tree <- applyToTree p' cur putInfo opts . text $ msgAdding msgs ++ " '" ++ f ++ "'" return (tree, Just p, Nothing) else do putWarning opts . text $ msgSkipping msgs ++ " '" ++ f ++ "' ... couldn't add parent directory '" ++ parentdir ++ "' to repository" return (cur, Nothing, Nothing) `catch` \(e :: IOException) -> do putWarning opts . text $ msgSkipping msgs ++ " '" ++ f ++ "' ... " ++ show e return (cur, Nothing, Nothing) parentdir = takeDirectory f gotAllowCaseOnly = allowCaseDifferingFilenames ? opts gotAllowWindowsReserved = allowWindowsReservedFilenames ? opts data AddMessages = AddMessages { msgSkipping :: String , msgAdding :: String , msgIs :: String , msgAre :: String } normalMessages :: AddMessages normalMessages = AddMessages { msgSkipping = "Skipping" , msgAdding = "Adding" , msgIs = "is" , msgAre = "are" } dryRunMessages :: AddMessages dryRunMessages = AddMessages { msgSkipping = "Would skip" , msgAdding = "Would add" , msgIs = "would be" , msgAre = "would be" } getParents :: Tree IO -> [FilePath] -> [FilePath] getParents cur = map (anchorPath "") . go . map floatPath where go fs = filter (isNothing . findTree cur) $ concatMap parents fs darcs-2.14.5/src/Darcs/UI/Commands/Amend.hs0000644000000000000000000004036407346545000016360 0ustar0000000000000000-- Copyright (C) 2004,2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | -- Copyright : 2004, 2007 David Roundy -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.UI.Commands.Amend ( amend , amendrecord ) where import Prelude () import Darcs.Prelude import Data.Maybe ( isNothing, isJust ) import Control.Monad ( when ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts , commandAlias , nodefaults , setEnvDarcsFiles , setEnvDarcsPatches , amInHashedRepository ) import Darcs.UI.Commands.Util ( announceFiles, testTentativeAndMaybeExit ) import Darcs.UI.Completion ( modifiedFileArgs, knownFileArgs ) import Darcs.UI.Flags ( DarcsFlag, diffOpts, fixSubPaths ) import Darcs.UI.Options ( DarcsOption, (^), oparse, odesc, ocheck, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.PatchHeader ( updatePatchHeader, AskAboutDeps(..) , HijackOptions(..) , runHijackT ) import Darcs.Repository.Flags ( UpdateWorking(..), DryRun(NoDryRun) ) import Darcs.Patch ( IsRepoType, RepoPatch, description, PrimOf , effect, invert, invertFL ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.Info ( isTag ) import Darcs.Patch.Split ( primSplitter ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info, patchDesc ) import Darcs.Patch.Rebase.Fixup ( RebaseFixup(..) ) import Darcs.Patch.Rebase.Name ( RebaseName(..) ) import Darcs.Util.Path ( toFilePath, SubPath(), AbsolutePath ) import Darcs.Repository ( Repository , withRepoLock , RepoJob(..) , RebaseJobFlags(..) , tentativelyRemovePatches , tentativelyAddPatch , withManualRebaseUpdate , finalizeRepositoryChanges , invalidateIndex , unrecordedChanges , readRecorded ) import Darcs.Repository.Prefs ( globalPrefsDirDoc ) import Darcs.UI.SelectChanges ( WhichChanges(..) , selectionContextPrim , runSelection , withSelectedPatchFromRepo ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions(..) ) import Darcs.Util.Exception ( clarifyErrors ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (:>)(..), (+>+), nullFL, reverseRL, mapFL_FL ) import Darcs.Util.Printer ( putDocLn ) import Darcs.Util.Tree( Tree ) import Darcs.Repository.Pending ( tentativelyRemoveFromPending ) amendDescription :: String amendDescription = "Improve a patch before it leaves your repository." amendHelp :: String amendHelp = "Amend updates a \"draft\" patch with additions or improvements,\n" ++ "resulting in a single \"finished\" patch.\n" ++ "\n" ++ "By default `amend` proposes you to record additional changes.\n" ++ "If instead you want to remove changes, use the flag `--unrecord`.\n" ++ "\n" ++ "When recording a draft patch, it is a good idea to start the name with\n" ++ "`DRAFT:`. When done, remove it with `darcs amend --edit-long-comment`.\n" ++ "Alternatively, to change the patch name without starting an editor, \n" ++ "use the `--name`/`-m` flag:\n" ++ "\n" ++ " darcs amend --match 'name \"DRAFT: foo\"' --name 'foo2'\n" ++ "\n" ++ "Like `darcs record`, if you call amend with files as arguments,\n" ++ "you will only be asked about changes to those files. So to amend a\n" ++ "patch to foo.c with improvements in bar.c, you would run:\n" ++ "\n" ++ " darcs amend --match 'touch foo.c' bar.c\n" ++ "\n" ++ "It is usually a bad idea to amend another developer's patch. To make\n" ++ "amend only ask about your own patches by default, you can add\n" ++ "something like `amend match David Roundy` to `" ++ globalPrefsDirDoc ++ "defaults`, \n" ++ "where `David Roundy` is your name.\n" amendBasicOpts :: DarcsOption a (Bool -> [O.MatchFlag] -> O.TestChanges -> Maybe Bool -> Maybe String -> Bool -> Maybe String -> Bool -> Maybe O.AskLongComment -> Bool -> O.LookFor -> Maybe String -> O.WithContext -> O.DiffAlgorithm -> a) amendBasicOpts = O.amendUnrecord ^ O.matchOneNontag ^ O.testChanges ^ O.interactive --True ^ O.author ^ O.selectAuthor ^ O.patchname ^ O.askDeps ^ O.askLongComment ^ O.keepDate ^ O.lookfor ^ O.repoDir ^ O.withContext ^ O.diffAlgorithm amendAdvancedOpts :: DarcsOption a (O.Compression -> O.UseIndex -> O.UMask -> O.SetScriptsExecutable -> a) amendAdvancedOpts = O.compress ^ O.useIndex ^ O.umask ^ O.setScriptsExecutable amendOpts :: DarcsOption a (Bool -> [O.MatchFlag] -> O.TestChanges -> Maybe Bool -> Maybe String -> Bool -> Maybe String -> Bool -> Maybe O.AskLongComment -> Bool -> O.LookFor -> Maybe String -> O.WithContext -> O.DiffAlgorithm -> Maybe O.StdCmdAction -> Bool -> Bool -> O.Verbosity -> Bool -> O.Compression -> O.UseIndex -> O.UMask -> O.SetScriptsExecutable -> O.UseCache -> O.HooksConfig -> a) amendOpts = withStdOpts amendBasicOpts amendAdvancedOpts data AmendConfig = AmendConfig { amendUnrecord :: Bool , matchFlags :: [O.MatchFlag] , testChanges :: O.TestChanges , interactive :: Maybe Bool , author :: Maybe String , selectAuthor :: Bool , patchname :: Maybe String , askDeps :: Bool , askLongComment :: Maybe O.AskLongComment , keepDate :: Bool , lookfor :: O.LookFor , _workingRepoDir :: Maybe String , withContext :: O.WithContext , diffAlgorithm :: O.DiffAlgorithm , verbosity :: O.Verbosity , compress :: O.Compression , useIndex :: O.UseIndex , umask :: O.UMask , sse :: O.SetScriptsExecutable , useCache :: O.UseCache } amendConfig :: [DarcsFlag] -> AmendConfig amendConfig = oparse (amendBasicOpts ^ O.verbosity ^ amendAdvancedOpts ^ O.useCache) AmendConfig amend :: DarcsCommand AmendConfig amend = DarcsCommand { commandProgramName = "darcs" , commandName = "amend" , commandHelp = amendHelp , commandDescription = amendDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[FILE or DIRECTORY]..."] , commandCommand = amendCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = amendFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc amendAdvancedOpts , commandBasicOptions = odesc amendBasicOpts , commandDefaults = defaultFlags amendOpts , commandCheckOptions = ocheck amendOpts , commandParseOptions = amendConfig } where amendFileArgs fps flags args = if (O.amendUnrecord ? flags) then knownFileArgs fps flags args else modifiedFileArgs fps flags args amendrecord :: DarcsCommand AmendConfig amendrecord = commandAlias "amend-record" Nothing amend amendCmd :: (AbsolutePath, AbsolutePath) -> AmendConfig -> [String] -> IO () amendCmd _ cfg [] = doAmend cfg Nothing amendCmd fps cfg args = do files <- fixSubPaths fps args if null files then fail "No valid arguments were given, nothing to do." else doAmend cfg $ Just files doAmend :: AmendConfig -> Maybe [SubPath] -> IO () doAmend cfg files = let rebaseJobFlags = RebaseJobFlags (compress cfg) (verbosity cfg) YesUpdateWorking in withRepoLock NoDryRun (useCache cfg) YesUpdateWorking (umask cfg) $ RebaseAwareJob rebaseJobFlags $ \(repository :: Repository rt p wR wU wR) -> withSelectedPatchFromRepo "amend" repository (patchSelOpts cfg) $ \ (_ :> oldp) -> do announceFiles (verbosity cfg) files "Amending changes in" -- auxiliary function needed because the witness types differ for the isTag case pristine <- readRecorded repository let go :: forall wU1 . FL (PrimOf p) wR wU1 -> IO () go NilFL | not (hasEditMetadata cfg) = putStrLn "No changes!" go ch = do let context = selectionContextPrim First "record" (patchSelOpts cfg) --([All,Unified] `intersect` opts) (Just (primSplitter (diffAlgorithm cfg))) (map toFilePath <$> files) (Just pristine) (chosenPatches :> _) <- runSelection ch context addChangesToPatch cfg repository oldp chosenPatches if not (isTag (info oldp)) -- amending a normal patch then if amendUnrecord cfg then do let context = selectionContextPrim Last "unrecord" (patchSelOpts cfg) -- ([All,Unified] `intersect` opts) (Just (primSplitter (diffAlgorithm cfg))) (map toFilePath <$> files) (Just pristine) (_ :> chosenPrims) <- runSelection (effect oldp) context let invPrims = reverseRL (invertFL chosenPrims) addChangesToPatch cfg repository oldp invPrims else go =<< unrecordedChanges (diffingOpts cfg) (O.moves (lookfor cfg)) (O.replaces (lookfor cfg)) repository files -- amending a tag else if hasEditMetadata cfg && isNothing files -- the user is not trying to add new changes to the tag so there is -- no reason to warn. then go NilFL -- the user is trying to add new changes to a tag. else do if hasEditMetadata cfg -- the user already knows that it is possible to edit tag metadata, -- note that s/he is providing editing options! then putStrLn "You cannot add new changes to a tag." -- the user may not be aware that s/he can edit tag metadata. else putStrLn "You cannot add new changes to a tag, but you are allowed to edit tag's metadata (see darcs help amend)." go NilFL addChangesToPatch :: forall rt p wR wU wT wX wY . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => AmendConfig -> Repository rt p wR wU wT -> PatchInfoAnd rt p wX wT -> FL (PrimOf p) wT wY -> IO () addChangesToPatch cfg repository oldp chs = let rebaseJobFlags = RebaseJobFlags (compress cfg) (verbosity cfg) YesUpdateWorking in if nullFL chs && not (hasEditMetadata cfg) then putStrLn "You don't want to record anything!" else do invalidateIndex repository -- If a rebase is in progress, we want to manually update the rebase state, using -- the amendments directly as rebase fixups. This is necessary because otherwise -- the normal commute rules for the rebase state will first remove the original -- patch then add the amended patch, and this can lead to more conflicts than using -- the amendment as a fixup directly. For example, if a rename operation is amended in, -- the rename can be propagated to any edits to the file in the rebase state, whereas -- a delete then add would just cause a conflict. -- -- We can also signal that any explicit dependencies of the old patch should be rewritten -- for the new patch using a 'NameFixup'. (repository''', (mlogf, newp)) <- withManualRebaseUpdate rebaseJobFlags repository $ \repository' -> do repository'' <- tentativelyRemovePatches repository' (compress cfg) YesUpdateWorking (oldp :>: NilFL) (mlogf, newp) <- runHijackT AlwaysRequestHijackPermission $ updatePatchHeader "amend" (if askDeps cfg then AskAboutDeps repository'' else NoAskAboutDeps) (patchSelOpts cfg) (diffAlgorithm cfg) (keepDate cfg) (selectAuthor cfg) (author cfg) (patchname cfg) (askLongComment cfg) oldp chs let fixups = mapFL_FL PrimFixup (invert chs) +>+ NameFixup (Rename (info newp) (info oldp)) :>: NilFL setEnvDarcsFiles newp repository''' <- tentativelyAddPatch repository'' (compress cfg) (verbosity cfg) YesUpdateWorking newp return (repository''', fixups, (mlogf, newp)) let failmsg = maybe "" (\lf -> "\nLogfile left in "++lf++".") mlogf testTentativeAndMaybeExit repository''' (verbosity cfg) (testChanges cfg) (sse cfg) (isInteractive cfg) ("you have a bad patch: '" ++ patchDesc newp ++ "'") "amend it" (Just failmsg) when (O.moves (lookfor cfg) == O.YesLookForMoves || O.replaces (lookfor cfg) == O.YesLookForReplaces) $ tentativelyRemoveFromPending repository''' YesUpdateWorking oldp finalizeRepositoryChanges repository''' YesUpdateWorking (compress cfg) `clarifyErrors` failmsg putStrLn "Finished amending patch:" putDocLn $ description newp setEnvDarcsPatches (newp :>: NilFL) hasEditMetadata :: AmendConfig -> Bool hasEditMetadata cfg = isJust (author cfg) || selectAuthor cfg || isJust (patchname cfg) || askLongComment cfg == Just O.YesEditLongComment || askLongComment cfg == Just O.PromptLongComment || askDeps cfg -- hasEditMetadata [] = False -- hasEditMetadata (Author _:_) = True -- hasEditMetadata (SelectAuthor:_) = True -- hasEditMetadata (LogFile _:_) = True -- ??? not listed as an option for amend -- hasEditMetadata (PatchName _:_) = True -- hasEditMetadata (EditLongComment:_) = True -- hasEditMetadata (PromptLongComment:_) = True -- hasEditMetadata (AskDeps:_) = True -- hasEditMetadata (_:fs) = hasEditMetadata fs patchSelOpts :: AmendConfig -> S.PatchSelectionOptions patchSelOpts cfg = S.PatchSelectionOptions { S.verbosity = verbosity cfg , S.matchFlags = matchFlags cfg , S.interactive = isInteractive cfg , S.selectDeps = O.PromptDeps -- option not supported, use default , S.summary = O.NoSummary -- option not supported, use default , S.withContext = withContext cfg } diffingOpts :: AmendConfig -> (O.UseIndex, O.ScanKnown, O.DiffAlgorithm) diffingOpts cfg = diffOpts (useIndex cfg) (O.adds (lookfor cfg)) O.NoIncludeBoring (diffAlgorithm cfg) isInteractive :: AmendConfig -> Bool isInteractive = maybe True id . interactive darcs-2.14.5/src/Darcs/UI/Commands/Annotate.hs0000644000000000000000000001463707346545000017111 0ustar0000000000000000-- Copyright (C) 2003 David Roundy, 2010-2011 Petr Rockai -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE OverloadedStrings #-} module Darcs.UI.Commands.Annotate ( annotate ) where import Prelude () import Darcs.Prelude import Control.Arrow ( first ) import Control.Monad ( when ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInHashedRepository ) import Darcs.UI.Completion ( knownFileArgs ) import Darcs.UI.Flags ( DarcsFlag, useCache, fixSubPaths, patchIndexYes ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise , defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.State ( readRecorded ) import Darcs.Repository ( withRepository , withRepoLockCanFail , RepoJob(..) , readRepo , repoPatchType ) import Darcs.Repository.PatchIndex ( attemptCreatePatchIndex ) import Darcs.Patch.Set ( patchSet2RL ) import Darcs.Patch ( invertRL ) import qualified Data.ByteString.Char8 as BC ( pack, concat, intercalate ) import Data.ByteString.Lazy ( toChunks ) import Darcs.Patch.ApplyMonad( withFileNames ) import System.FilePath.Posix ( () ) import Darcs.Patch.Match ( haveNonrangeMatch, getNonrangeMatchS ) import Darcs.Repository.Match ( getOnePatchset ) import Darcs.Repository.PatchIndex ( getRelevantSubsequence, canUsePatchIndex ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), seal ) import qualified Darcs.Patch.Annotate as A import Darcs.Util.Tree( TreeItem(..), readBlob, list, expand ) import Darcs.Util.Tree.Monad( findM, virtualTreeIO ) import Darcs.Util.Path( floatPath, anchorPath, fp2fn, toFilePath , AbsolutePath, SubPath ) import Darcs.Util.Exception ( die ) annotateDescription :: String annotateDescription = "Annotate lines of a file with the last patch that modified it." annotateHelp :: String annotateHelp = unlines [ "When `darcs annotate` is called on a file, it will find the patch that" , "last modified each line in that file. This also works on directories." , "" , "The `--machine-readable` option can be used to generate output for" , "machine postprocessing." ] annotate :: DarcsCommand [DarcsFlag] annotate = DarcsCommand { commandProgramName = "darcs" , commandName = "annotate" , commandHelp = annotateHelp , commandDescription = annotateDescription , commandExtraArgs = 1 , commandExtraArgHelp = ["[FILE or DIRECTORY]"] , commandCommand = annotateCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = knownFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc annotateAdvancedOpts , commandBasicOptions = odesc annotateBasicOpts , commandDefaults = defaultFlags annotateOpts , commandCheckOptions = ocheck annotateOpts , commandParseOptions = onormalise annotateOpts } where annotateBasicOpts = O.machineReadable ^ O.matchUpToOne ^ O.repoDir annotateAdvancedOpts = O.patchIndexYes annotateOpts = annotateBasicOpts `withStdOpts` annotateAdvancedOpts annotateCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () annotateCmd fps opts args = do fixed_paths <- fixSubPaths fps args case fixed_paths of [] -> die "Error: annotate needs a filename to work with" (fixed_path:_) -> do when (patchIndexYes ? opts == O.YesPatchIndex) $ withRepoLockCanFail (useCache ? opts) $ RepoJob (\repo -> readRepo repo >>= attemptCreatePatchIndex repo) annotateCmd' opts fixed_path annotateCmd' :: [DarcsFlag] -> SubPath -> IO () annotateCmd' opts fixed_path = withRepository (useCache ? opts) $ RepoJob $ \repository -> do let matchFlags = parseFlags O.matchUpToOne opts r <- readRepo repository recorded <- readRecorded repository (patches, initial, path') <- if haveNonrangeMatch (repoPatchType repository) matchFlags then do Sealed x <- getOnePatchset repository matchFlags let fn = [fp2fn $ toFilePath fixed_path] nonRangeMatch = getNonrangeMatchS matchFlags r (_, [path], _) = withFileNames Nothing fn nonRangeMatch initial <- snd `fmap` virtualTreeIO (getNonrangeMatchS matchFlags r) recorded return (seal $ patchSet2RL x, initial, toFilePath path) else return (seal $ patchSet2RL r, recorded, toFilePath fixed_path) let path = "./" ++ path' found <- findM initial (floatPath $ toFilePath path) -- TODO need to decide about the --machine flag let fmt = if parseFlags O.machineReadable opts then A.machineFormat else A.format usePatchIndex <- (O.yes (O.patchIndexYes ? opts) &&) <$> canUsePatchIndex repository case found of Nothing -> die $ "Error: no such file or directory: " ++ toFilePath path Just (SubTree s) -> do s' <- expand s let subs = map (fp2fn . (path ) . anchorPath "" . fst) $ list s' showPath (n, File _) = BC.pack (path n) showPath (n, _) = BC.concat [BC.pack (path n), "/"] (Sealed ans_patches) <- do if not usePatchIndex then return patches else getRelevantSubsequence patches repository r subs putStrLn $ fmt (BC.intercalate "\n" $ map (showPath . first (anchorPath "")) $ list s') $ A.annotateDirectory (invertRL ans_patches) (fp2fn path) subs Just (File b) -> do (Sealed ans_patches) <- do if not usePatchIndex then return patches else getRelevantSubsequence patches repository r [fp2fn path] con <- BC.concat `fmap` toChunks `fmap` readBlob b putStrLn $ fmt con $ A.annotateFile (invertRL ans_patches) (fp2fn path) con Just (Stub _ _) -> impossible darcs-2.14.5/src/Darcs/UI/Commands/Apply.hs0000644000000000000000000003521407346545000016417 0ustar0000000000000000-- Copyright (C) 2003-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Apply ( apply, applyCmd , getPatchBundle -- used by darcsden ) where import Prelude () import Darcs.Prelude import System.Exit ( exitSuccess ) import Control.Monad ( when ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, hopefullyM, info ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts , putVerbose , amInHashedRepository ) import Darcs.UI.Completion ( fileArgs ) import Darcs.UI.Flags ( DarcsFlag , happyForwarding, changesReverse, verbosity, useCache, dryRun , reorder, umask , fixUrl, getCc, getSendmailCmd , withContext, reply ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking(..) ) import Darcs.Util.Path ( toFilePath, AbsolutePath ) import Darcs.Repository ( Repository , SealedPatchSet , withRepoLock , readRepo , filterOutConflicts ) import Darcs.Patch.Set ( Origin, patchSet2RL ) import Darcs.Patch ( IsRepoType, RepoPatch ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Info ( PatchInfo, displayPatchInfo ) import Darcs.Patch.Witnesses.Ordered ( RL(..), (:\/:)(..), (:>)(..) , mapRL, nullFL, reverseFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed) ) import Darcs.Util.ByteString ( linesPS, unlinesPS, gzReadStdin ) import Data.List( (\\) ) import qualified Data.ByteString as B (ByteString, null, init, take, drop) import qualified Data.ByteString.Char8 as BC (unpack, last, pack) import Darcs.Util.Download ( Cachable(Uncachable) ) import Darcs.Util.External ( gzFetchFilePS ) import Darcs.UI.External ( sendEmailDoc , resendEmail , verifyPS ) import Darcs.UI.Email ( readEmail ) import Darcs.Patch.Depends ( findUncommon, findCommonWithThem ) import Darcs.UI.ApplyPatches ( PatchApplier(..), StandardPatchApplier(..), PatchProxy ) import Darcs.UI.SelectChanges ( WhichChanges(..) , runSelection , selectionContext ) import qualified Darcs.UI.SelectChanges as S import Darcs.Patch.Bundle ( scanBundle ) import Darcs.Util.Printer ( packedString, vcat, text, empty , renderString ) import Darcs.Util.Tree( Tree ) applyDescription :: String applyDescription = "Apply a patch bundle created by `darcs send'." applyHelp :: String applyHelp = unlines [ "The `darcs apply` command takes a patch bundle and attempts to insert" , "it into the current repository. In addition to invoking it directly" , "on bundles created by `darcs send`, it is used internally by `darcs" , "push` on the remote end of an SSH connection." , "" , "If no file is supplied, the bundle is read from standard input." , "" , "If given an email instead of a patch bundle, Darcs will look for the" , "bundle as a MIME attachment to that email. Currently this will fail" , "if the MIME boundary is rewritten, such as in Courier and Mail.app." , "" , "If the `--reply noreply@example.net` option is used, and the bundle is" , "attached to an email, Darcs will send a report (indicating success or" , "failure) to the sender of the bundle (the `To` field). The argument to" , "noreply is the address the report will appear to originate FROM." , "" , "The `--cc` option will cause the report to be CC'd to another address," , "for example `--cc reports@lists.example.net,admin@lists.example.net`." , "Using `--cc` without `--reply` is undefined." , "" , "If you want to use a command different from the default one for sending mail," , "you need to specify a command line with the `--sendmail-command` option." , "The command line can contain the format specifier `%t` for to" , "and you can add `%<` to the end of the command line if the command" , "expects the complete mail on standard input. For example, the command line" , "for msmtp looks like this:" , "" , " msmtp -t %<" , "" , "If gpg(1) is installed, you can use `--verify pubring.gpg` to reject" , "bundles that aren't signed by a key in `pubring.gpg`." , "" , "If `--test` is supplied and a test is defined (see `darcs setpref`), the" , "bundle will be rejected if the test fails after applying it. In that" , "case, the rejection email from `--reply` will include the test output." ] stdindefault :: a -> [String] -> IO [String] stdindefault _ [] = return ["-"] stdindefault _ x = return x apply :: DarcsCommand [DarcsFlag] apply = DarcsCommand { commandProgramName = "darcs" , commandName = "apply" , commandHelp = applyHelp ++ "\n" ++ applyHelp' , commandDescription = applyDescription , commandExtraArgs = 1 , commandExtraArgHelp = [""] , commandCommand = applyCmd StandardPatchApplier , commandPrereq = amInHashedRepository , commandCompleteArgs = fileArgs , commandArgdefaults = const stdindefault , commandAdvancedOptions = odesc applyAdvancedOpts , commandBasicOptions = odesc applyBasicOpts , commandDefaults = defaultFlags applyOpts , commandCheckOptions = ocheck applyOpts , commandParseOptions = onormalise applyOpts } where applyBasicOpts = O.verify ^ O.reorder ^ O.interactive ^ O.dryRunXml ^ O.matchSeveral ^ O.conflictsNo ^ O.externalMerge ^ O.runTest ^ O.leaveTestDir ^ O.repoDir ^ O.diffAlgorithm applyAdvancedOpts = O.reply ^ O.ccApply ^ O.happyForwarding ^ O.sendmail ^ O.useIndex ^ O.compress ^ O.setScriptsExecutable ^ O.umask ^ O.restrictPaths ^ O.changesReverse ^ O.pauseForGui applyOpts = applyBasicOpts `withStdOpts` applyAdvancedOpts applyCmd :: PatchApplier pa => pa -> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () applyCmd _ _ _ [""] = fail "Empty filename argument given to apply!" applyCmd patchApplier _ opts ["-"] = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ repoJob patchApplier opts $ \patchProxy repository -> do -- for darcs users who try out 'darcs apply' without any arguments putVerbose opts $ text "reading patch bundle from stdin..." bundle <- gzReadStdin applyCmdCommon patchApplier patchProxy opts bundle repository applyCmd patchApplier (_,o) opts [unfixed_patchesfile] = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ repoJob patchApplier opts $ \patchProxy repository -> do patchesfile <- fixUrl o unfixed_patchesfile bundle <- gzFetchFilePS (toFilePath patchesfile) Uncachable applyCmdCommon patchApplier patchProxy opts bundle repository applyCmd _ _ _ _ = impossible applyCmdCommon :: forall rt pa p wR wU . ( PatchApplier pa, RepoPatch p, ApplyState p ~ Tree , ApplierRepoTypeConstraint pa rt, IsRepoType rt ) => pa -> PatchProxy p -> [DarcsFlag] -> B.ByteString -> Repository rt p wR wU wR -> IO () applyCmdCommon patchApplier patchProxy opts bundle repository = do let from_whom = getFrom bundle us <- readRepo repository either_them <- getPatchBundle opts bundle Sealed them <- case either_them of Right t -> return t Left er -> do forwarded <- considerForwarding opts bundle if forwarded then exitSuccess else fail er common :> _ <- return $ findCommonWithThem us them -- all patches that are in "them" and not in "common" need to be available; check that let common_i = mapRL info $ patchSet2RL common them_i = mapRL info $ patchSet2RL them required = them_i \\ common_i -- FIXME quadratic? check :: RL (PatchInfoAnd rt p) wX wY -> [PatchInfo] -> IO () check (ps' :<: p) bad = case hopefullyM p of Nothing | info p `elem` required -> check ps' (info p : bad) _ -> check ps' bad check NilRL [] = return () check NilRL bad = fail . renderString $ vcat $ map displayPatchInfo bad ++ [ text "\nFATAL: Cannot apply this bundle. We are missing the above patches." ] check (patchSet2RL them) [] (us':\/:them') <- return $ findUncommon us them (hadConflicts, Sealed their_ps) <- if O.conflictsNo ? opts == Nothing -- skip conflicts then filterOutConflicts (reverseFL us') repository them' else return (False, Sealed them') when hadConflicts $ putStrLn "Skipping some patches which would cause conflicts." when (nullFL their_ps) $ do if hadConflicts then putStrLn ("All new patches of the bundle cause conflicts. " ++ "Nothing to do.") >> exitSuccess else putStrLn ("All these patches have already been applied. " ++ "Nothing to do.") >> when (reorder ? opts /= O.Reorder) exitSuccess let direction = if changesReverse ? opts then FirstReversed else First context = selectionContext direction "apply" (patchSelOpts opts) Nothing Nothing (to_be_applied :> _) <- runSelection their_ps context applyPatches patchApplier patchProxy "apply" opts from_whom repository us' to_be_applied -- see the default (False) for the option -- where fixed_opts = if Interactive `elem` opts -- then opts -- else All : opts getPatchBundle :: RepoPatch p => [DarcsFlag] -> B.ByteString -> IO (Either String (SealedPatchSet rt p Origin)) getPatchBundle opts fps = do let opt_verify = parseFlags O.verify opts mps <- verifyPS opt_verify $ readEmail fps mops <- verifyPS opt_verify fps case (mps, mops) of (Nothing, Nothing) -> return $ Left "Patch bundle not properly signed, or gpg failed." (Just bundle, Nothing) -> return $ scanBundle bundle (Nothing, Just bundle) -> return $ scanBundle bundle -- We use careful_scan_bundle only below because in either of the two -- above case we know the patch was signed, so it really shouldn't -- need stripping of CRs. (Just ps1, Just ps2) -> case careful_scan_bundle ps1 of Left _ -> return $ careful_scan_bundle ps2 Right x -> return $ Right x where careful_scan_bundle bundle = case scanBundle bundle of Left e -> case scanBundle $ stripCrPS bundle of Right x -> Right x _ -> Left e x -> x stripCrPS :: B.ByteString -> B.ByteString stripCrPS bundle = unlinesPS $ map stripline $ linesPS bundle stripline p | B.null p = p | BC.last p == '\r' = B.init p | otherwise = p applyHelp' :: String applyHelp' = "A patch bundle may introduce unresolved conflicts with existing\n" ++ "patches or with the working tree. By default, Darcs will add conflict\n" ++ "markers (see `darcs mark-conflicts`).\n" ++ "\n" ++ "The `--external-merge` option lets you resolve these conflicts\n" ++ "using an external merge tool. In the option, `%a` is replaced with\n" ++ "the common ancestor (merge base), `%1` with the first version, `%2`\n" ++ "with the second version, and `%o` with the path where your resolved\n" ++ "content should go. For example, to use the xxdiff visual merge tool\n" ++ "you'd specify: `--external-merge='xxdiff -m -O -M %o %1 %a %2'`\n" ++ "\n" ++ "The `--allow-conflicts` option will skip conflict marking; this is\n" ++ "useful when you want to treat a repository as just a bunch of patches,\n" ++ "such as using `darcs pull --union` to download of your co-workers\n" ++ "patches before going offline.\n" ++ "\n" ++ "This can mess up unrecorded changes in the working tree, forcing you\n" ++ "to resolve the conflict immediately. To simply reject bundles that\n" ++ "introduce unresolved conflicts, using the `--dont-allow-conflicts`\n" ++ "option. Making this the default in push-based workflows is strongly\n" ++ "recommended.\n" ++ "\n" ++ "Unlike most Darcs commands, `darcs apply` defaults to `--all`. Use the\n" ++ "`--interactive` option to pick which patches to apply from a bundle.\n" getFrom :: B.ByteString -> String getFrom bundle = readFrom $ linesPS bundle where readFrom [] = "" readFrom (x:xs) | B.take 5 x == fromStart = BC.unpack $ B.drop 5 x | otherwise = readFrom xs forwardingMessage :: B.ByteString forwardingMessage = BC.pack $ "The following patch was either unsigned, or signed by a non-allowed\n"++ "key, or there was a GPG failure.\n" considerForwarding :: [DarcsFlag] -> B.ByteString -> IO Bool considerForwarding opts bundle = case reply ? opts of Nothing -> return False Just from -> case break is_from (linesPS bundle) of (m1, f:m2) -> let m_lines = forwardingMessage:m1 ++ m2 m' = unlinesPS m_lines f' = BC.unpack (B.drop 5 f) in if from == f' || from == init f' then return False -- Refuse possible email loop. else do scmd <- getSendmailCmd opts if happyForwarding ? opts then resendEmail from scmd bundle else sendEmailDoc f' from "A forwarded darcs patch" cc scmd (Just (empty,empty)) (packedString m') return True _ -> return False -- Don't forward emails lacking headers! where cc = getCc opts is_from l = B.take 5 l == fromStart fromStart :: B.ByteString fromStart = BC.pack "From:" patchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions patchSelOpts flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = parseFlags O.matchSeveral flags , S.interactive = maybeIsInteractive flags , S.selectDeps = O.PromptDeps -- option not supported, use default , S.summary = O.NoSummary -- option not supported, use default , S.withContext = withContext ? flags } maybeIsInteractive :: [DarcsFlag] -> Bool maybeIsInteractive = maybe False id . parseFlags O.interactive darcs-2.14.5/src/Darcs/UI/Commands/Clone.hs0000644000000000000000000003262407346545000016374 0ustar0000000000000000-- Copyright (C) 2002-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Clone ( get , put , clone , makeRepoName , cloneToSSH ) where import Prelude () import Darcs.Prelude import System.Directory ( doesDirectoryExist, doesFileExist , setCurrentDirectory ) import System.Exit ( ExitCode(..) ) import Control.Exception ( catch, SomeException ) import Control.Monad ( when, unless ) import Data.Maybe ( listToMaybe ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts , nodefaults , commandStub , commandAlias , putInfo ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags( DarcsFlag( NewRepo , UpToPattern , UpToPatch , UpToHash , OnePattern , OnePatch , OneHash ) , matchAny, useCache, umask, remoteRepos , setDefault, quiet, usePacks , remoteDarcs, cloneKind, verbosity, setScriptsExecutable , withWorkingDir, patchIndexNo ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.Commands.Util ( getUniqueRepositoryName ) import Darcs.Repository ( cloneRepository ) import Darcs.Repository.Format ( identifyRepoFormat , RepoProperty ( HashedInventory , RebaseInProgress ) , formatHas ) import Darcs.Util.Lock ( withTempDir ) import Darcs.Util.Ssh ( getSSH, SSHCmd(SCP) ) import Darcs.Repository.Flags ( CloneKind(CompleteClone), SetDefault(NoSetDefault), ForgetParent(..) ) import Darcs.Patch.Bundle ( scanContextFile ) import Darcs.Patch.Dummy ( DummyPatch ) import Darcs.Patch.Set ( PatchSet, Origin ) import Darcs.Repository.Prefs ( showMotd ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Printer ( text, ($$) ) import Darcs.Util.Path ( toFilePath, toPath, ioAbsoluteOrRemote, AbsolutePath ) import Darcs.Util.Workaround ( getCurrentDirectory ) import Darcs.Util.URL ( isSshUrl ) import Darcs.Util.Exec ( exec, Redirect(..), ) cloneDescription :: String cloneDescription = "Make a copy of an existing repository." cloneHelp :: String cloneHelp = unlines [ "Clone creates a copy of a repository. The optional second" , "argument specifies a destination directory for the new copy;" , "if omitted, it is inferred from the source location." , "" , "By default Darcs will copy every patch from the original repository." , "If you expect the original repository to remain accessible, you can" , "use `--lazy` to avoid copying patches until they are needed ('copy on" , "demand'). This is particularly useful when copying a remote" , "repository with a long history that you don't care about." , "" , "When cloning locally, Darcs automatically uses hard linking where" , "possible. As well as saving time and space, this enables to move or" , "delete the original repository without affecting the copy." , "Hard linking requires that the copy be on the same filesystem as the" , "original repository, and that the filesystem support hard linking." , "This includes NTFS, HFS+ and all general-purpose Unix filesystems" , "(such as ext, UFS and ZFS). FAT does not support hard links." , "" , "When cloning from a remote location, Darcs will look for and attempt" , "to use packs created by `darcs optimize http` in the remote repository." , "Packs are single big files that can be downloaded faster than many" , "little files." , "" , "Darcs clone will not copy unrecorded changes to the source repository's" , "working tree." , "" , "You can copy a repository to a ssh url, in which case the new repository" , "will always be complete." , "" ] ++ cloneHelpTag ++ cloneHelpSSE clone :: DarcsCommand [DarcsFlag] clone = DarcsCommand { commandProgramName = "darcs" , commandName = "clone" , commandHelp = cloneHelp , commandDescription = cloneDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["", "[]"] , commandCommand = cloneCmd , commandPrereq = validContextFile , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc cloneAdvancedOpts , commandBasicOptions = odesc cloneBasicOpts , commandDefaults = defaultFlags cloneOpts , commandCheckOptions = ocheck cloneOpts , commandParseOptions = onormalise cloneOpts } where cloneBasicOpts = O.reponame ^ O.cloneKind ^ O.matchOneContext ^ O.setDefault ^ O.setScriptsExecutable ^ O.withWorkingDir cloneAdvancedOpts = O.usePacks ^ O.patchIndexNo ^ O.network cloneOpts = cloneBasicOpts `withStdOpts` cloneAdvancedOpts get :: DarcsCommand [DarcsFlag] get = commandAlias "get" Nothing clone putDescription :: String putDescription = "Deprecated command, replaced by clone." putHelp :: String putHelp = unlines [ "This command is deprecated." , "" , "To clone the current repository to a ssh destination," , "use the syntax `darcs clone . user@server:path` ." ] put :: DarcsCommand [DarcsFlag] put = commandStub "put" putHelp putDescription clone cloneCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () cloneCmd fps opts [inrepodir, outname] = cloneCmd fps (NewRepo outname:opts) [inrepodir] cloneCmd _ opts [inrepodir] = do debugMessage "Starting work on clone..." typed_repodir <- ioAbsoluteOrRemote inrepodir let repodir = toPath typed_repodir unless (quiet opts) $ showMotd repodir rfsource <- identifyRepoFormat repodir debugMessage $ "Found the format of "++repodir++"..." -- there's no fundamental reason for banning gets of repositories with -- rebase in progress, but it seems a bit dubious to actually copy the -- rebase state, and removing it is a bit of work since the current -- implementation just copies the inventory file when (formatHas RebaseInProgress rfsource) $ fail "Can't clone a repository with a rebase in progress" unless (formatHas HashedInventory rfsource) $ putInfo opts $ text "***********************************************************************" $$ text " _______ Sorry for the wait! The repository you are cloning is" $$ text " | | using the DEPRECATED 'old-fashioned' format. I'm doing a" $$ text " | O O | hashed copy instead, but this may take a while." $$ text " | ___ |" $$ text " | / \\ | We recommend that the maintainer upgrade the remote copy" $$ text " |_______| as well. See http://wiki.darcs.net/OF for more information." $$ text "" $$ text "***********************************************************************" case cloneToSSH opts of Just repo -> do withTempDir "clone" $ \_ -> do putInfo opts $ text "Creating local clone..." currentDir <- getCurrentDirectory mysimplename <- makeRepoName True [] repodir -- give correct name to local clone cloneRepository repodir mysimplename (verbosity ? opts) (useCache ? opts) CompleteClone (umask ? opts) (remoteDarcs opts) (setScriptsExecutable ? opts) (remoteRepos ? opts) (NoSetDefault True) (matchAny ? map convertUpToToOne opts) rfsource (withWorkingDir ? opts) (patchIndexNo ? opts) (usePacks ? opts) YesForgetParent setCurrentDirectory currentDir (scp, args) <- getSSH SCP putInfo opts $ text $ "Transferring clone using " ++ scp ++ "..." r <- exec scp (args ++ ["-r", mysimplename ++ "/", repo]) (AsIs,AsIs,AsIs) when (r /= ExitSuccess) $ fail $ "Problem during " ++ scp ++ " transfer." putInfo opts $ text "Cloning and transferring successful." Nothing -> do mysimplename <- makeRepoName True opts repodir cloneRepository repodir mysimplename (verbosity ? opts) (useCache ? opts) (cloneKind ? opts) (umask ? opts) (remoteDarcs opts) (setScriptsExecutable ? opts) (remoteRepos ? opts) (setDefault True opts) (matchAny ? map convertUpToToOne opts) rfsource (withWorkingDir ? opts) (patchIndexNo ? opts) (usePacks ? opts) NoForgetParent putInfo opts $ text "Finished cloning." cloneCmd _ _ _ = fail "You must provide 'clone' with either one or two arguments." cloneToSSH :: [DarcsFlag] -> Maybe String cloneToSSH fs = case O.reponame ? fs of Nothing -> Nothing Just r -> if isSshUrl r then Just r else Nothing makeRepoName :: Bool -> [DarcsFlag] -> FilePath -> IO String makeRepoName talkative fs d = case O.reponame ? fs of Just n -> do exists <- doesDirectoryExist n file_exists <- doesFileExist n if exists || file_exists then fail $ "Directory or file named '" ++ n ++ "' already exists." else return n Nothing -> case mkName d of "" -> getUniqueRepositoryName talkative "anonymous_repo" base@('/':_) -> getUniqueRepositoryName talkative base -- Absolute base -- Relative -> do cwd <- getCurrentDirectory getUniqueRepositoryName talkative (cwd ++ "/" ++ base) where mkName = dropWhile (== '.') . reverse . takeWhile (not . (`elem` "/:")) . dropWhile (== '/') . reverse cloneHelpTag :: String cloneHelpTag = unlines [ "It is often desirable to make a copy of a repository that excludes" , "some patches. For example, if releases are tagged then `darcs clone" , "--tag .` would make a copy of the repository as at the latest release." , "" , "An untagged repository state can still be identified unambiguously by" , "a context file, as generated by `darcs log --context`. Given the" , "name of such a file, the `--context` option will create a repository" , "that includes only the patches from that context. When a user reports" , "a bug in an unreleased version of your project, the recommended way to" , "find out exactly what version they were running is to have them" , "include a context file in the bug report." , "" , "You can also make a copy of an untagged state using the `--to-patch` or" , "`--to-match` options, which exclude patches *after* the first matching" , "patch. Because these options treat the set of patches as an ordered" , "sequence, you may get different results after reordering with `darcs" , "optimize reorder`." , "" ] cloneHelpSSE :: String cloneHelpSSE = unlines [ "The `--set-scripts-executable` option causes scripts to be made" , "executable in the working tree. A script is any file that starts" , "with a shebang (\"#!\")." ] validContextFile :: [DarcsFlag] -> IO (Either String ()) validContextFile opts = case getContext opts of Nothing -> return $ Right () Just ctxAbsolutePath -> do let ctxFilePath = toFilePath ctxAbsolutePath exists <- doesFileExist ctxFilePath if exists then do (ps :: PatchSet rt DummyPatch Origin wX) <- scanContextFile ctxFilePath (ps `seq` return $ Right ()) `catch` \(_ :: SomeException) -> return . Left $ "File " ++ ctxFilePath ++ " is not a valid context file" else return . Left $ "Context file " ++ ctxFilePath ++ " does not exist" -- TODO getContext choses arbitrarily the first --context flag -- should instead report an error when more than one is given -- | 'getContext' takes a list of flags and returns the context -- specified by @Context c@ in that list of flags, if any. -- This flag is present if darcs was invoked with @--context=FILE@ getContext :: [DarcsFlag] -> Maybe AbsolutePath getContext fs = listToMaybe [ f | O.Context f <- O.context ? fs ] -- The 'clone' command takes --to-patch and --to-match as arguments, -- but internally wants to handle them as if they were --patch and --match -- TODO: remove this when we get rid of directly looking at [DarcsFlag] -- for this command. convertUpToToOne :: DarcsFlag -> DarcsFlag convertUpToToOne (UpToPattern p) = OnePattern p convertUpToToOne (UpToPatch p) = OnePatch p convertUpToToOne (UpToHash p) = OneHash p convertUpToToOne f = f darcs-2.14.5/src/Darcs/UI/Commands/Convert.hs0000644000000000000000000014025507346545000016754 0ustar0000000000000000-- Copyright (C) 2002-2014 David Roundy, Petr Rockai, Owen Stephens -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE MagicHash, OverloadedStrings #-} module Darcs.UI.Commands.Convert ( convert ) where import Prelude ( lookup ) import Darcs.Prelude hiding ( readFile, lex ) import System.FilePath.Posix ( () ) import System.Directory ( doesDirectoryExist , doesFileExist , removeFile ) import System.IO ( stdin ) import Data.IORef ( newIORef, modifyIORef, readIORef ) import Data.Char ( isSpace ) import Control.Arrow ( second, (&&&) ) import Control.Monad ( when, unless, void, forM_ ) import Control.Monad.Trans ( liftIO ) import Control.Monad.State.Strict ( gets, modify ) import Control.Exception ( finally ) import Control.Applicative ( (<|>) ) import System.Time ( toClockTime ) import Data.Maybe ( catMaybes, fromJust, fromMaybe ) import qualified Data.IntMap as M import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as BLC import qualified Data.ByteString.Lazy.UTF8 as BLU import qualified Data.Attoparsec.ByteString.Char8 as A import Data.Attoparsec.ByteString.Char8( () ) import Darcs.Util.ByteString ( decodeLocale ) import qualified Darcs.Util.Tree as T import qualified Darcs.Util.Tree.Monad as TM import Darcs.Util.Tree.Monad hiding ( createDirectory, exists, rename ) import Darcs.Util.Tree.Hashed ( hashedTreeIO, darcsAddMissingHashes ) import Darcs.Util.Tree( Tree, treeHash, readBlob, TreeItem(..) , emptyTree, listImmediate, findTree ) import Darcs.Util.Path( anchorPath, appendPath, floatPath , parent, anchoredRoot , AnchoredPath(..), makeName , ioAbsoluteOrRemote, toPath, AbsolutePath ) import Darcs.Util.Hash( encodeBase16, sha256, Hash(..) ) import Darcs.Util.DateTime ( formatDateTime, fromClockTime, parseDateTime, startOfTime ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Exception ( clarifyErrors ) import Darcs.Util.Lock ( withNewDirectory ) import Darcs.Util.Prompt ( askUser ) import Darcs.Util.Printer ( text, ($$) ) import Darcs.Util.Printer.Color ( traceDoc ) import Darcs.Util.Workaround ( getCurrentDirectory ) import Darcs.Patch.Depends ( getUncovered ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, n2pia, info, hopefully ) import Darcs.Patch ( showPatch, ShowPatchFor(..), fromPrim, fromPrims , effect, RepoPatch, apply, listTouchedFiles, move ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Effect ( Effect ) import Darcs.Patch.Named ( patch2patchinfo , infopatch, adddeps, getdeps, patchcontents ) import Darcs.Patch.Named.Wrapped ( WrappedNamed(..) ) import qualified Darcs.Patch.Named.Wrapped as Wrapped ( getdeps ) import Darcs.Patch.Witnesses.Eq ( EqCheck(..), (=/\=) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..), bunchFL, mapFL_FL, concatFL, mapRL, nullFL, (+>+), (+<+) , reverseRL, reverseFL, foldFL_M ) import Darcs.Patch.Witnesses.Sealed ( FlippedSeal(..), Sealed(..), unFreeLeft , mapSeal, flipSeal, unsafeUnsealFlipped ) import Darcs.Patch.Info ( piRename, piTag, isTag, PatchInfo, patchinfo, piName, piLog, piDate, piAuthor, makePatchname ) import qualified Darcs.Patch.V1 as V1 ( RepoPatchV1 ) import qualified Darcs.Patch.V1.Prim as V1 ( Prim(..) ) import qualified Darcs.Patch.V2 as V2 ( RepoPatchV2 ) import qualified Darcs.Patch.V2.Prim as V2 ( Prim(..) ) import Darcs.Patch.V1.Commute ( publicUnravel ) import qualified Darcs.Patch.V1.Core as V1 ( RepoPatchV1(PP), isMerger ) import Darcs.Patch.V2.RepoPatch ( mergeUnravelled ) import Darcs.Patch.Prim ( sortCoalesceFL ) import Darcs.Patch.Prim.Class ( PrimOf ) import Darcs.Patch.RepoType ( RepoType(..), IsRepoType(..), RebaseType(..) ) import Darcs.Patch.Set ( PatchSet(..), Tagged(..), patchSet2RL, patchSet2FL ) import Darcs.Patch.Progress ( progressFL ) import Darcs.Repository.Flags ( UpdateWorking(..) , Compression(..) , DiffAlgorithm(PatienceDiff) ) import Darcs.Repository ( Repository, RepoJob(..), withRepositoryLocation , createRepository, invalidateIndex, repoLocation , createPristineDirectoryTree, repoCache , revertRepositoryChanges, finalizeRepositoryChanges , applyToWorking, repoLocation, repoCache , readRepo, readTentativeRepo, cleanRepository , createRepositoryV2, EmptyRepository(..) , withUMaskFlag ) import qualified Darcs.Repository as R( setScriptsExecutable ) import Darcs.Repository.InternalTypes ( coerceR ) import Darcs.Repository.State( readRecorded ) import Darcs.Repository.Cache ( HashedDir( HashedPristineDir ) ) import Darcs.Repository.Hashed ( tentativelyAddPatch_ , UpdatePristine(..) , readHashedPristineRoot , addToTentativeInventory ) import Darcs.Repository.HashedIO ( cleanHashdir ) import Darcs.Repository.Prefs( FileType(..), showMotd ) import Darcs.Repository.Format(identifyRepoFormat, formatHas, RepoProperty(Darcs2)) import Darcs.Util.External ( fetchFilePS, Cachable(Uncachable) ) import Darcs.Repository.Diff( treeDiff ) import Darcs.UI.External ( catchall ) import Darcs.UI.Flags ( verbosity, useCache, umask, withWorkingDir, patchIndexNo , DarcsFlag ( NewRepo ) , getRepourl, patchFormat, quiet ) import Darcs.UI.Commands ( DarcsCommand(..), amInRepository, nodefaults, putInfo , normalCommand, withStdOpts ) import Darcs.UI.Commands.Util.Tree ( treeHasDir, treeHasFile ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O type RepoPatchV1 = V1.RepoPatchV1 V1.Prim type RepoPatchV2 = V2.RepoPatchV2 V2.Prim convertDescription :: String convertDescription = "Convert repositories between various formats." convertHelp :: String convertHelp = unlines [ "This command converts a repository that uses the old patch semantics" , "`darcs-1` to a new repository with current `darcs-2` semantics." , "" , convertHelp' ] -- | This part of the help is split out because it is used twice: in -- the help string, and in the prompt for confirmation. convertHelp' :: String convertHelp' = unlines [ "WARNING: the repository produced by this command is not understood by" , "Darcs 1.x, and patches cannot be exchanged between repositories in" , "darcs-1 and darcs-2 formats." , "" , "Furthermore, repositories created by different invocations of" , "this command SHOULD NOT exchange patches." ] convertExportHelp :: String convertExportHelp = unlines [ "This command enables you to export darcs repositories into git." , "" , "For a one-time export you can use the recipe:" , "" , " $ cd repo" , " $ git init ../mirror" , " $ darcs convert export | (cd ../mirror && git fast-import)" , "" , "For incremental export using marksfiles:" , "" , " $ cd repo" , " $ git init ../mirror" , " $ touch ../mirror/git.marks" , " $ darcs convert export --read-marks darcs.marks --write-marks darcs.marks" , " | (cd ../mirror && git fast-import --import-marks=git.marks --export-marks=git.marks)" , "" , "In the case of incremental export, be careful to never amend, delete or" , "reorder patches in the source darcs repository." , "" , "Also, be aware that exporting a darcs repo to git will not be exactly" , "faithful in terms of history if the darcs repository contains conflicts." , "" , "Limitations:" , "" , "* Empty directories are not supported by the fast-export protocol." , "* Unicode filenames are currently not correctly handled." , " See http://bugs.darcs.net/issue2359 ." ] convertImportHelp :: String convertImportHelp = unlines [ "This command imports git repositories into new darcs repositories." , "Further options are accepted (see `darcs help init`)." , "" , "To convert a git repo to a new darcs one you may run:" , " $ (cd gitrepo && git fast-export --all -M) | darcs convert import darcsmirror" , "" , "WARNING: git repositories with branches will produce weird results," , " use at your own risks." , "" , "Incremental import with marksfiles is currently not supported." ] convert :: DarcsCommand [DarcsFlag] convert = SuperCommand { commandProgramName = "darcs" , commandName = "convert" , commandHelp = "" , commandDescription = convertDescription , commandPrereq = amInRepository , commandSubCommands = [ normalCommand convertDarcs2 , normalCommand convertExport , normalCommand convertImport ] } convertDarcs2 :: DarcsCommand [DarcsFlag] convertDarcs2 = DarcsCommand { commandProgramName = "darcs" , commandName = "darcs-2" , commandHelp = convertHelp , commandDescription = "Convert darcs-1 repository to the darcs-2 patch format" , commandExtraArgs = -1 , commandExtraArgHelp = ["", "[]"] , commandCommand = toDarcs2 , commandPrereq = \_ -> return $ Right () , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc convertDarcs2AdvancedOpts , commandBasicOptions = odesc convertDarcs2BasicOpts , commandDefaults = defaultFlags (convertDarcs2Opts ^ convertDarcs2SilentOpts) , commandCheckOptions = ocheck convertDarcs2Opts , commandParseOptions = onormalise convertDarcs2Opts } where convertDarcs2BasicOpts = O.reponame ^ O.setScriptsExecutable ^ O.withWorkingDir convertDarcs2AdvancedOpts = O.network ^ O.patchIndexNo convertDarcs2Opts = convertDarcs2BasicOpts `withStdOpts` convertDarcs2AdvancedOpts convertDarcs2SilentOpts = O.patchFormat convertExport :: DarcsCommand [DarcsFlag] convertExport = DarcsCommand { commandProgramName = "darcs" , commandName = "export" , commandHelp = convertExportHelp , commandDescription = "Export a darcs repository to a git-fast-import stream" , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = fastExport , commandPrereq = amInRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc convertExportAdvancedOpts , commandBasicOptions = odesc convertExportBasicOpts , commandDefaults = defaultFlags convertExportOpts , commandCheckOptions = ocheck convertExportOpts , commandParseOptions = onormalise convertExportOpts } where convertExportBasicOpts = O.reponame ^ O.marks convertExportAdvancedOpts = O.network convertExportOpts = convertExportBasicOpts `withStdOpts` convertExportAdvancedOpts convertImport :: DarcsCommand [DarcsFlag] convertImport = DarcsCommand { commandProgramName = "darcs" , commandName = "import" , commandHelp = convertImportHelp , commandDescription = "Import from a git-fast-export stream into darcs" , commandExtraArgs = -1 , commandExtraArgHelp = ["[]"] , commandCommand = fastImport , commandPrereq = \_ -> return $ Right () , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc convertImportAdvancedOpts , commandBasicOptions = odesc convertImportBasicOpts , commandDefaults = defaultFlags convertImportOpts , commandCheckOptions = ocheck convertImportOpts , commandParseOptions = onormalise convertImportOpts } where convertImportBasicOpts = O.reponame ^ O.setScriptsExecutable ^ O.patchFormat ^ O.withWorkingDir convertImportAdvancedOpts = O.patchIndexNo convertImportOpts = convertImportBasicOpts `withStdOpts` convertImportAdvancedOpts toDarcs2 :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () toDarcs2 _ opts' args = do (inrepodir, opts) <- case args of [arg1, arg2] -> return (arg1, NewRepo arg2:opts') [arg1] -> return (arg1, opts') _ -> fail "You must provide either one or two arguments." typed_repodir <- ioAbsoluteOrRemote inrepodir let repodir = toPath typed_repodir format <- identifyRepoFormat repodir when (formatHas Darcs2 format) $ fail "Repository is already in darcs 2 format." putStrLn convertHelp' let vow = "I understand the consequences of my action" putStrLn "Please confirm that you have read and understood the above" vow' <- askUser ("by typing `" ++ vow ++ "': ") when (vow' /= vow) $ fail "User didn't understand the consequences." unless (quiet opts) $ showMotd repodir mysimplename <- makeRepoName opts repodir withUMaskFlag (umask ? opts) $ withNewDirectory mysimplename $ do repo <- createRepositoryV2 (withWorkingDir ? opts) (patchIndexNo ? opts) (O.useCache ? opts) revertRepositoryChanges repo NoUpdateWorking withRepositoryLocation (useCache ? opts) repodir $ V1Job $ \other -> do theirstuff <- readRepo other let patches = mapFL_FL (convertNamed . hopefully) $ patchSet2FL theirstuff outOfOrderTags = catMaybes $ mapRL oot $ patchSet2RL theirstuff where oot t = if isTag (info t) && info t `notElem` inOrderTags theirstuff then Just (info t, Wrapped.getdeps $ hopefully t) else Nothing fixDep p = case lookup p outOfOrderTags of Just d -> p : concatMap fixDep d Nothing -> [p] primV1toV2 = V2.Prim . V1.unPrim convertOne :: RepoPatchV1 wX wY -> FL RepoPatchV2 wX wY convertOne x | V1.isMerger x = let ex = mapFL_FL primV1toV2 (effect x) in case mergeUnravelled $ map (mapSeal (mapFL_FL primV1toV2)) $ publicUnravel x of Just (FlippedSeal y) -> case effect y =/\= ex of IsEq -> y :>: NilFL NotEq -> traceDoc (text "lossy conversion:" $$ showPatch ForDisplay x) fromPrims ex Nothing -> traceDoc (text "lossy conversion of complicated conflict:" $$ showPatch ForDisplay x) fromPrims ex convertOne (V1.PP x) = fromPrim (primV1toV2 x) :>: NilFL convertOne _ = impossible convertFL :: FL RepoPatchV1 wX wY -> FL RepoPatchV2 wX wY convertFL = concatFL . mapFL_FL convertOne convertNamed :: WrappedNamed ('RepoType 'NoRebase) RepoPatchV1 wX wY -> PatchInfoAnd ('RepoType 'NoRebase) RepoPatchV2 wX wY convertNamed (NormalP n) = n2pia $ NormalP $ adddeps (infopatch (convertInfo $ patch2patchinfo n) $ convertFL $ patchcontents n) (map convertInfo $ concatMap fixDep $ getdeps n) convertInfo n | n `elem` inOrderTags theirstuff = n | otherwise = maybe n (\t -> piRename n ("old tag: "++t)) $ piTag n -- Note: we use bunchFL so we can commit every 100 patches _ <- applyAll opts repo $ bunchFL 100 $ progressFL "Converting patch" patches when (parseFlags O.setScriptsExecutable opts == O.YesSetScriptsExecutable) R.setScriptsExecutable -- Copy over the prefs file let prefsRelPath = darcsdir "prefs" "prefs" (fetchFilePS (repodir prefsRelPath) Uncachable >>= B.writeFile prefsRelPath) `catchall` return () putInfo opts $ text "Finished converting." where applyOne :: (RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> W2 (Repository rt p wR) wX -> PatchInfoAnd rt p wX wY -> IO (W2 (Repository rt p wR) wY) applyOne opts (W2 r) x = do r' <- tentativelyAddPatch_ (updatePristine opts) r GzipCompression (verbosity ? opts) (updateWorking opts) x r'' <- withTryAgainMsg $ applyToWorking r' (verbosity ? opts) (effect x) invalidateIndex r'' return (W2 r'') applySome opts (W3 r) xs = do r' <- unW2 <$> foldFL_M (applyOne opts) (W2 r) xs -- commit after applying a bunch of patches finalizeRepositoryChanges r' (updateWorking opts) GzipCompression revertRepositoryChanges r' (updateWorking opts) -- finalizeRepositoryChanges and revertRepositoryChanges -- do not (yet?) return a repo with properly coerced witnesses. -- We should have -- -- > finalizeRepositoryChanges :: ... wR wU wT -> ... wT wU wT -- -- and -- -- > revertRepositoryChanges :: ... wR wU wT -> ... wR wU wR -- -- This is why we must coerce here: return (W3 (coerceR r')) applyAll :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> Repository rt p wX wX wX -> FL (FL (PatchInfoAnd rt p)) wX wY -> IO (Repository rt p wY wY wY) applyAll opts r xss = unW3 <$> foldFL_M (applySome opts) (W3 r) xss updatePristine :: [DarcsFlag] -> UpdatePristine updatePristine opts = case withWorkingDir ? opts of O.WithWorkingDir -> UpdatePristine -- this should not be necessary but currently is, because -- some commands (e.g. send) cannot cope with a missing pristine -- even if the repo is marked as having no working tree O.NoWorkingDir -> {- DontUpdatePristineNorRevert -}UpdatePristine updateWorking :: [DarcsFlag] -> UpdateWorking updateWorking opts = case withWorkingDir ? opts of O.WithWorkingDir -> YesUpdateWorking O.NoWorkingDir -> NoUpdateWorking withTryAgainMsg :: IO a -> IO a withTryAgainMsg x = x `clarifyErrors` unlines [ "An error occurred while applying patches to the working tree." , "You may have more luck if you supply --no-working-dir." ] -- | Need this to make 'foldFL_M' work with a function that changes -- the last two (identical) witnesses at the same time. newtype W2 r wX = W2 {unW2 :: r wX wX} -- | Similarly for when the function changes all three witnesses. newtype W3 r wX = W3 {unW3 :: r wX wX wX} makeRepoName :: [DarcsFlag] -> FilePath -> IO String makeRepoName (NewRepo n:_) _ = do exists <- doesDirectoryExist n file_exists <- doesFileExist n if exists || file_exists then fail $ "Directory or file named '" ++ n ++ "' already exists." else return n makeRepoName (_:as) d = makeRepoName as d makeRepoName [] d = case dropWhile (=='.') $ reverse $ takeWhile (\c -> c /= '/' && c /= ':') $ dropWhile (=='/') $ reverse d of "" -> modifyRepoName "anonymous_repo" base -> modifyRepoName base modifyRepoName :: String -> IO String modifyRepoName name = if head name == '/' then mrn name (-1) else do cwd <- getCurrentDirectory mrn (cwd ++ "/" ++ name) (-1) where mrn :: String -> Int -> IO String mrn n i = do exists <- doesDirectoryExist thename file_exists <- doesFileExist thename if not exists && not file_exists then do when (i /= -1) $ putStrLn $ "Directory '"++ n ++ "' already exists, creating repository as '"++ thename ++"'" return thename else mrn n $ i+1 where thename = if i == -1 then n else n++"_"++show i fastExport :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () fastExport _ opts _ = do let repodir = fromMaybe "." $ getRepourl opts marks <- case parseFlags O.readMarks opts of Nothing -> return emptyMarks Just f -> readMarks f newMarks <- withRepositoryLocation (useCache ? opts) repodir $ RepoJob $ \repo -> fastExport' repo marks case parseFlags O.writeMarks opts of Nothing -> return () Just f -> writeMarks f newMarks fastExport' :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p r u r -> Marks -> IO Marks fastExport' repo marks = do putStrLn "progress (reading repository)" patchset <- readRepo repo marksref <- newIORef marks let patches = patchSet2FL patchset tags = inOrderTags patchset mark :: (PatchInfoAnd rt p) x y -> Int -> TreeIO () mark p n = liftIO $ do putStrLn $ "mark :" ++ show n modifyIORef marksref $ \m -> addMark m n (patchHash p) -- apply a single patch to build the working tree of the last exported version checkOne :: (RepoPatch p, ApplyState p ~ Tree) => Int -> (PatchInfoAnd rt p) x y -> TreeIO () checkOne n p = do apply p unless (inOrderTag tags p || (getMark marks n == Just (patchHash p))) $ fail $ "FATAL: Marks do not correspond: expected " ++ show (getMark marks n) ++ ", got " ++ BC.unpack (patchHash p) -- build the working tree of the last version exported by convert --export check :: (RepoPatch p, ApplyState p ~ Tree) => Int -> FL (PatchInfoAnd rt p) x y -> TreeIO (Int, FlippedSeal( FL (PatchInfoAnd rt p)) y) check _ NilFL = return (1, flipSeal NilFL) check n allps@(p:>:ps) | n <= lastMark marks = checkOne n p >> check (next tags n p) ps | n > lastMark marks = return (n, flipSeal allps) | lastMark marks == 0 = return (1, flipSeal allps) | otherwise = undefined ((n, patches'), tree') <- hashedTreeIO (check 1 patches) emptyTree $ darcsdir "pristine.hashed" let patches'' = unsafeUnsealFlipped patches' void $ hashedTreeIO (dumpPatches tags mark n patches'') tree' $ darcsdir "pristine.hashed" readIORef marksref `finally` do putStrLn "progress (cleaning up)" current <- readHashedPristineRoot repo cleanHashdir (repoCache repo) HashedPristineDir $ catMaybes [current] putStrLn "progress done" dumpPatches :: (RepoPatch p, ApplyState p ~ Tree) => [PatchInfo] -> (forall p0 x0 y0 . (PatchInfoAnd rt p0) x0 y0 -> Int -> TreeIO ()) -> Int -> FL (PatchInfoAnd rt p) x y -> TreeIO () dumpPatches _ _ _ NilFL = liftIO $ putStrLn "progress (patches converted)" dumpPatches tags mark n (p:>:ps) = do apply p if inOrderTag tags p && n > 0 then dumpTag p n else do dumpPatch mark p n dumpFiles $ map floatPath $ listTouchedFiles p dumpPatches tags mark (next tags n p) ps dumpTag :: (PatchInfoAnd rt p) x y -> Int -> TreeIO () dumpTag p n = dumpBits [ BLU.fromString $ "progress TAG " ++ cleanTagName p , BLU.fromString $ "tag " ++ cleanTagName p -- FIXME is this valid? , BLU.fromString $ "from :" ++ show (n - 1) , BLU.fromString $ unwords ["tagger", patchAuthor p, patchDate p] -- -3 == (-4 for "TAG " and +1 for newline) , BLU.fromString $ "data " ++ show (BL.length (patchMessage p) - 3) , BL.drop 4 $ patchMessage p ] where -- FIXME forbidden characters and subsequences in tags: -- https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html cleanTagName = map cleanup . drop 4 . piName . info where cleanup x | x `elem` bad = '_' | otherwise = x bad :: String bad = " ~^:" dumpFiles :: [AnchoredPath] -> TreeIO () dumpFiles files = forM_ files $ \file -> do let quotedPath = quotePath $ anchorPath "" file isfile <- fileExists file isdir <- directoryExists file when isfile $ do bits <- readFile file dumpBits [ BLU.fromString $ "M 100644 inline " ++ quotedPath , BLU.fromString $ "data " ++ show (BL.length bits) , bits ] when isdir $ do -- Always delete directory before dumping its contents. This fixes -- a corner case when a same patch moves dir1 to dir2, and creates -- another directory dir1. -- As we always dump its contents anyway this is not more costly. liftIO $ putStrLn $ "D " ++ anchorPath "" file tt <- gets tree -- ick let subs = [ file `appendPath` n | (n, _) <- listImmediate $ fromJust $ findTree tt file ] dumpFiles subs when (not isfile && not isdir) $ liftIO $ putStrLn $ "D " ++ anchorPath "" file where -- |quotePath escapes and quotes paths containing newlines, double-quotes -- or backslashes. quotePath :: FilePath -> String quotePath path = case foldr escapeChars ("", False) path of (_, False) -> path (path', True) -> quote path' quote str = "\"" ++ str ++ "\"" escapeChars c (processed, haveEscaped) = case escapeChar c of (escaped, didEscape) -> (escaped ++ processed, didEscape || haveEscaped) escapeChar c = case c of '\n' -> ("\\n", True) '\r' -> ("\\r", True) '"' -> ("\\\"", True) '\\' -> ("\\\\", True) _ -> ([c], False) dumpPatch :: (forall p0 x0 y0 . (PatchInfoAnd rt p0) x0 y0 -> Int -> TreeIO ()) -> (PatchInfoAnd rt p) x y -> Int -> TreeIO () dumpPatch mark p n = do dumpBits [ BLU.fromString $ "progress " ++ show n ++ ": " ++ piName (info p) , "commit refs/heads/master" ] mark p n dumpBits [ BLU.fromString $ "committer " ++ patchAuthor p ++ " " ++ patchDate p , BLU.fromString $ "data " ++ show (BL.length $ patchMessage p) , patchMessage p ] when (n > 1) $ dumpBits [ BLU.fromString $ "from :" ++ show (n - 1) ] dumpBits :: [BL.ByteString] -> TreeIO () dumpBits = liftIO . BLC.putStrLn . BL.intercalate "\n" -- patchAuthor attempts to fixup malformed author strings -- into format: "Name " -- e.g. -- -> john -- john@home -> john -- john -> john -- john john -- -> john patchAuthor :: (PatchInfoAnd rt p) x y -> String patchAuthor p | null author = unknownEmail "unknown" | otherwise = case span (/='<') author of -- No name, but have email (nothing spanned) ("", email) -> case span (/='@') (tail email) of -- Not a real email address (no @). (n, "") -> case span (/='>') n of (name, _) -> unknownEmail name -- A "real" email address. (user, rest) -> case span (/= '>') (tail rest) of (dom, _) -> mkAuthor user $ emailPad (user ++ "@" ++ dom) -- No email (everything spanned) (_, "") -> case span (/='@') author of (n, "") -> unknownEmail n (name, _) -> mkAuthor name $ emailPad author -- Name and email (n, rest) -> case span (/='>') $ tail rest of (email, _) -> n ++ emailPad email where author = dropWhile isSpace $ piAuthor (info p) unknownEmail = flip mkAuthor "" emailPad email = "<" ++ email ++ ">" mkAuthor name email = name ++ " " ++ email patchDate :: (PatchInfoAnd rt p) x y -> String patchDate = formatDateTime "%s +0000" . fromClockTime . toClockTime . piDate . info patchMessage :: (PatchInfoAnd rt p) x y -> BLU.ByteString patchMessage p = BL.concat [ BLU.fromString (piName $ info p) , case unlines . piLog $ info p of "" -> BL.empty plog -> BLU.fromString ("\n\n" ++ plog) ] type Marked = Maybe Int type Branch = B.ByteString type AuthorInfo = B.ByteString type Message = B.ByteString type Content = B.ByteString type Tag = B.ByteString data RefId = MarkId Int | HashId B.ByteString | Inline deriving Show -- Newish (> 1.7.6.1) Git either quotes filenames or has two -- non-special-char-containing paths. Older git doesn't do any quoting, so -- we'll have to manually try and find the correct paths, when we use the -- paths. data CopyRenameNames = Quoted B.ByteString B.ByteString | Unquoted B.ByteString deriving Show data Object = Blob (Maybe Int) Content | Reset Branch (Maybe RefId) | Commit Branch Marked AuthorInfo Message | Tag Tag Int AuthorInfo Message | Modify (Either Int Content) B.ByteString -- (mark or content), filename | Gitlink B.ByteString | Copy CopyRenameNames | Rename CopyRenameNames | Delete B.ByteString -- filename | From Int | Merge Int | Progress B.ByteString | End deriving Show type Ancestors = (Marked, [Int]) data State p where Toplevel :: Marked -> Branch -> State p InCommit :: Marked -> Ancestors -> Branch -> Tree IO -> RL (PrimOf p) cX cY -> PatchInfo -> State p Done :: State p instance Show (State p) where show Toplevel {} = "Toplevel" show InCommit {} = "InCommit" show Done = "Done" fastImport :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () fastImport _ opts [outrepo] = withUMaskFlag (umask ? opts) $ withNewDirectory outrepo $ do EmptyRepository repo <- createRepository (patchFormat ? opts) (withWorkingDir ? opts) (patchIndexNo ? opts) (useCache ? opts) -- TODO implement --dry-run, which would be read-only? marks <- fastImport' repo emptyMarks createPristineDirectoryTree repo "." (withWorkingDir ? opts) return marks fastImport _ _ _ = fail "I need exactly one output repository." fastImport' :: forall rt p r u . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p r u r -> Marks -> IO () fastImport' repo marks = do pristine <- readRecorded repo marksref <- newIORef marks let initial = Toplevel Nothing $ BC.pack "refs/branches/master" go :: State p -> B.ByteString -> TreeIO () go state rest = do (rest', item) <- parseObject rest state' <- process state item case state' of Done -> return () _ -> go state' rest' -- sort marks into buckets, since there can be a *lot* of them markpath :: Int -> AnchoredPath markpath n = floatPath (darcsdir "marks") `appendPath` (makeName $ show (n `div` 1000)) `appendPath` (makeName $ show (n `mod` 1000)) makeinfo author message tag = do let (name, log) = case BC.unpack message of "" -> ("Unnamed patch", []) msg -> (head &&& tail) . lines $ msg (author'', date'') = span (/='>') $ BC.unpack author date' = dropWhile (`notElem` ("0123456789" :: String)) date'' author' = author'' ++ ">" date = formatDateTime "%Y%m%d%H%M%S" $ fromMaybe startOfTime (parseDateTime "%s %z" date') liftIO $ patchinfo date (if tag then "TAG " ++ name else name) author' log addtag author msg = do info_ <- makeinfo author msg True gotany <- liftIO $ doesFileExist $ darcsdir "tentative_hashed_pristine" deps <- if gotany then liftIO $ getUncovered `fmap` readTentativeRepo repo (repoLocation repo) else return [] let ident = NilFL :: FL RepoPatchV2 cX cX patch = NormalP (adddeps (infopatch info_ ident) deps) void $ liftIO $ addToTentativeInventory (repoCache repo) GzipCompression (n2pia patch) -- processing items updateHashes = do let nodarcs = \(AnchoredPath (x:_)) _ -> x /= makeName darcsdir hashblobs (File blob@(T.Blob con NoHash)) = do hash <- sha256 `fmap` readBlob blob return $ File (T.Blob con hash) hashblobs x = return x tree' <- liftIO . T.partiallyUpdateTree hashblobs nodarcs =<< gets tree modify $ \s -> s { tree = tree' } return $ T.filter nodarcs tree' -- Since git doesn't track directores it implicitly deletes -- them when they become empty. We should therefore remove any -- directories that become empty (except the repo-root -- directory!) deleteEmptyParents fp = do let directParent = parent fp unless (directParent == anchoredRoot) $ do parentTree <- flip findTree directParent <$> gets tree case (null . listImmediate) <$> parentTree of Just True -> do TM.unlink directParent deleteEmptyParents directParent -- Either missing (not possible) or non-empty. _ -> return () -- generate a Hunk primitive patch from diffing diffCurrent :: State p -> TreeIO (State p) diffCurrent (InCommit mark ancestors branch start ps info_) = do current <- updateHashes Sealed diff <- unFreeLeft `fmap` liftIO (treeDiff PatienceDiff (const TextFile) start current) let newps = ps +<+ reverseFL diff return $ InCommit mark ancestors branch current newps info_ diffCurrent _ = error "This is never valid outside of a commit." process :: State p -> Object -> TreeIO (State p) process s (Progress p) = do liftIO $ putStrLn ("progress " ++ decodeLocale p) return s process (Toplevel _ _) End = do tree' <- (liftIO . darcsAddMissingHashes) =<< updateHashes modify $ \s -> s { tree = tree' } -- lets dump the right tree, without _darcs let root = encodeBase16 $ treeHash tree' liftIO $ do putStrLn "\\o/ It seems we survived. Enjoy your new repo." B.writeFile (darcsdir "tentative_pristine") $ BC.concat [BC.pack "pristine:", root] return Done process (Toplevel n b) (Tag tag what author msg) = do if Just what == n then addtag author msg else liftIO $ putStrLn $ "WARNING: Ignoring out-of-order tag " ++ decodeLocale tag return (Toplevel n b) process (Toplevel n _) (Reset branch from) = do case from of (Just (MarkId k)) | Just k == n -> addtag (BC.pack "Anonymous Tagger <> 0 +0000") branch _ -> liftIO $ putStrLn $ "WARNING: Ignoring out-of-order tag " ++ BC.unpack branch return $ Toplevel n branch process (Toplevel n b) (Blob (Just m) bits) = do TM.writeFile (markpath m) (BLC.fromChunks [bits]) return $ Toplevel n b process x (Gitlink link) = do liftIO $ putStrLn $ "WARNING: Ignoring gitlink " ++ BC.unpack link return x process (Toplevel previous pbranch) (Commit branch mark author message) = do when (pbranch /= branch) $ do liftIO $ putStrLn ("Tagging branch: " ++ BC.unpack pbranch) addtag author pbranch info_ <- makeinfo author message False startstate <- updateHashes return $ InCommit mark (previous, []) branch startstate NilRL info_ process s@InCommit {} (Modify (Left m) path) = do TM.copy (markpath m) (floatPath $ BC.unpack path) diffCurrent s process s@InCommit {} (Modify (Right bits) path) = do TM.writeFile (floatPath $ BC.unpack path) (BLC.fromChunks [bits]) diffCurrent s process s@InCommit {} (Delete path) = do let floatedPath = floatPath $ BC.unpack path TM.unlink floatedPath deleteEmptyParents floatedPath diffCurrent s process (InCommit mark (prev, current) branch start ps info_) (From from) = return $ InCommit mark (prev, from:current) branch start ps info_ process (InCommit mark (prev, current) branch start ps info_) (Merge from) = return $ InCommit mark (prev, from:current) branch start ps info_ process s@InCommit {} (Copy names) = do (from, to) <- extractNames names TM.copy (floatPath $ BC.unpack from) (floatPath $ BC.unpack to) -- We can't tell Darcs that a file has been copied, so it'll -- show as an addfile. diffCurrent s process s@(InCommit mark ancestors branch start _ info_) (Rename names) = do (from, to) <- extractNames names let uFrom = BC.unpack from uTo = BC.unpack to parentDir = parent $ floatPath uTo targetDirExists <- liftIO $ treeHasDir start uTo targetFileExists <- liftIO $ treeHasFile start uTo parentDirExists <- liftIO $ treeHasDir start (anchorPath "" parentDir) -- If the target exists, remove it; if it doesn't, add all -- its parent directories. if targetDirExists || targetFileExists then TM.unlink $ floatPath uTo else unless parentDirExists $ TM.createDirectory parentDir (InCommit _ _ _ _ newPs _) <- diffCurrent s TM.rename (floatPath uFrom) (floatPath uTo) let ps' = newPs :<: move uFrom uTo current <- updateHashes -- ensure empty dirs get deleted deleteEmptyParents (floatPath uFrom) -- run diffCurrent to add the dir deletions prims diffCurrent (InCommit mark ancestors branch current ps' info_) -- When we leave the commit, create a patch for the cumulated -- prims. process (InCommit mark ancestors branch _ ps info_) x = do case ancestors of (_, []) -> return () -- OK, previous commit is the ancestor (Just n, list) | n `elem` list -> return () -- OK, we base off one of the ancestors | otherwise -> liftIO $ putStrLn $ "WARNING: Linearising non-linear ancestry:" ++ " currently at " ++ show n ++ ", ancestors " ++ show list (Nothing, list) -> liftIO $ putStrLn $ "WARNING: Linearising non-linear ancestry " ++ show list {- current <- updateHashes -} -- why not? (prims :: FL p cX cY) <- return $ fromPrims $ sortCoalesceFL $ reverseRL ps let patch = NormalP (infopatch info_ ((NilFL :: FL p cX cX) +>+ prims)) void $ liftIO $ addToTentativeInventory (repoCache repo) GzipCompression (n2pia patch) case mark of Nothing -> return () Just n -> case getMark marks n of Nothing -> liftIO $ modifyIORef marksref $ \m -> addMark m n (patchHash $ n2pia patch) Just n' -> fail $ "FATAL: Mark already exists: " ++ BC.unpack n' process (Toplevel mark branch) x process state obj = do liftIO $ print obj fail $ "Unexpected object in state " ++ show state extractNames :: CopyRenameNames -> TreeIO (BC.ByteString, BC.ByteString) extractNames names = case names of Quoted f t -> return (f, t) Unquoted uqNames -> do let spaceIndices = BC.elemIndices ' ' uqNames splitStr = second (BC.drop 1) . flip BC.splitAt uqNames -- Reverse the components, so we find the longest -- prefix existing name. spaceComponents = reverse $ map splitStr spaceIndices componentCount = length spaceComponents if componentCount == 1 then return $ head spaceComponents else do let dieMessage = unwords [ "Couldn't determine move/rename" , "source/destination filenames, with the" , "data produced by this (old) version of" , "git, since it uses unquoted, but" , "special-character-containing paths." ] floatUnpack = floatPath . BC.unpack lPathExists (l,_) = TM.fileExists $ floatUnpack l finder [] = error dieMessage finder (x : rest) = do xExists <- lPathExists x if xExists then return x else finder rest finder spaceComponents void $ hashedTreeIO (go initial B.empty) pristine $ darcsdir "pristine.hashed" finalizeRepositoryChanges repo YesUpdateWorking GzipCompression cleanRepository repo parseObject :: BC.ByteString -> TreeIO ( BC.ByteString, Object ) parseObject = next' mbObject where mbObject = A.parse p_maybeObject p_maybeObject = Just `fmap` p_object <|> (A.endOfInput >> return Nothing) lex p = p >>= \x -> A.skipSpace >> return x lexString s = A.string (BC.pack s) >> A.skipSpace line = lex $ A.takeWhile (/='\n') optional p = Just `fmap` p <|> return Nothing p_object = p_blob <|> p_reset <|> p_commit <|> p_tag <|> p_modify <|> p_rename <|> p_copy <|> p_from <|> p_merge <|> p_delete <|> (lexString "progress" >> Progress `fmap` line) p_author name = lexString name >> line p_reset = do lexString "reset" branch <- line refid <- optional $ lexString "from" >> p_refid return $ Reset branch refid p_commit = do lexString "commit" branch <- line mark <- optional p_mark _ <- optional $ p_author "author" committer <- p_author "committer" message <- p_data return $ Commit branch mark committer message p_tag = do _ <- lexString "tag" tag <- line lexString "from" mark <- p_marked author <- p_author "tagger" message <- p_data return $ Tag tag mark author message p_blob = do lexString "blob" mark <- optional p_mark Blob mark `fmap` p_data "p_blob" p_mark = do lexString "mark" p_marked "p_mark" p_refid = MarkId `fmap` p_marked <|> (lexString "inline" >> return Inline) <|> HashId `fmap` p_hash p_data = do lexString "data" len <- A.decimal _ <- A.char '\n' lex $ A.take len "p_data" p_marked = lex $ A.char ':' >> A.decimal p_hash = lex $ A.takeWhile1 (A.inClass "0123456789abcdefABCDEF") p_from = lexString "from" >> From `fmap` p_marked p_merge = lexString "merge" >> Merge `fmap` p_marked p_delete = lexString "D" >> Delete `fmap` p_maybeQuotedName p_rename = do lexString "R" names <- p_maybeQuotedCopyRenameNames return $ Rename names p_copy = do lexString "C" names <- p_maybeQuotedCopyRenameNames return $ Copy names p_modify = do lexString "M" mode <- lex $ A.takeWhile (A.inClass "01234567890") mark <- p_refid path <- p_maybeQuotedName case mark of HashId hash | mode == BC.pack "160000" -> return $ Gitlink hash | otherwise -> fail ":((" MarkId n -> return $ Modify (Left n) path Inline -> do bits <- p_data return $ Modify (Right bits) path p_maybeQuotedCopyRenameNames = p_lexTwoQuotedNames <|> Unquoted `fmap` line p_lexTwoQuotedNames = do n1 <- lex p_quotedName n2 <- lex p_quotedName return $ Quoted n1 n2 p_maybeQuotedName = lex (p_quotedName <|> line) p_quotedName = do _ <- A.char '"' -- Take until a non-escaped " character. name <- A.scan Nothing (\previous char -> if char == '"' && previous /= Just '\\' then Nothing else Just (Just char)) _ <- A.char '"' return $ unescape name next' :: (B.ByteString -> A.Result (Maybe Object)) -> B.ByteString -> TreeIO (B.ByteString, Object) next' parser rest = do chunk <- if B.null rest then liftIO $ B.hGet stdin (64 * 1024) else return rest next_chunk parser chunk next_chunk :: (B.ByteString -> A.Result (Maybe Object)) -> B.ByteString -> TreeIO (B.ByteString, Object) next_chunk parser chunk = case parser chunk of A.Done rest result -> return (rest, maybe End id result) -- not sure about the maybe A.Partial cont -> next' cont B.empty A.Fail _ ctx err -> do liftIO $ putStrLn $ "=== chunk ===\n" ++ BC.unpack chunk ++ "\n=== end chunk ====" fail $ "Error parsing stream. " ++ err ++ "\nContext: " ++ show ctx patchHash :: PatchInfoAnd rt p cX cY -> BC.ByteString patchHash p = BC.pack $ show $ makePatchname (info p) inOrderTag :: (Effect p) => [PatchInfo] -> PatchInfoAnd rt p wX wZ -> Bool inOrderTag tags p = isTag (info p) && info p `elem` tags && nullFL (effect p) next :: (Effect p) => [PatchInfo] -> Int -> PatchInfoAnd rt p x y -> Int next tags n p = if inOrderTag tags p then n else n + 1 inOrderTags :: PatchSet rt p wS wX -> [PatchInfo] inOrderTags (PatchSet ts _) = go ts where go :: RL(Tagged rt t1) wT wY -> [PatchInfo] go (ts' :<: Tagged t _ _) = info t : go ts' go NilRL = [] type Marks = M.IntMap BC.ByteString emptyMarks :: Marks emptyMarks = M.empty lastMark :: Marks -> Int lastMark m = if M.null m then 0 else fst $ M.findMax m getMark :: Marks -> Int -> Maybe BC.ByteString getMark marks key = M.lookup key marks addMark :: Marks -> Int -> BC.ByteString -> Marks addMark marks key value = M.insert key value marks readMarks :: FilePath -> IO Marks readMarks p = do lines' <- BC.split '\n' `fmap` BC.readFile p return $ foldl merge M.empty lines' `catchall` return emptyMarks where merge set line = case BC.split ':' line of [i, hash] -> M.insert (read $ BC.unpack i) (BC.dropWhile (== ' ') hash) set _ -> set -- ignore, although it is maybe not such a great idea... writeMarks :: FilePath -> Marks -> IO () writeMarks fp m = do removeFile fp `catchall` return () -- unlink BC.writeFile fp marks where marks = BC.concat $ map format $ M.assocs m format (k, s) = BC.concat [BC.pack $ show k, BC.pack ": ", s, BC.pack "\n"] -- |unescape turns \r \n \" \\ into their unescaped form, leaving any -- other \-preceeded characters as they are. unescape :: BC.ByteString -> BC.ByteString unescape cs = case BC.uncons cs of Nothing -> BC.empty Just (c', cs') -> if c' == '\\' then case BC.uncons cs' of Nothing -> BC.empty Just (c'', cs'') -> let unescapedC = case c'' of 'r' -> '\r' 'n' -> '\n' '"' -> '"' '\\' -> '\\' x -> x in BC.cons unescapedC $ unescape cs'' else BC.cons c' $ unescape cs' darcs-2.14.5/src/Darcs/UI/Commands/Diff.hs0000644000000000000000000002660607346545000016207 0ustar0000000000000000-- Copyright (C) 2003-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Diff ( diffCommand, getDiffDoc ) where import Prelude () import Darcs.Prelude hiding ( all ) import Data.Maybe ( fromJust ) import System.FilePath.Posix ( takeFileName, () ) import Darcs.Util.Workaround ( getCurrentDirectory ) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Prompt ( askEnter ) import Control.Monad ( when ) import Data.List ( (\\) ) import Darcs.Util.Tree.Plain( writePlainTree ) import Darcs.Util.Tree.Hashed( hashedTreeIO ) import Data.Maybe ( isJust ) import System.Directory ( findExecutable ) import Darcs.Util.CommandLine ( parseCmd ) import Darcs.UI.External ( diffProgram , execPipeIgnoreError ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInHashedRepository ) import Darcs.UI.Completion ( knownFileArgs ) import Darcs.UI.Flags ( DarcsFlag, wantGuiPause, useCache, fixSubPaths ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( WantGuiPause (..), DiffAlgorithm(MyersDiff) ) import Darcs.Patch.PatchInfoAnd ( info, n2pia ) import Darcs.Util.Path ( toFilePath, SubPath, simpleSubPath, isSubPathOf, AbsolutePath ) import Darcs.Util.Global ( darcsdir ) import Darcs.Patch.Match ( firstMatch , secondMatch , matchFirstPatchset , matchSecondPatchset ) import Darcs.Repository ( withRepository, RepoJob(..), readRepo ) import Darcs.Repository.State ( readUnrecorded, restrictSubpaths , readRecorded, unrecordedChanges , UseIndex(..), ScanKnown(..), applyTreeFilter ) import Darcs.Patch.Witnesses.Ordered ( mapRL, (:>)(..), (+>+), RL(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoercePEnd ) import Darcs.Patch.Witnesses.Sealed ( unseal, Sealed(..), seal ) import Darcs.Patch ( RepoPatch, IsRepoType, apply, listTouchedFiles, invert, fromPrims ) import Darcs.Patch.Depends ( findCommonWithThem ) import Darcs.Patch.Named.Wrapped ( anonymous ) import Darcs.Patch.Set ( PatchSet(..), patchSet2RL ) import Darcs.Patch.Info ( PatchInfo, displayPatchInfo ) import Darcs.Util.Lock ( withTempDir ) import Darcs.Util.Printer ( Doc, putDoc, vcat, empty, ($$) ) diffDescription :: String diffDescription = "Create a diff between two versions of the repository." diffHelp :: String diffHelp = "The `darcs diff` command compares two versions of the working tree of\n" ++ "the current repository. Without options, the pristine (recorded) and\n" ++ "unrecorded working trees are compared. This is lower-level than\n" ++ "the `darcs whatsnew` command, since it outputs a line-by-line diff,\n" ++ "and it is also slower. As with `darcs whatsnew`, if you specify\n" ++ "files or directories, changes to other files are not listed.\n" ++ "The command always uses an external diff utility.\n" ++ "\n" ++ "With the `--patch` option, the comparison will be made between working\n" ++ "trees with and without that patch. Patches *after* the selected patch\n" ++ "are not present in either of the compared working trees. The\n" ++ "`--from-patch` and `--to-patch` options allow the set of patches in the\n" ++ "`old' and `new' working trees to be specified separately.\n" ++ "\n" ++ "The associated tag and match options are also understood, e.g. `darcs\n" ++ "diff --from-tag 1.0 --to-tag 1.1`. All these options assume an\n" ++ "ordering of the patch set, so results may be affected by operations\n" ++ "such as `darcs optimize reorder`.\n" ++ "\n" ++ "diff(1) is called with the arguments `-rN`. The `--unified` option causes\n" ++ "`-u` to be passed to diff(1). An additional argument can be passed\n" ++ "using `--diff-opts`, such as `--diff-opts=-ud` or `--diff-opts=-wU9`.\n" ++ "\n" ++ "The `--diff-command` option can be used to specify an alternative\n" ++ "utility. Arguments may be included, separated by whitespace. The value\n" ++ "is not interpreted by a shell, so shell constructs cannot be used. The\n" ++ "arguments %1 and %2 MUST be included, these are substituted for the two\n" ++ "working trees being compared. For instance:\n" ++ "\n" ++ " darcs diff -p . --diff-command \"meld %1 %2\"\n" ++ "\n" ++ "If this option is used, `--diff-opts` is ignored.\n" diffCommand :: DarcsCommand [DarcsFlag] diffCommand = DarcsCommand { commandProgramName = "darcs" , commandName = "diff" , commandHelp = diffHelp , commandDescription = diffDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[FILE or DIRECTORY]..."] , commandCommand = diffCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = knownFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc diffAdvancedOpts , commandBasicOptions = odesc diffBasicOpts , commandDefaults = defaultFlags diffOpts , commandCheckOptions = ocheck diffOpts , commandParseOptions = onormalise diffOpts } where diffBasicOpts = O.matchRange ^ O.extDiff ^ O.repoDir ^ O.storeInMemory diffAdvancedOpts = O.pauseForGui diffOpts = diffBasicOpts `withStdOpts` diffAdvancedOpts getDiffOpts :: O.ExternalDiff -> [String] getDiffOpts O.ExternalDiff {O.diffOpts=os,O.diffUnified=u} = addUnified os where addUnified = if u then ("-u":) else id -- | Returns the command we should use for diff as a tuple (command, arguments). -- This will either be whatever the user specified via --diff-command or the -- default 'diffProgram'. Note that this potentially involves parsing the -- user's diff-command, hence the possibility for failure with an exception. getDiffCmdAndArgs :: String -> [DarcsFlag] -> String -> String -> Either String (String, [String]) getDiffCmdAndArgs cmd opts f1 f2 = helper (O.extDiff ? opts) where helper extDiff = case O.diffCmd extDiff of Just c -> case parseCmd [ ('1', f1) , ('2', f2) ] c of Left err -> Left $ show err Right ([],_) -> bug "parseCmd should never return empty list" Right (h:t,_) -> Right (h,t) Nothing -> -- if no command specified, use 'diff' Right (cmd, "-rN":getDiffOpts extDiff++[f1,f2]) diffCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () diffCmd fps opts args | not (null (O.matchLast ? opts)) && not (null (O.matchFrom ? opts)) = fail $ "using --patch and --last at the same time with the 'diff'" ++ " command doesn't make sense. Use --from-patch to create a diff" ++ " from this patch to the present, or use just '--patch' to view" ++ " this specific patch." | null args = doDiff opts Nothing | otherwise = doDiff opts . Just =<< fixSubPaths fps args doDiff :: [DarcsFlag] -> Maybe [SubPath] -> IO () doDiff opts msubpaths = getDiffDoc opts msubpaths >>= putDoc getDiffDoc :: [DarcsFlag] -> Maybe [SubPath] -> IO Doc getDiffDoc opts msubpaths = withRepository (useCache ? opts) $ RepoJob $ \repository -> do formerdir <- getCurrentDirectory let thename = takeFileName formerdir patchset <- readRepo repository unrecorded <- fromPrims `fmap` unrecordedChanges (UseIndex, ScanKnown, MyersDiff) O.NoLookForMoves O.NoLookForReplaces repository msubpaths unrecorded' <- n2pia `fmap` anonymous unrecorded let matchFlags = parseFlags O.matchRange opts Sealed all <- return $ case (secondMatch matchFlags, patchset) of (True, _) -> seal patchset (False, PatchSet tagged untagged) -> seal $ PatchSet tagged (untagged :<: unrecorded') Sealed ctx <- return $ if firstMatch matchFlags then matchFirstPatchset matchFlags patchset else seal patchset Sealed match <- return $ if secondMatch matchFlags then matchSecondPatchset matchFlags patchset else seal all (_ :> todiff) <- return $ findCommonWithThem match ctx (_ :> tounapply) <- return $ findCommonWithThem all match base <- if secondMatch matchFlags then readRecorded repository else readUnrecorded repository Nothing let touched = map (fromJust . simpleSubPath) $ listTouchedFiles todiff files = case msubpaths of Nothing -> touched Just subpaths -> concatMap (\s -> filter (isSubPathOf s) touched) subpaths relevant <- restrictSubpaths repository files let filt = applyTreeFilter relevant . snd ppath = darcsdir "pristine.hashed" oldtree <- filt `fmap` hashedTreeIO (apply . invert $ unsafeCoercePEnd todiff +>+ tounapply) base ppath newtree <- filt `fmap` hashedTreeIO (apply . invert $ tounapply) base ppath withTempDir ("old-"++thename) $ \odir -> withTempDir ("new-"++thename) $ \ndir -> withCurrentDirectory formerdir $ do writePlainTree oldtree (toFilePath odir) writePlainTree newtree (toFilePath ndir) thediff <- withCurrentDirectory (toFilePath odir ++ "/..") $ rundiff (takeFileName $ toFilePath odir) (takeFileName $ toFilePath ndir) morepatches <- readRepo repository return $ changelog (getDiffInfo opts morepatches) $$ thediff where rundiff :: String -> String -> IO Doc rundiff f1 f2 = do cmd <- diffProgram case getDiffCmdAndArgs cmd opts f1 f2 of Left err -> fail err Right (d_cmd, d_args) -> do if length (filter (==f1) d_args) /= 1 || length (filter (==f2) d_args) /= 1 then fail $ "Invalid argument (%1 or %2) in --diff-command" else return () cmdExists <- findExecutable d_cmd if isJust cmdExists then return () else fail $ d_cmd ++ " is not an executable in --diff-command" let pausingForGui = (wantGuiPause opts == YesWantGuiPause) in do when pausingForGui $ putStrLn $ "Running command '" ++ unwords (d_cmd:d_args) ++ "'" output <- execPipeIgnoreError d_cmd d_args empty when pausingForGui $ askEnter "Hit return to move on..." return output getDiffInfo :: (IsRepoType rt, RepoPatch p) => [DarcsFlag] -> PatchSet rt p wStart wX -> [PatchInfo] getDiffInfo opts ps = let matchFlags = parseFlags O.matchRange opts infos = mapRL info . patchSet2RL handle (match_cond, do_match) | match_cond matchFlags = unseal infos (do_match matchFlags ps) | otherwise = infos ps in handle (secondMatch, matchSecondPatchset) \\ handle (firstMatch, matchFirstPatchset) changelog :: [PatchInfo] -> Doc changelog pis = vcat $ map displayPatchInfo pis darcs-2.14.5/src/Darcs/UI/Commands/Dist.hs0000644000000000000000000002001307346545000016224 0ustar0000000000000000-- Copyright (C) 2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | -- Module : Darcs.UI.Commands.Dist -- Copyright : 2003 David Roundy -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.UI.Commands.Dist ( dist , doFastZip -- libdarcs export , doFastZip' ) where import Prelude () import Darcs.Prelude hiding ( writeFile ) import Data.ByteString.Lazy ( writeFile ) import Data.Char ( isAlphaNum ) import Control.Monad ( when ) import System.Directory ( setCurrentDirectory ) import System.Process ( system ) import System.Exit ( ExitCode(..), exitWith ) import System.FilePath.Posix ( takeFileName, () ) import Darcs.Util.Workaround ( getCurrentDirectory ) import Codec.Archive.Tar ( pack, write ) import Codec.Archive.Tar.Entry ( entryPath ) import Codec.Compression.GZip ( compress ) import Codec.Archive.Zip ( emptyArchive, fromArchive, addEntryToArchive, toEntry ) import Darcs.Util.External ( fetchFilePS, Cachable( Uncachable ) ) import Darcs.Util.Global ( darcsdir ) import Darcs.Repository.Hashed ( peekPristineHash ) import Darcs.Repository.HashedIO ( pathsAndContents ) import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString as B import Darcs.UI.Flags as F ( DarcsFlag, useCache ) import qualified Darcs.UI.Flags as F ( setScriptsExecutable ) import Darcs.UI.Options ( (^), oid, odesc, ocheck, onormalise , defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInHashedRepository , putVerbose, putInfo ) import Darcs.UI.Completion ( noArgs ) import Darcs.Util.Lock ( withTempDir ) import Darcs.Patch.Match ( haveNonrangeMatch ) import Darcs.Repository.Match ( getNonrangeMatch ) import Darcs.Repository ( withRepository, withRepositoryLocation, RepoJob(..), setScriptsExecutable, repoPatchType, repoCache, createPartialsPristineDirectoryTree ) import Darcs.Repository.Prefs ( getPrefval ) import Darcs.Util.DateTime ( getCurrentTime, toSeconds ) import Darcs.Util.Path ( AbsolutePath, toFilePath ) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Printer ( text, vcat ) distDescription :: String distDescription = "Create a distribution archive." distHelp :: String distHelp = unlines [ "`darcs dist` creates a compressed archive in the repository's root" , "directory, containing the recorded state of the working tree" , "(unrecorded changes and the `_darcs` directory are excluded)." , "The command accepts matchers to create an archive of some past" , "repository state, for instance `--tag`." , "" , "By default, the archive (and the top-level directory within the" , "archive) has the same name as the repository, but this can be" , "overridden with the `--dist-name` option." , "" , "If a predist command is set (see `darcs setpref`), that command will" , "be run on the recorded state prior to archiving. For example," , "autotools projects would set it to `autoconf && automake`." , "" , "If `--zip` is used, matchers and the predist command are ignored." ] dist :: DarcsCommand [DarcsFlag] dist = DarcsCommand { commandProgramName = "darcs" , commandName = "dist" , commandHelp = distHelp , commandDescription = distDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = distCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc distBasicOpts , commandDefaults = defaultFlags distOpts , commandCheckOptions = ocheck distOpts , commandParseOptions = onormalise distOpts } where distBasicOpts = O.distname ^ O.distzip ^ O.repoDir ^ O.matchUpToOne ^ O.setScriptsExecutable ^ O.storeInMemory distOpts = distBasicOpts `withStdOpts` oid distCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () distCmd _ opts _ | O.distzip ? opts = doFastZip opts distCmd _ opts _ = withRepository (useCache ? opts) $ RepoJob $ \repository -> do let matchFlags = parseFlags O.matchUpToOne opts formerdir <- getCurrentDirectory let distname = getDistName formerdir (O.distname ? opts) predist <- getPrefval "predist" let resultfile = formerdir distname ++ ".tar.gz" withTempDir "darcsdist" $ \tempdir -> do setCurrentDirectory formerdir withTempDir (toFilePath tempdir takeFileName distname) $ \ddir -> do if haveNonrangeMatch (repoPatchType repository) matchFlags then withCurrentDirectory ddir $ getNonrangeMatch repository matchFlags else createPartialsPristineDirectoryTree repository [""] (toFilePath ddir) ec <- case predist of Nothing -> return ExitSuccess Just pd -> system pd if ec == ExitSuccess then do withCurrentDirectory ddir $ when (F.setScriptsExecutable ? opts == O.YesSetScriptsExecutable) setScriptsExecutable doDist opts tempdir ddir resultfile else do putStrLn "Dist aborted due to predist failure" exitWith ec -- | This function performs the actual distribution action itself. -- NB - it does /not/ perform the pre-dist, that should already -- have completed successfully before this is invoked. doDist :: [DarcsFlag] -> AbsolutePath -> AbsolutePath -> FilePath -> IO () doDist opts tempdir ddir resultfile = do setCurrentDirectory (toFilePath tempdir) let safeddir = safename $ takeFileName $ toFilePath ddir entries <- pack "." [safeddir] putVerbose opts $ vcat $ map (text . entryPath) entries writeFile resultfile $ compress $ write entries putInfo opts $ text $ "Created dist as " ++ resultfile where safename n@(c:_) | isAlphaNum c = n safename n = "./" ++ n getDistName :: FilePath -> Maybe String -> FilePath getDistName _ (Just dn) = dn getDistName currentDirectory _ = takeFileName currentDirectory doFastZip :: [DarcsFlag] -> IO () doFastZip opts = do currentdir <- getCurrentDirectory let distname = getDistName currentdir (O.distname ? opts) let resultfile = currentdir distname ++ ".zip" doFastZip' opts currentdir (writeFile resultfile) putInfo opts $ text $ "Created " ++ resultfile doFastZip' :: [DarcsFlag] -- ^ Flags/options -> FilePath -- ^ The path to the repository -> (BL.ByteString -> IO a) -- ^ An action to perform on the archive contents -> IO a doFastZip' opts path act = withRepositoryLocation (useCache ? opts) path $ RepoJob $ \repo -> do when (F.setScriptsExecutable ? opts == O.YesSetScriptsExecutable) $ putStrLn "WARNING: Zip archives cannot store executable flag." let distname = getDistName path (O.distname ? opts) i <- fetchFilePS (path darcsdir "hashed_inventory") Uncachable pristine <- pathsAndContents (distname ++ "/") (repoCache repo) (peekPristineHash i) epochtime <- toSeconds `fmap` getCurrentTime let entries = [ toEntry filepath epochtime (toLazy contents) | (filepath,contents) <- pristine ] let archive = foldr addEntryToArchive emptyArchive entries act (fromArchive archive) toLazy :: B.ByteString -> BL.ByteString toLazy bs = BL.fromChunks [bs] darcs-2.14.5/src/Darcs/UI/Commands/GZCRCs.hs0000644000000000000000000002267607346545000016375 0ustar0000000000000000-- Copyright (C) 2009 Ganesh Sittampalam -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. module Darcs.UI.Commands.GZCRCs ( gzcrcs , doCRCWarnings ) where import Prelude () import Darcs.Prelude import Control.Monad ( when, unless, forM_ ) import Control.Monad.Trans ( liftIO ) import Control.Monad.Writer ( runWriterT, tell ) import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import Data.IORef ( newIORef, readIORef, writeIORef ) import Data.Monoid ( Any(..), Sum(..) ) import System.Directory ( doesFileExist, doesDirectoryExist ) import System.Exit ( ExitCode(..), exitWith ) import System.IO ( hPutStr, hPutStrLn, stderr ) import Darcs.Util.File ( getRecursiveContentsFullPath ) import Darcs.Util.ByteString ( isGZFile, gzDecompress ) import Darcs.Util.Global ( getCRCWarnings, resetCRCWarnings ) import Darcs.Repository ( Repository, withRepository, RepoJob(..), repoCache ) -- This command needs access beyond the normal repository APIs (to -- get at the caches and inspect them directly) -- Could move the relevant code into Darcs.Repository modules -- but it doesn't really seem worth it. import Darcs.Repository.Cache ( Cache(..), writable, isThisRepo, hashedFilePath, allHashedDirs ) import Darcs.Util.Lock ( gzWriteAtomicFilePSs ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInRepository , putInfo, putVerbose ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Options ( (^), oid, odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Util.Path ( AbsolutePath ) import Darcs.UI.Flags ( DarcsFlag, useCache ) import Darcs.Util.Text ( formatText ) import Darcs.Util.Printer ( text ) gzcrcsHelp :: String gzcrcsHelp = formatText 80 [ "Versions of darcs >=1.0.4 and <2.2.0 had a bug that caused compressed " ++ "files with bad CRCs (but valid data) to be written out. CRCs were " ++ "not checked on reading, so this bug wasn't noticed." , "This command inspects your repository for this corruption and " ++ "optionally repairs it." , "By default it also does this for any caches you have configured and " ++ "any other local repositories listed as sources of patches for this " ++ "one, perhaps because of a lazy clone. You can limit the scope to just " ++ "the current repo with the --just-this-repo flag." , "Note that readonly caches, or other repositories listed as sources, " ++ "will be checked but not repaired. Also, this command will abort if " ++ "it encounters any non-CRC corruption in compressed files." , "You may wish to also run 'darcs check --complete' before repairing the " ++ "corruption. This is not done automatically because it might result " ++ "in needing to fetch extra patches if the repository is lazy." , "If there are any other problems with your repository, you can still " ++ "repair the CRCs, but you are advised to first make a backup copy in " ++ "case the CRC errors are actually caused by bad data and the old " ++ "CRCs might be useful in recovering that data." , "If you were warned about CRC errors during an operation involving " ++ "another repository, then it is possible that the other repository " ++ "contains the corrupt CRCs, so you should arrange for that " ++ "repository to also be checked/repaired." ] -- |This is designed for use in an atexit handler, e.g. in Darcs.RunCommand doCRCWarnings :: Bool -> IO () doCRCWarnings verbose = do files <- getCRCWarnings resetCRCWarnings unless (null files) $ do hPutStr stderr . formatText 80 $ ["" , "Warning: CRC errors found. These are probably harmless but " ++ "should be repaired. See 'darcs gzcrcs --help' for more " ++ "information." , "" ] when verbose $ hPutStrLn stderr . unlines $ "The following corrupt files were found:" : files gzcrcsDescription :: String gzcrcsDescription = "Check or repair the CRCs of compressed files in the " ++ "repository." gzcrcs :: DarcsCommand [DarcsFlag] gzcrcs = DarcsCommand { commandProgramName = "darcs" , commandName = "gzcrcs" , commandHelp = gzcrcsHelp , commandDescription = gzcrcsDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = gzcrcsCmd , commandPrereq = amInRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc gzcrcsBasicOpts , commandDefaults = defaultFlags gzcrcsOpts , commandCheckOptions = ocheck gzcrcsOpts , commandParseOptions = onormalise gzcrcsOpts } where gzcrcsBasicOpts = O.gzcrcsActions ^ O.justThisRepo ^ O.repoDir gzcrcsOpts = gzcrcsBasicOpts `withStdOpts` oid gzcrcsCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () gzcrcsCmd _ opts _ = case O.gzcrcsActions ? opts of Nothing -> fail "You must specify --check or --repair for gzcrcs" Just action -> withRepository (useCache ? opts) (RepoJob (gzcrcs' action opts)) gzcrcs' :: O.GzcrcsAction -> [DarcsFlag] -> Repository rt p wR wU wT -> IO () gzcrcs' action opts repo = do -- Somewhat ugly IORef use here because it's convenient, would be nicer to -- pre-filter the list of locs to check and then decide whether to print -- the message up front. warnRelatedRepos <- newIORef $ not isJustThisRepo let Ca locs = repoCache repo (_, Any checkFailed) <- runWriterT $ forM_ locs $ \loc -> unless (isJustThisRepo && not (isThisRepo loc)) $ do let isWritable = writable loc forM_ allHashedDirs $ \hdir -> do let dir = hashedFilePath loc hdir "" exists <- liftIO $ doesDirectoryExist dir when exists $ do liftIO $ do warn <- readIORef warnRelatedRepos when (warn && not (isThisRepo loc)) $ do writeIORef warnRelatedRepos False putInfo opts $ text $ "Also checking related repos and caches; use " ++ "--just-this-repo to disable.\n" ++ "Checking " ++ dir ++ (if isWritable then "" else " (readonly)") files <- liftIO $ getRecursiveContentsFullPath dir (_, Sum count) <- runWriterT $ forM_ files $ \file -> do isfile <- liftIO $ doesFileExist file when isfile $ do gz <- liftIO $ isGZFile file case gz of Nothing -> return () Just len -> do contents <- liftIO $ B.readFile file let contentsbl = BL.fromChunks [contents] (uncompressed, isCorrupt) = gzDecompress (Just len) contentsbl when isCorrupt $ do -- Count of files in current directory tell (Sum 1) liftIO . putVerbose opts $ text $ "Corrupt: " ++ file when (isWritable && shouldRepair) $ doRepair file uncompressed when (count > (0 :: Int)) $ do liftIO . putInfo opts $ text $ "Found " ++ show count ++ " corrupt file" ++ (if count > 1 then "s" else "") ++ (if shouldRepair then if isWritable then " (repaired)" else " (not repaired)" else "") -- Something corrupt somewhere tell (Any True) when (action == O.GzcrcsCheck && checkFailed) $ exitWith (ExitFailure 1) where shouldRepair = action == O.GzcrcsRepair isJustThisRepo = O.justThisRepo ? opts doRepair name contents = liftIO $ gzWriteAtomicFilePSs name contents darcs-2.14.5/src/Darcs/UI/Commands/Help.hs0000644000000000000000000004263207346545000016224 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Help ( helpCmd, commandControlList, environmentHelp, -- these are for preproc.hs printVersion, listAvailableCommands ) where import Prelude () import Darcs.Prelude import Darcs.UI.Flags ( DarcsFlag , environmentHelpEmail , environmentHelpSendmail ) import Darcs.UI.Options.Markdown ( optionsMarkdown ) import Darcs.UI.Commands ( CommandArgs(..) , CommandControl(..) , normalCommand , DarcsCommand(..) , WrappedCommand(..) , wrappedCommandName , disambiguateCommands , extractCommands , getSubcommands , nodefaults ) import Darcs.UI.External ( viewDoc ) import Darcs.UI.Usage ( getCommandHelp , usage , subusage ) import Darcs.Util.Lock ( environmentHelpTmpdir, environmentHelpKeepTmpdir , environmentHelpLocks ) import Darcs.Patch.Match ( helpOnMatchers ) import Darcs.Repository.Prefs ( environmentHelpHome, prefsFilesHelp ) import Darcs.Util.Ssh ( environmentHelpSsh, environmentHelpScp, environmentHelpSshPort ) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Path ( AbsolutePath ) import Control.Arrow ( (***) ) import Data.Char ( isAlphaNum, toLower, toUpper ) import Data.Either ( partitionEithers ) import Data.List ( groupBy, isPrefixOf, intercalate, nub, lookup ) import Darcs.Util.English ( andClauses ) import Darcs.Util.Printer (text, vcat, vsep, ($$), empty) import Darcs.Util.Printer.Color ( environmentHelpColor, environmentHelpEscape, environmentHelpEscapeWhite ) import System.Exit ( exitSuccess ) import Version ( version ) import Darcs.Util.Download ( environmentHelpProxy, environmentHelpProxyPassword ) import Darcs.Util.Workaround ( getCurrentDirectory ) import Darcs.UI.Options ( defaultFlags, ocheck, onormalise, oid ) import qualified Darcs.UI.TheCommands as TheCommands helpDescription :: String helpDescription = "Display help about darcs and darcs commands." helpHelp :: String helpHelp = "Without arguments, `darcs help` prints a categorized list of darcs\n" ++ "commands and a short description of each one. With an extra argument,\n" ++ "`darcs help foo` prints detailed help about the darcs command foo.\n" -- | Starting from a list of 'CommandControl's, unwrap one level -- to get a list of command names together with their subcommands. unwrapTree :: [CommandControl] -> [(String, [CommandControl])] unwrapTree cs = [ (wrappedCommandName c, subcmds c) | CommandData c <- cs ] where subcmds (WrappedCommand sc) = getSubcommands sc -- | Given a list of (normal) arguments to the help command, produce a list -- of possible completions for the next (normal) argument. completeArgs :: [String] -> [String] completeArgs [] = map fst (unwrapTree commandControlList) ++ extraArgs where extraArgs = [ "manpage", "markdown", "patterns", "environment" ] completeArgs (arg:args) = exploreTree arg args commandControlList where exploreTree cmd cmds cs = case lookup cmd (unwrapTree cs) of Nothing -> [] Just cs' -> case cmds of [] -> map fst (unwrapTree cs') sub:cmds' -> exploreTree sub cmds' cs' help :: DarcsCommand [DarcsFlag] help = DarcsCommand { commandProgramName = "darcs" , commandName = "help" , commandHelp = helpHelp , commandDescription = helpDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[ [DARCS_SUBCOMMAND]] "] , commandCommand = \ x y z -> helpCmd x y z >> exitSuccess , commandPrereq = \_ -> return $ Right () , commandCompleteArgs = \_ _ -> return . completeArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = [] , commandDefaults = defaultFlags oid , commandCheckOptions = ocheck oid , commandParseOptions = onormalise oid } helpCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () helpCmd _ _ ["manpage"] = putStr $ unlines manpageLines helpCmd _ _ ["markdown"] = putStr $ unlines markdownLines helpCmd _ _ ["patterns"] = viewDoc $ text $ unlines helpOnMatchers helpCmd _ _ ("environment":vs_) = viewDoc $ header $$ vsep (map render known) $$ footer where header | null known = empty | otherwise = text "Environment Variables" $$ text "=====================" footer | null unknown = empty | otherwise = text "" $$ text ("Unknown environment variables: " ++ intercalate ", " unknown) render (ks, ds) = text (andClauses ks ++ ":") $$ vcat [ text (" " ++ d) | d <- ds ] (unknown, known) = case map (map toUpper) vs_ of [] -> ([], environmentHelp) vs -> (nub *** (nub . concat)) . partitionEithers $ map doLookup vs -- v is not known if it doesn't appear in the list of aliases of any -- of the environment var help descriptions. doLookup v = case filter ((v `elem`) . fst) environmentHelp of [] -> Left v es -> Right es helpCmd _ _ [] = viewDoc $ usage commandControlList helpCmd _ _ (cmd:args) = case disambiguateCommands commandControlList cmd args of Left err -> fail err Right (cmds,as) -> let msg = case cmds of CommandOnly c -> getCommandHelp Nothing c SuperCommandOnly c -> if null as then getCommandHelp Nothing c else text $ "Invalid subcommand!\n\n" ++ subusage c SuperCommandSub c s -> getCommandHelp (Just c) s in viewDoc $ msg listAvailableCommands :: IO () listAvailableCommands = do here <- getCurrentDirectory is_valid <- mapM (\(WrappedCommand c)-> withCurrentDirectory here $ commandPrereq c []) (extractCommands commandControlList) putStr $ unlines $ map (wrappedCommandName . fst) $ filter (isRight.snd) $ zip (extractCommands commandControlList) is_valid putStrLn "--help" putStrLn "--version" putStrLn "--exact-version" where isRight (Right _) = True isRight _ = False printVersion :: IO () printVersion = putStrLn $ "darcs version " ++ version -- avoiding a module import cycle between Help and TheCommands commandControlList :: [CommandControl] commandControlList = normalCommand help : TheCommands.commandControlList -- FIXME: the "grouping" comments below should made subsections in the -- manpage, as we already do for DarcsCommand groups. --twb, 2009 -- | Help on each environment variable in which Darcs is interested. environmentHelp :: [([String], [String])] environmentHelp = [ -- General-purpose environmentHelpHome, environmentHelpEditor, environmentHelpPager, environmentHelpColor, environmentHelpEscapeWhite, environmentHelpEscape, environmentHelpTmpdir, environmentHelpKeepTmpdir, environmentHelpEmail, environmentHelpSendmail, environmentHelpLocks, -- Remote Repositories environmentHelpSsh, environmentHelpScp, environmentHelpSshPort, environmentHelpProxy, environmentHelpProxyPassword, environmentHelpTimeout] -- | This module is responsible for emitting a darcs "man-page", a -- reference document used widely on Unix-like systems. Manpages are -- primarily used as a quick reference, or "memory jogger", so the -- output should be terser than the user manual. -- -- Before modifying the output, please be sure to read the man(7) and -- man-pages(7) manpages, as these respectively describe the relevant -- syntax and conventions. -- | The lines of the manpage to be printed. manpageLines :: [String] manpageLines = [ ".TH DARCS 1 \"" ++ version ++ "\"", ".SH NAME", "darcs \\- an advanced revision control system", ".SH SYNOPSIS", ".B darcs", ".I command", ".RI < arguments |[ options ]>...", "", "Where the", ".I commands", "and their respective", ".I arguments", "are", "", unlines synopsis, ".SH DESCRIPTION", -- FIXME: this is copy-and-pasted from darcs.cabal, so -- it'll get out of date as people forget to maintain -- both in sync. "Darcs is a free, open source revision control", "system. It is:", ".TP 3", "\\(bu", "Distributed: Every user has access to the full", "command set, removing boundaries between server and", "client or committer and non\\(hycommitters.", ".TP", "\\(bu", "Interactive: Darcs is easy to learn and efficient to", "use because it asks you questions in response to", "simple commands, giving you choices in your work", "flow. You can choose to record one change in a file,", "while ignoring another. As you update from upstream,", "you can review each patch name, even the full `diff'", "for interesting patches.", ".TP", "\\(bu", "Smart: Originally developed by physicist David", "Roundy, darcs is based on a unique algebra of", "patches.", "This smartness lets you respond to changing demands", "in ways that would otherwise not be possible. Learn", "more about spontaneous branches with darcs.", ".SH OPTIONS", "Different options are accepted by different Darcs commands.", "Each command's most important options are listed in the", ".B COMMANDS", "section. For a full list of all options accepted by", "a particular command, run `darcs", ".I command", "\\-\\-help'.", ".SS " ++ escape (unlines helpOnMatchers), -- FIXME: this is a kludge. ".SH COMMANDS", unlines commands, unlines environment, ".SH FILES", unlines prefFiles, ".SH BUGS", "At http://bugs.darcs.net/ you can find a list of known", "bugs in Darcs. Unknown bugs can be reported at that", "site (after creating an account) or by emailing the", "report to bugs@darcs.net.", -- ".SH EXAMPLE", -- FIXME: -- new project: init, rec -la; -- track upstream project: clone, pull -a; -- contribute to project: add, rec, push/send. ".SH SEE ALSO", "The Darcs website provides a lot of additional information.", "It can be found at http://darcs.net/", ".SH LICENSE", "Darcs is free software; you can redistribute it and/or modify", "it under the terms of the GNU General Public License as published by", "the Free Software Foundation; either version 2, or (at your option)", "any later version." ] where -- | A synopsis line for each command. Uses 'foldl' because it is -- necessary to avoid blank lines from Hidden_commands, as groff -- translates them into annoying vertical padding (unlike TeX). synopsis :: [String] synopsis = foldl iter [] commandControlList where iter :: [String] -> CommandControl -> [String] iter acc (GroupName _) = acc iter acc (HiddenCommand _) = acc iter acc (CommandData (WrappedCommand c@SuperCommand {})) = acc ++ concatMap (render (commandName c ++ " ")) (extractCommands (commandSubCommands c)) iter acc (CommandData c) = acc ++ render "" c render :: String -> WrappedCommand -> [String] render prefix (WrappedCommand c) = [".B darcs " ++ prefix ++ commandName c] ++ map mangle_args (commandExtraArgHelp c) ++ -- In the output, we want each command to be on its own -- line, but we don't want blank lines between them. -- AFAICT this can only be achieved with the .br -- directive, which is probably a GNUism. [".br"] -- | As 'synopsis', but make each group a subsection (.SS), and -- include the help text for each command. commands :: [String] commands = foldl iter [] commandControlList where iter :: [String] -> CommandControl -> [String] iter acc (GroupName x) = acc ++ [".SS \"" ++ x ++ "\""] iter acc (HiddenCommand _) = acc iter acc (CommandData (WrappedCommand c@SuperCommand {})) = acc ++ concatMap (render (commandName c ++ " ")) (extractCommands (commandSubCommands c)) iter acc (CommandData c) = acc ++ render "" c render :: String -> WrappedCommand -> [String] render prefix (WrappedCommand c) = [".B darcs " ++ prefix ++ commandName c] ++ map mangle_args (commandExtraArgHelp c) ++ [".RS 4", escape $ commandHelp c, ".RE"] -- | Now I'm showing off: mangle the extra arguments of Darcs commands -- so as to use the ideal format for manpages, italic words and roman -- punctuation. mangle_args :: String -> String mangle_args s = ".RI " ++ unwords (map show (groupBy cmp $ map toLower $ gank s)) where cmp x y = not $ xor (isAlphaNum x) (isAlphaNum y) xor x y = (x && not y) || (y && not x) gank (' ':'o':'r':' ':xs) = '|' : gank xs gank (x:xs) = x : gank xs gank [] = [] environment :: [String] environment = ".SH ENVIRONMENT" : concat [(".SS \"" ++ andClauses ks ++ "\"") : map escape ds | (ks, ds) <- environmentHelp] escape :: String -> String escape = minus . bs -- Order is important where minus = replace "-" "\\-" bs = replace "\\" "\\\\" replace :: Eq a => [a] -> [a] -> [a] -> [a] replace _ _ [] = [] replace find repl s = if find `isPrefixOf` s then repl ++ replace find repl (drop (length find) s) else head s : replace find repl (tail s) prefFiles = concatMap go prefsFilesHelp where go (f,h) = [".SS \"_darcs/prefs/" ++ f ++ "\"", escape h] markdownLines :: [String] markdownLines = [ "# Commands", "" , unlines commands , "# Patterns" , "", unlines helpOnMatchers , "# Configuration" , "", unlines prefFiles , "# Environment variables" , "", unlines environment ] where prefFiles = concatMap go prefsFilesHelp where go (f,h) = ["## `_darcs/prefs/" ++ f ++ "`", "", h] environment :: [String] environment = intercalate [""] [ renderEnv ks ds | (ks, ds) <- environmentHelp ] where renderEnv k d = ("## " ++ (intercalate ", " k)) : "" : d commands :: [String] commands = foldl iter [] commandControlList iter :: [String] -> CommandControl -> [String] iter acc (GroupName x) = acc ++ ["## " ++ x, ""] iter acc (HiddenCommand _) = acc iter acc (CommandData (WrappedCommand c@SuperCommand {})) = acc ++ concatMap (render (commandName c ++ " ")) (extractCommands (commandSubCommands c)) iter acc (CommandData c) = acc ++ render "" c render :: String -> WrappedCommand -> [String] render prefix (WrappedCommand c) = [ "### " ++ prefix ++ commandName c , "", "darcs " ++ prefix ++ commandName c ++ " [OPTION]... " ++ unwords (commandExtraArgHelp c) , "", commandDescription c , "", commandHelp c , "Options:", optionsMarkdown $ commandBasicOptions c , if null opts2 then "" else unlines ["Advanced Options:", optionsMarkdown opts2] ] where opts2 = commandAdvancedOptions c environmentHelpEditor :: ([String], [String]) environmentHelpEditor = (["DARCS_EDITOR", "VISUAL", "EDITOR"],[ "To edit a patch description of email comment, Darcs will invoke an", "external editor. Your preferred editor can be set as any of the", "environment variables $DARCS_EDITOR, $VISUAL or $EDITOR.", "If none of these are set, nano is used. If nano crashes or is not", "found in your PATH, vi, emacs, emacs -nw and (on Windows) edit are", "each tried in turn."]) environmentHelpPager :: ([String], [String]) environmentHelpPager = (["DARCS_PAGER", "PAGER"],[ "Darcs will invoke a pager if the output of some command is longer", "than 20 lines. Darcs will use the pager specified by $DARCS_PAGER", "or $PAGER. If neither are set, `less` will be used."]) environmentHelpTimeout :: ([String], [String]) environmentHelpTimeout = (["DARCS_CONNECTION_TIMEOUT"],[ "Set the maximum time in seconds that darcs allows and connection to", "take. If the variable is not specified the default are 30 seconds.", "This option only works with curl."]) -- | There are two environment variables that we do not document: -- - DARCS_USE_ISPRINT: deprecated, use DARCS_DONT_ESCAPE_ISPRINT. -- - DARCS_TESTING_PREFS_DIR: used by the test suite to tell darcs -- where to find its configuration files. darcs-2.14.5/src/Darcs/UI/Commands/Init.hs0000644000000000000000000000760307346545000016236 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Init ( initialize, initializeCmd ) where import Prelude () import Darcs.Prelude import Prelude hiding ( (^) ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amNotInRepository, putInfo ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags ( DarcsFlag( WorkRepoDir ) ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.Options.All ( ) import Darcs.Util.Printer ( text ) import Darcs.Util.Path ( AbsolutePath ) import Darcs.Util.Text ( quote ) import Darcs.Repository ( createRepository, withUMaskFlag ) initializeDescription :: String initializeDescription = "Create an empty repository." initializeHelp :: String initializeHelp = "The `darcs initialize` command creates an empty repository in the\n" ++ "current directory. This repository lives in a new `_darcs` directory,\n"++ "which stores version control metadata and settings.\n" ++ "\n" ++ "Any existing files and subdirectories become UNSAVED changes:\n" ++ "record them with `darcs record --look-for-adds`.\n" ++ "\n" ++ "By default, patches of the new repository are in the darcs-2 semantics.\n" ++ "However it is possible to create a repository in darcs-1 semantics with\n" ++ "the flag `--darcs-1`, althought this is not recommended except for sharing\n" ++ "patches with a project that uses patches in the darcs-1 semantics.\n" ++ "\n" ++ "Initialize is commonly abbreviated to `init`.\n" initialize :: DarcsCommand [DarcsFlag] initialize = DarcsCommand { commandProgramName = "darcs" , commandName = "initialize" , commandHelp = initializeHelp , commandDescription = initializeDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[]"] , commandPrereq = \_ -> return $ Right () , commandCommand = initializeCmd , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc initAdvancedOpts , commandBasicOptions = odesc initBasicOpts , commandDefaults = defaultFlags initOpts , commandCheckOptions = ocheck initOpts , commandParseOptions = onormalise initOpts } where initBasicOpts = O.patchFormat ^ O.withWorkingDir ^ O.repoDir initAdvancedOpts = O.patchIndexNo ^ O.hashed initOpts = initBasicOpts `withStdOpts` initAdvancedOpts initializeCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () initializeCmd aps opts [outname] | null [ () | WorkRepoDir _ <- opts ] = initializeCmd aps (WorkRepoDir outname:opts) [] initializeCmd _ opts [] = withUMaskFlag (O.umask ? opts) $ do location <- amNotInRepository opts case location of Left msg -> fail $ "Unable to " ++ quote ("darcs " ++ commandName initialize) ++ " here.\n\n" ++ msg Right () -> do _ <- createRepository (O.patchFormat ? opts) (O.withWorkingDir ? opts) (O.patchIndexNo ? opts) (O.useCache ? opts) putInfo opts $ text "Repository initialized." initializeCmd _ _ _ = fail "You must provide 'initialize' with either zero or one argument." darcs-2.14.5/src/Darcs/UI/Commands/Log.hs0000644000000000000000000005035007346545000016051 0ustar0000000000000000-- Copyright (C) 2003-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE PatternGuards #-} module Darcs.UI.Commands.Log ( changes, log , changelog, getLogInfo ) where import Prelude () import Darcs.Prelude import Data.List ( intersect, sort, nub, find ) import Data.Maybe ( fromMaybe, fromJust, isJust ) import Control.Arrow ( second ) import Control.Exception ( catch, IOException ) import Control.Monad.State.Strict import Darcs.UI.PrintPatch ( showFriendly ) import Darcs.Patch.PatchInfoAnd ( fmapFLPIAP, hopefullyM, info ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, commandAlias, findRepository ) import Darcs.UI.Completion ( knownFileArgs ) import Darcs.UI.External ( viewDocWith ) import Darcs.UI.Flags ( DarcsFlag , changesReverse, onlyToFiles , useCache, maxCount, hasXmlOutput , verbosity, withContext, isInteractive, verbose , fixSubPaths, getRepourl ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Util.Path ( SubPath(), toFilePath, fp2fn, fn2fp, normPath, AbsolutePath, simpleSubPath ) import Darcs.Repository ( PatchSet, PatchInfoAnd, withRepositoryLocation, RepoJob(..), readRepo, unrecordedChanges, withRepoLockCanFail ) import Darcs.Repository.Flags ( UseIndex(..), ScanKnown(..), DiffAlgorithm(MyersDiff) ) import Darcs.Util.Lock ( withTempDir ) import Darcs.Patch.Set ( PatchSet(..), patchSet2RL ) import Darcs.Patch.Conflict ( Conflict, CommuteNoConflicts ) import Darcs.Patch.Format ( PatchListFormat ) import Darcs.Patch.FileHunk ( IsHunk ) import Darcs.Patch.Info ( toXml, toXmlShort, showPatchInfo, displayPatchInfo, escapeXML, PatchInfo ) import Darcs.Patch.Depends ( findCommonWithThem ) import Darcs.Patch.Bundle( contextPatches ) import Darcs.Patch.Prim ( PrimPatchBase ) import Darcs.Patch.Show ( ShowPatch, ShowPatchFor(..) ) import Darcs.Patch.TouchesFiles ( lookTouch ) import Darcs.Patch.Type ( PatchType(PatchType) ) import Darcs.Patch.Apply ( Apply, ApplyState ) import Darcs.Patch ( IsRepoType, invert, xmlSummary, description, effectOnFilePaths, listTouchedFiles, showPatch ) import Darcs.Patch.Named.Wrapped ( (:~:)(..), getdeps ) import Darcs.Patch.Witnesses.Eq ( EqCheck(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(NilFL), RL(..), filterOutFLFL, filterRL, reverseFL, (:>)(..), mapRL ) import Darcs.Patch.Witnesses.Sealed ( Sealed2(..), unseal2, Sealed(..), seal2 ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Patch.Match ( MatchFlag , firstMatch , secondMatch , matchAPatch , haveNonrangeMatch , matchFirstPatchset , matchSecondPatchset ) import Darcs.Patch.Matchable ( Matchable ) import Darcs.Util.Printer ( Doc, simplePrinters, (<+>), prefix, text, vcat, vsep, ($$), errorDoc, insertBeforeLastline, empty ) import Darcs.Util.Printer.Color ( fancyPrinters ) import Darcs.Util.Progress ( setProgressMode, debugMessage ) import Darcs.Util.URL ( isValidLocalPath ) import Darcs.UI.SelectChanges ( viewChanges ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions (..) ) import Darcs.Repository.PatchIndex ( PatchFilter, maybeFilterPatches, attemptCreatePatchIndex ) import Darcs.Util.Tree( Tree ) logHelp :: String logHelp = unlines [ "The `darcs log` command lists patches of the current repository or," , "with `--repo`, a remote repository. Without options or arguments," , "ALL patches will be listed." , ""] ++ logHelp' ++ logHelp'' log :: DarcsCommand [DarcsFlag] log = DarcsCommand { commandProgramName = "darcs" , commandName = "log" , commandHelp = logHelp , commandDescription = "List patches in the repository." , commandExtraArgs = -1 , commandExtraArgHelp = ["[FILE or DIRECTORY]..."] , commandCompleteArgs = knownFileArgs , commandCommand = logCmd , commandPrereq = findRepository , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc logAdvancedOpts , commandBasicOptions = odesc logBasicOpts , commandDefaults = defaultFlags logOpts , commandCheckOptions = ocheck logOpts , commandParseOptions = onormalise logOpts } where logBasicOpts = O.matchSeveralOrRange ^ O.maxCount ^ O.onlyToFiles ^ O.changesFormat ^ O.summary ^ O.changesReverse ^ O.possiblyRemoteRepo ^ O.repoDir ^ O.interactive logAdvancedOpts = O.network ^ O.patchIndexYes logOpts = logBasicOpts `withStdOpts` logAdvancedOpts logCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () logCmd fps opts args | O.changesFormat ? opts == Just O.GenContext = if not . null $ args then fail "log --context cannot accept other arguments" else logContext opts | hasRemoteRepo opts = do (fs, es) <- remoteSubPaths args [] if null es then withTempDir "darcs.log" (\_ -> showLog opts $ maybeNotNull $ nub $ sort fs) else fail $ "For a remote repo I can only handle relative paths.\n" ++ "Invalid arguments: "++unwords es | null args = showLog opts Nothing | otherwise = do fs <- fixSubPaths fps args case fs of [] -> putStrLn "No valid arguments were given, nothing to do." _ -> do unless (isInteractive False opts) $ when (O.patchIndexNo ? opts == O.YesPatchIndex) $ withRepoLockCanFail (useCache ? opts) $ RepoJob (\repo -> readRepo repo >>= attemptCreatePatchIndex repo) showLog opts $ Just $ nub $ sort fs maybeNotNull :: [a] -> Maybe [a] maybeNotNull [] = Nothing maybeNotNull xs = Just xs hasRemoteRepo :: [DarcsFlag] -> Bool hasRemoteRepo = maybe False (not . isValidLocalPath) . parseFlags O.possiblyRemoteRepo remoteSubPaths :: [String] -> [String] -> IO ([SubPath],[String]) remoteSubPaths [] es = return ([], es) remoteSubPaths (arg:args) es = case simpleSubPath arg of Nothing -> remoteSubPaths args (arg:es) Just sp -> do (sps, es') <- remoteSubPaths args es return (sp:sps, es') showLog :: [DarcsFlag] -> Maybe [SubPath] -> IO () showLog opts files = let repodir = fromMaybe "." (getRepourl opts) in withRepositoryLocation (useCache ? opts) repodir $ RepoJob $ \repository -> do unless (O.debug ? opts) $ setProgressMode False Sealed unrec <- case files of Nothing -> return $ Sealed NilFL Just _ -> Sealed `fmap` unrecordedChanges (UseIndex, ScanKnown, MyersDiff) O.NoLookForMoves O.NoLookForReplaces repository files `catch` \(_ :: IOException) -> return (Sealed NilFL) -- this is triggered when repository is remote debugMessage "About to read the repository..." patches <- readRepo repository debugMessage "Done reading the repository." let normfp = fn2fp . normPath . fp2fn undoUnrecordedOnFPs = effectOnFilePaths (invert unrec) recFiles = map normfp . undoUnrecordedOnFPs . map toFilePath <$> files filtered_changes p = maybe_reverse <$> getLogInfo (maxCount ? opts) (parseFlags O.matchSeveralOrRange opts) (onlyToFiles ? opts) recFiles (maybeFilterPatches repository patches) p if isInteractive False opts then do (fp_and_fs, _, _) <- filtered_changes patches let fp = map fst fp_and_fs viewChanges (logPatchSelOpts opts) fp else do let header = if isJust files && hasXmlOutput opts then text $ "Changes to "++unwords (fromJust recFiles)++":\n" else empty debugMessage "About to print the patches..." let printers = if hasXmlOutput opts then simplePrinters else fancyPrinters ps <- readRepo repository -- read repo again to prevent holding onto -- values forced by filtered_changes logOutput <- changelog opts ps `fmap` filtered_changes patches viewDocWith printers $ header $$ logOutput where maybe_reverse (xs,b,c) = if changesReverse ? opts then (reverse xs, b, c) else (xs, b, c) logHelp' :: String logHelp' = unlines [ "When given files or directories paths as arguments, only patches which" , "affect those paths are listed. This includes patches that happened to" , "files before they were moved or renamed." , "" , "When given `--from-tag` or `--from-patch`, only patches since that tag" , "or patch are listed. Similarly, the `--to-tag` and `--to-patch`" , "options restrict the list to older patches." , "" , "The `--last` and `--max-count` options both limit the number of patches" , "listed. The former applies BEFORE other filters, whereas the latter" , "applies AFTER other filters. For example `darcs log foo.c" , "--max-count 3` will print the last three patches that affect foo.c," , "whereas `darcs log --last 3 foo.c` will, of the last three" , "patches, print only those that affect foo.c." , "" ] getLogInfo :: forall rt p wX wY . (IsRepoType rt, Matchable p, ApplyState p ~ Tree) => Maybe Int -> [MatchFlag] -> Bool -> Maybe [FilePath] -> PatchFilter rt p -> PatchSet rt p wX wY -> IO ( [(Sealed2 (PatchInfoAnd rt p), [FilePath])] , [(FilePath, FilePath)] , Maybe Doc ) getLogInfo maxCountFlag matchFlags onlyToFilesFlag plain_fs patchFilter ps = case (sp1s, sp2s) of (Sealed p1s, Sealed p2s) -> case findCommonWithThem p2s p1s of _ :> us -> let ps' = filterRL pf (reverseFL us) in case plain_fs of Nothing -> return $ foldr (\x xs -> (x, []) -:- xs) ([], [], Nothing) $ maybe id take maxCountFlag ps' Just fs -> let fs' = map (\x -> "./" ++ x) fs in do filterOutUnrelatedChanges <$> do ps'' <- patchFilter fs' ps' return $ filterPatchesByNames maxCountFlag fs' ps'' where sp1s = if firstMatch matchFlags then matchFirstPatchset matchFlags ps else Sealed $ PatchSet NilRL NilRL sp2s = if secondMatch matchFlags then matchSecondPatchset matchFlags ps else Sealed ps pf = if haveNonrangeMatch (PatchType :: PatchType rt p) matchFlags then matchAPatch matchFlags else \_ -> True filterOutUnrelatedChanges (pfs, renames, doc) | onlyToFilesFlag = (map onlyRelated pfs, renames, doc) | otherwise = (pfs, renames, doc) onlyRelated (Sealed2 p, fs) = (Sealed2 $ fmapFLPIAP (filterOutFLFL (unrelated fs)) (\_ -> ReflPatch) p, fs) unrelated fs p -- If the change does not affect the patches we are looking at, -- we ignore the difference between the two states. | null $ fs `intersect` listTouchedFiles p = unsafeCoerceP IsEq | otherwise = NotEq -- | Take a list of filenames and patches and produce a list of patches that -- actually touch the given files with a list of touched file names, a list of -- original-to-current filepath mappings, indicating the original names of the -- affected files and possibly an error. Additionaly, the function takes a -- "depth limit" -- maxcount, that could be Nothing (return everything) or -- "Just n" -- returns at most n patches touching the file (starting from the -- beginning of the patch list). filterPatchesByNames :: forall rt p . (Matchable p, ApplyState p ~ Tree) => Maybe Int -- ^ maxcount -> [FilePath] -- ^ filenames -> [Sealed2 (PatchInfoAnd rt p)] -- ^ patchlist -> ([(Sealed2 (PatchInfoAnd rt p),[FilePath])], [(FilePath, FilePath)], Maybe Doc) filterPatchesByNames maxcount fns patches = removeNonRenames $ evalState (filterPatchesByNames' fns patches) (maxcount, initRenames) where removeNonRenames (ps, renames, doc) = (ps, removeIds renames, doc) removeIds = filter $ uncurry (/=) initRenames = map (\x -> (x, x)) fns returnFinal = (\renames -> ([], renames, Nothing)) <$> gets snd filterPatchesByNames' [] _ = returnFinal filterPatchesByNames' _ [] = returnFinal filterPatchesByNames' fs (s2hp@(Sealed2 hp) : ps) = do (count, renames) <- get let stopNow = case count of Nothing -> False Just c -> c <= 0 if stopNow then returnFinal else case hopefullyM hp of Nothing -> do let err = text "Can't find patches prior to:" $$ displayPatchInfo (info hp) return ([], renames, Just err) Just p -> case lookTouch (Just renames) fs (invert p) of (True, affected, [], renames') -> return ([(s2hp, affected)], renames', Nothing) (True, affected, fs', renames') -> do let sub1Mb c = subtract 1 <$> c modify $ \(c, _) -> (sub1Mb c, renames') rest <- filterPatchesByNames' fs' ps return $ (s2hp, affected) -:- rest (False, _, fs', renames') -> do modify $ second (const renames') filterPatchesByNames' fs' ps -- | Note, lazy pattern matching is required to make functions like -- filterPatchesByNames lazy in case you are only not interested in -- the first element. E.g.: -- -- let (fs, _, _) = filterPatchesByNames ... (-:-) :: a -> ([a],b,c) -> ([a],b,c) x -:- ~(xs,y,z) = (x:xs,y,z) changelog :: forall rt p wStart wX . ( Apply p, ApplyState p ~ Tree, ShowPatch p, IsHunk p , PrimPatchBase p, PatchListFormat p , Conflict p, CommuteNoConflicts p ) => [DarcsFlag] -> PatchSet rt p wStart wX -> ([(Sealed2 (PatchInfoAnd rt p), [FilePath])], [(FilePath, FilePath)], Maybe Doc) -> Doc changelog opts patchset (pis_and_fs, createdAsFs, mbErr) | O.changesFormat ? opts == Just O.CountPatches = text $ show $ length pis_and_fs | hasXmlOutput opts = text "" $$ vcat created_as_xml $$ vcat actual_xml_changes $$ text "" | O.yes (O.summary ? opts) || verbose opts = mbAppendErr $ vsep (map (number_patch change_with_summary) pis) | otherwise = mbAppendErr $ vsep (map (number_patch description') pis) where mbAppendErr = maybe id (\err -> ($$ err)) mbErr change_with_summary :: Sealed2 (PatchInfoAnd rt p) -> Doc change_with_summary (Sealed2 hp) | Just p <- hopefullyM hp = if O.changesFormat ? opts == Just O.MachineReadable then showPatch ForStorage p else showFriendly (verbosity ? opts) (O.summary ? opts) p | otherwise = description hp $$ indent (text "[this patch is unavailable]") xml_with_summary (Sealed2 hp) | Just p <- hopefullyM hp = let deps = getdeps p xmlDependencies = text "" $$ vcat (map (indent . toXmlShort) deps) $$ text "" summary | deps == [] = indent $ xmlSummary p | otherwise = indent $ xmlDependencies $$ xmlSummary p in insertBeforeLastline (toXml $ info hp) summary xml_with_summary (Sealed2 hp) = toXml (info hp) indent = prefix " " actual_xml_changes = case O.summary ? opts of O.YesSummary -> map xml_with_summary pis O.NoSummary -> map (toXml . unseal2 info) pis created_as_xml = map create createdAsFs where create rename@(_, as) = createdAsXml (first_change_of as) rename -- We need to reorder the patches when they haven't been reversed -- already, so that we find the *first* patch that modifies a given -- file, not the last (by default, the list is oldest->newest). reorderer = if not (changesReverse ? opts) then reverse else id oldest_first_pis_and_fs = reorderer pis_and_fs couldnt_find fn = error $ "Couldn't find first patch affecting " ++ fn ++ " in pis_and_fs" mb_first_change_of fn = find ((fn `elem`) . snd) oldest_first_pis_and_fs find_first_change_of fn = fromMaybe (couldnt_find fn) (mb_first_change_of fn) first_change_of = unseal2 info . fst . find_first_change_of number_patch f x = if O.changesFormat ? opts == Just O.NumberPatches then case get_number x of Just n -> text (show n++":") <+> f x Nothing -> f x else f x get_number :: Sealed2 (PatchInfoAnd re p) -> Maybe Int get_number (Sealed2 y) = gn 1 (patchSet2RL patchset) where iy = info y gn :: Int -> RL (PatchInfoAnd rt p) wStart wY -> Maybe Int gn n (bs:<:b) | seq n (info b) == iy = Just n | otherwise = gn (n+1) bs gn _ NilRL = Nothing pis = map fst pis_and_fs description' = unseal2 description logHelp'' :: String logHelp'' = unlines [ "Four output formats exist. The default is `--human-readable`. The slightly" , "different `--machine-readable` format enables to see patch dependencies in" , "non-interactive mode. You can also select `--context`, which is an internal" , "format that can be re-read by Darcs (e.g. `darcs clone --context`)." , "" , "Finally, there is `--xml-output`, which emits valid XML... unless a the" , "patch metadata (author, name or description) contains a non-ASCII" , "character and was recorded in a non-UTF8 locale." ] logContext :: [DarcsFlag] -> IO () logContext opts = do let repodir = fromMaybe "." $ getRepourl opts withRepositoryLocation (useCache ? opts) repodir $ RepoJob $ \repository -> do (_ :> ps') <- contextPatches `fmap` readRepo repository let pis = mapRL seal2 ps' let header = text "\nContext:\n" let logOutput = maybe (vsep $ map (unseal2 (showPatchInfo ForStorage . info)) pis) errorDoc Nothing viewDocWith simplePrinters $ header $$ logOutput -- | changes is an alias for log changes :: DarcsCommand [DarcsFlag] changes = commandAlias "changes" Nothing log createdAsXml :: PatchInfo -> (String, String) -> Doc createdAsXml pinfo (current, createdAs) = text "" $$ toXml pinfo $$ text "" logPatchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions logPatchSelOpts flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = parseFlags O.matchSeveralOrRange flags , S.interactive = isInteractive False flags , S.selectDeps = O.PromptDeps -- option not supported, use default , S.summary = O.summary ? flags , S.withContext = withContext ? flags } darcs-2.14.5/src/Darcs/UI/Commands/MarkConflicts.hs0000644000000000000000000003144507346545000020073 0ustar0000000000000000-- Copyright (C) 2002-2003,2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE OverloadedStrings #-} module Darcs.UI.Commands.MarkConflicts ( markconflicts ) where import Prelude () import Darcs.Prelude import System.Exit ( exitSuccess ) import Data.List.Ordered ( nubSort, isect ) import Data.Maybe ( fromJust ) import Control.Monad ( when, unless ) import Control.Exception ( catch, IOException ) import Darcs.Util.Prompt ( promptYorn ) import Darcs.Util.SignalHandler ( withSignalsBlocked ) import Darcs.Util.Path ( AbsolutePath, SubPath, toFilePath, simpleSubPath ) import Darcs.Util.Printer ( Doc, putDocLnWith, text, redText, debugDocLn, vsep, (<+>), ($$) ) import Darcs.Util.Printer.Color ( fancyPrinters ) import Darcs.Util.Text ( pathlist ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInHashedRepository, putInfo ) import Darcs.UI.Commands.Util ( filterExistingPaths ) import Darcs.UI.Completion ( knownFileArgs ) import Darcs.UI.Flags ( DarcsFlag, diffingOpts, verbosity, dryRun, umask , useCache, fixSubPaths ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking (..) ) import Darcs.Repository ( withRepoLock , RepoJob(..) , addToPending , applyToWorking , readRepo , unrecordedChanges ) import Darcs.Patch ( invert, listTouchedFiles, effectOnFilePaths ) import Darcs.Patch.Show import Darcs.Patch.TouchesFiles ( chooseTouching ) import Darcs.Patch.Witnesses.Ordered ( FL(..), mapFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed) ) import Darcs.Repository.Resolution ( patchsetConflictResolutions ) -- * The mark-conflicts command markconflictsDescription :: String markconflictsDescription = "Mark unresolved conflicts in working tree, for manual resolution." markconflictsHelp :: String markconflictsHelp = unlines ["Darcs requires human guidance to unify changes to the same part of a" ,"source file. When a conflict first occurs, darcs will add the" ,"initial state and both choices to the working tree, delimited by the" ,"markers `v v v`, `=====`, `* * *` and `^ ^ ^`, as follows:" ,"" ," v v v v v v v" ," Initial state." ," =============" ," First choice." ," *************" ," Second choice." ," ^ ^ ^ ^ ^ ^ ^" ,"" ,"However, you might revert or manually delete these markers without" ,"actually resolving the conflict. In this case, `darcs mark-conflicts`" ,"is useful to show where are the unresolved conflicts. It is also" ,"useful if `darcs apply` or `darcs pull` is called with" ,"`--allow-conflicts`, where conflicts aren't marked initially." ,"" ,"Unless you use the `--dry-run` flag, any unrecorded changes to the" ,"affected files WILL be lost forever when you run this command!" ,"You will be prompted for confirmation before this takes place." ] markconflicts :: DarcsCommand [DarcsFlag] markconflicts = DarcsCommand { commandProgramName = "darcs" , commandName = "mark-conflicts" , commandHelp = markconflictsHelp , commandDescription = markconflictsDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[FILE or DIRECTORY]..."] , commandCommand = markconflictsCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = knownFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc markconflictsAdvancedOpts , commandBasicOptions = odesc markconflictsBasicOpts , commandDefaults = defaultFlags markconflictsOpts , commandCheckOptions = ocheck markconflictsOpts , commandParseOptions = onormalise markconflictsOpts } where markconflictsBasicOpts = O.useIndex ^ O.repoDir ^ O.diffAlgorithm ^ O.dryRunXml markconflictsAdvancedOpts = O.umask markconflictsOpts = markconflictsBasicOpts `withStdOpts` markconflictsAdvancedOpts markconflictsCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () markconflictsCmd fps opts args = do paths <- if null args then return Everything else sps2ps <$> fixSubPaths fps args -- Applicative IO debugDocLn $ "::: paths =" <+> (text . show) paths withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do {- What we do here: * read the unrecorded changes (all of them) * extract functions representing path rename effects from unrecorded * convert argument paths to pre-pending * read conflict resolutions that touch pre-pending argument paths * affected paths = intersection of paths touched by resolutions and pre-pending argument paths * for these paths, revert pending changes * apply the (filtered, see above) conflict resolutions Technical side-note: Ghc can't handle pattern bindings for existentials. So 'let' is out, one has to use 'case expr of var ->' or 'do var <- return expr'. Case is clearer but do-notation does not increase indentation depth. So we use case for small-scope bindings and <-/return when the scope is a long do block. -} let (useidx, scan, _) = diffingOpts opts verb = verbosity ? opts classified_paths <- traverse (filterExistingPaths repository verb useidx scan O.NoLookForMoves) paths unrecorded <- unrecordedChanges (diffingOpts opts) O.NoLookForMoves O.NoLookForReplaces repository (fromOnly Everything) let forward_renames = liftToPathSet (effectOnFilePaths unrecorded) backward_renames = liftToPathSet (effectOnFilePaths (invert unrecorded)) existing_paths = fmap snd classified_paths pre_pending_paths = backward_renames existing_paths debugDocLn $ "::: pre_pending_paths =" <+> (text . show) pre_pending_paths r <- readRepo repository Sealed res <- case patchsetConflictResolutions r of Sealed raw_res -> do let raw_res_paths = fps2ps (listTouchedFiles raw_res) debugDocLn $ "::: raw_res_paths =" <+> (text . show) raw_res_paths return $ chooseTouching (ps2fps pre_pending_paths) raw_res let res_paths = fps2ps (listTouchedFiles res) debugDocLn $ "::: res_paths =" <+> (text . show) res_paths let affected_paths = isectPathSet res_paths pre_pending_paths debugDocLn $ "::: affected_paths =" <+> (text . show) affected_paths when (affected_paths == Only []) $ do putInfo opts "No conflicts to mark." exitSuccess to_revert <- unrecordedChanges (diffingOpts opts) O.NoLookForMoves O.NoLookForReplaces repository (fromOnly affected_paths) let post_pending_affected_paths = forward_renames affected_paths putInfo opts $ "Marking conflicts in:" <+> showPathSet post_pending_affected_paths <> "." debugDocLn $ "::: to_revert =" $$ vsep (mapFL displayPatch to_revert) debugDocLn $ "::: res = " $$ vsep (mapFL displayPatch res) when (O.yes (dryRun ? opts)) $ do putInfo opts $ "Conflicts will not be marked: this is a dry run." exitSuccess repository' <- case to_revert of NilFL -> return repository _ -> do -- TODO: -- (1) create backups for all files where we revert changes -- (2) try to add the reverted stuff to the unrevert bundle -- after (1) and (2) is done we can soften the warning below putDocLnWith fancyPrinters $ "Warning: This will revert all unrecorded changes in:" <+> showPathSet post_pending_affected_paths <> "." $$ redText "These changes will be LOST." confirmed <- promptYorn "Are you sure? " unless confirmed exitSuccess {- -- copied from Revert.hs, see comment (2) above debugMessage "About to write the unrevert file." case commute (norevert:>p) of Just (p':>_) -> writeUnrevert repository p' recorded NilFL Nothing -> writeUnrevert repository (norevert+>+p) recorded NilFL debugMessage "About to apply to the working directory." -} let to_add = invert to_revert addToPending repository YesUpdateWorking to_add applyToWorking repository (verbosity ? opts) to_add `catch` \(e :: IOException) -> bug ("Can't undo pending changes!" ++ show e) withSignalsBlocked $ do addToPending repository' YesUpdateWorking res _ <- applyToWorking repository' (verbosity ? opts) res `catch` \(e :: IOException) -> bug ("Problem marking conflicts in mark-conflicts!" ++ show e) return () putInfo opts "Finished marking conflicts." -- * Generic 'PathSet' support {- $SupportCode What follows is generic support code for working with argument path lists that are used to restrict operations to a subset of the working or pristine tree. The rest of Darcs uses two types for this: * @'Maybe' ['SubPath']@ * @'Maybe' ['FilePath']@ The problem with both is the contra-intuitive name 'Nothing', which here stands for 'Everything'. To make the intended use clearer, we use the 'Only' type instead (which is is isomorphic to 'Maybe') and the synonym 'PathSet' defined below. These abstractions should get their own module (or become integrated into Darcs.Util.Path) if and when someone decides to reuse it elsewhere. The functionality provided is intentionally minimal and light-weight. -} -- | 'Only' is isomorphic to 'Maybe' but with the opposite semantics. -- -- About the name: I like the data constructor names, they are pretty -- suggestive. The data type name is up for grabs; a possible alternative -- is @AtMost@. data Only a = Everything | Only a deriving (Eq, Ord, Show) instance Functor Only where fmap _ Everything = Everything fmap f (Only x) = Only (f x) instance Foldable Only where foldMap _ Everything = mempty foldMap f (Only x) = f x instance Traversable Only where traverse _ Everything = pure Everything traverse f (Only x) = Only <$> f x -- | This is mostly for conversion to legacy APIs fromOnly :: Only a -> Maybe a fromOnly Everything = Nothing fromOnly (Only x) = Just x {- | A set of repository paths. 'Everything' means every path in the repo, it usually originates from an empty list of path arguments. The list of 'SubPath's is always kept in sorted order with no duplicates and normalised (as in 'FilePath.normalise'). This has the nice effect of getting rid of the idiotic "./" that Darcs insists on prepending to repo paths (which can make things like comparing paths returned from different parts of the code base a nightmare). It uses 'SubPath' for easier compatibility and lists because the number of elements is expected to be small. -} type PathSet = Only [SubPath] -- | Intersection of two 'PathSet's isectPathSet :: PathSet -> PathSet -> PathSet isectPathSet Everything ys = ys isectPathSet xs Everything = xs isectPathSet (Only xs) (Only ys) = Only (isect xs ys) {- -- | Union of two 'PathSet's union :: PathSet -> PathSet -> PathSet union Everything ys = Everything union xs Everything = Everything union (Only xs) (Only ys) = Only (union xs ys) -} -- | Convert a list of 'SubPath's to a 'PathSet'. sps2ps :: [SubPath] -> PathSet sps2ps = Only . nubSort -- | Convert a list of repo paths to a 'PathSet'. -- Partial function! Use only with repo paths. fps2ps :: [FilePath] -> PathSet fps2ps = sps2ps . map fp2sp -- | Convert a 'PathSet' to something that e.g. 'chooseTouching' -- takes as parameter. ps2fps :: PathSet -> Maybe [FilePath] ps2fps = fmap (map sp2fp) . fromOnly -- | Convert a 'PathSet' to a 'Doc'. Uses the English module -- to generate a nicely readable list of file names. showPathSet :: Only [SubPath] -> Doc showPathSet Everything = text "all paths" showPathSet (Only xs) = pathlist (map sp2fp xs) -- | Lift a function transforming a list of 'FilePath' to one that -- transforms a 'PathSet'. liftToPathSet :: ([FilePath] -> [FilePath]) -> PathSet -> PathSet liftToPathSet f = fmap (nubSort . map fp2sp . f . map sp2fp) -- | Convert a 'FilePath' to a 'SubPath'. -- -- Note: Should call this only with paths we get from the repository. -- This guarantees that they are relative (to the repo dir). fp2sp :: FilePath -> SubPath fp2sp = fromJust . simpleSubPath -- | Convert a 'SubPath' to a 'FilePath'. Same as 'toFilePath' and -- only here for symmetry. sp2fp :: SubPath -> FilePath sp2fp = toFilePath darcs-2.14.5/src/Darcs/UI/Commands/Move.hs0000644000000000000000000003545407346545000016246 0ustar0000000000000000{-# LANGUAGE RankNTypes #-} -- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Move ( move, mv ) where import Prelude () import Darcs.Prelude import Control.Monad ( when, unless, forM_, forM ) import Data.Maybe ( fromMaybe ) import Darcs.Util.SignalHandler ( withSignalsBlocked ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, commandAlias, amInHashedRepository , putInfo ) import Darcs.UI.Completion ( knownFileArgs ) import Darcs.UI.Flags ( DarcsFlag , allowCaseDifferingFilenames, allowWindowsReservedFilenames , useCache, dryRun, umask , maybeFixSubPaths, fixSubPaths ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Diff ( treeDiff ) import Darcs.Repository.Flags ( UpdateWorking (..), DiffAlgorithm(..) ) import Darcs.Repository.Prefs ( filetypeFunction ) import System.FilePath.Posix ( (), takeFileName ) import System.Directory ( renameDirectory ) import Darcs.Repository.State ( readRecordedAndPending, readRecorded, updateIndex ) import Darcs.Repository ( Repository , withRepoLock , RepoJob(..) , addPendingDiffToPending ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (+>+) ) import Darcs.Patch.Witnesses.Sealed ( emptyGap, freeGap, joinGap, FreeLeft ) import Darcs.Util.Global ( debugMessage ) import qualified Darcs.Patch import Darcs.Patch ( RepoPatch, PrimPatch ) import Darcs.Patch.Apply( ApplyState ) import Data.List ( nub, sort ) import qualified System.FilePath.Windows as WindowsFilePath import Darcs.UI.Commands.Util.Tree ( treeHas, treeHasDir, treeHasAnycase, treeHasFile ) import Darcs.Util.Tree( Tree, modifyTree ) import Darcs.Util.Tree.Plain( readPlainTree ) import Darcs.Util.Path ( floatPath , fp2fn , fn2fp , superName , SubPath() , toFilePath , AbsolutePath ) import Darcs.Util.Printer ( text, hsep ) import Darcs.Util.Workaround ( renameFile ) moveDescription :: String moveDescription = "Move or rename files." moveHelp :: String moveHelp = "Darcs cannot reliably distinguish between a file being deleted and a\n" ++ "new one added, and a file being moved. Therefore Darcs always assumes\n" ++ "the former, and provides the `darcs mv` command to let Darcs know when\n" ++ "you want the latter. This command will also move the file in the\n" ++ "working tree (unlike `darcs remove`), unless it has already been moved.\n" ++ "\n" ++ -- Note that this paragraph is very similar to one in ./Add.lhs. "Darcs will not rename a file if another file in the same folder has\n" ++ "the same name, except for case. The `--case-ok` option overrides this\n" ++ "behaviour. Windows and OS X usually use filesystems that do not allow\n" ++ "files a folder to have the same name except for case (for example,\n" ++ "`ReadMe` and `README`). If `--case-ok` is used, the repository might be\n" ++ "unusable on those systems!\n" move :: DarcsCommand [DarcsFlag] move = DarcsCommand { commandProgramName = "darcs" , commandName = "move" , commandHelp = moveHelp , commandDescription = moveDescription , commandExtraArgs = -1 , commandExtraArgHelp = [" ... "] , commandCommand = moveCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = knownFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc moveAdvancedOpts , commandBasicOptions = odesc moveBasicOpts , commandDefaults = defaultFlags moveOpts , commandCheckOptions = ocheck moveOpts , commandParseOptions = onormalise moveOpts } where moveBasicOpts = O.allowProblematicFilenames ^ O.repoDir moveAdvancedOpts = O.umask moveOpts = moveBasicOpts `withStdOpts` moveAdvancedOpts moveCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () moveCmd fps opts args | length args < 2 = fail "The `darcs move' command requires at least two arguments." | length args == 2 = do -- NOTE: The extra case for two arguments is necessary because -- in this case we allow file -> file moves. Whereas with 3 or -- more arguments the last one (i.e. the target) must be a directory. xs <- maybeFixSubPaths fps args case xs of [Just from, Just to] | from == to -> fail "Cannot rename a file or directory onto itself." | toFilePath from == "" -> fail "Cannot move the root of the repository." | otherwise -> moveFile opts from to _ -> fail "Both source and destination must be valid." | otherwise = let (froms, to) = (init args, last args) in do x <- head <$> maybeFixSubPaths fps [to] case x of Nothing -> fail "Invalid destination directory." Just to' -> do xs <- nub . sort <$> fixSubPaths fps froms if to' `elem` xs then fail "Cannot rename a file or directory onto itself." else case xs of [] -> fail "Nothing to move." froms' -> if or (map (null . toFilePath) froms') then fail "Cannot move the root of the repository." else moveFilesToDir opts froms' to' data FileKind = Dir | File deriving (Show, Eq) data FileStatus = Nonexistant | Unadded FileKind | Shadow FileKind -- ^ known to darcs, but absent in working copy | Known FileKind deriving Show fileStatus :: Tree IO -- ^ tree of the working directory -> Tree IO -- ^ tree of recorded and pending changes -> Tree IO -- ^ tree of recorded changes -> FilePath -> IO FileStatus fileStatus work cur recorded fp = do existsInCur <- treeHas cur fp existsInRec <- treeHas recorded fp existsInWork <- treeHas work fp case (existsInRec, existsInCur, existsInWork) of (_, True, True) -> do isDirCur <- treeHasDir cur fp isDirWork <- treeHasDir work fp unless (isDirCur == isDirWork) . fail $ "don't know what to do with " ++ fp return . Known $ if isDirCur then Dir else File (_, False, True) -> do isDir <- treeHasDir work fp if isDir then return $ Unadded Dir else return $ Unadded File (False, False, False) -> return Nonexistant (_, _, False) -> do isDir <- treeHasDir cur fp if isDir then return $ Shadow Dir else return $ Shadow File -- | Takes two filenames (as 'Subpath'), and tries to move the first -- into/onto the second. Needs to guess what that means: renaming or moving -- into a directory, and whether it is a post-hoc move. moveFile :: [DarcsFlag] -> SubPath -> SubPath -> IO () moveFile opts old new = withRepoAndState opts $ \(repo, work, cur, recorded) -> do let old_fp = toFilePath old new_fp = toFilePath new new_fs <- fileStatus work cur recorded new_fp old_fs <- fileStatus work cur recorded old_fp let doSimpleMove = simpleMove repo opts cur work old_fp new_fp case (old_fs, new_fs) of (Nonexistant, _) -> fail $ old_fp ++ " does not exist." (Unadded k, _) -> fail $ show k ++ " " ++ old_fp ++ " is unadded." (Known _, Nonexistant) -> doSimpleMove (Known _, Shadow _) -> doSimpleMove (_, Nonexistant) -> fail $ old_fp ++ " is not in the repository." (Known _, Known Dir) -> moveToDir repo opts cur work [old_fp] new_fp (Known _, Unadded Dir) -> fail $ new_fp ++ " is not known to darcs; please add it to the repository." (Known _, _) -> fail $ new_fp ++ " already exists." (Shadow k, Unadded k') | k == k' -> doSimpleMove (Shadow File, Known Dir) -> moveToDir repo opts cur work [old_fp] new_fp (Shadow Dir, Known Dir) -> doSimpleMove (Shadow File, Known File) -> doSimpleMove (Shadow k, _) -> fail $ "cannot move " ++ show k ++ " " ++ old_fp ++ " into " ++ new_fp ++ " : " ++ "did you already move it elsewhere?" moveFilesToDir :: [DarcsFlag] -> [SubPath] -> SubPath -> IO () moveFilesToDir opts froms to = withRepoAndState opts $ \(repo, work, cur, _) -> moveToDir repo opts cur work (map toFilePath froms) $ toFilePath to withRepoAndState :: [DarcsFlag] -> (forall rt p wR wU . (ApplyState p ~ Tree, RepoPatch p) => (Repository rt p wR wU wR, Tree IO, Tree IO, Tree IO) -> IO ()) -> IO () withRepoAndState opts f = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repo -> do work <- readPlainTree "." cur <- readRecordedAndPending repo recorded <- readRecorded repo f (repo, work, cur, recorded) simpleMove :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> [DarcsFlag] -> Tree IO -> Tree IO -> FilePath -> FilePath -> IO () simpleMove repository opts cur work old_fp new_fp = do doMoves repository opts cur work [(old_fp, new_fp)] putInfo opts $ hsep $ map text ["Moved:", old_fp, "to:", new_fp] moveToDir :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> [DarcsFlag] -> Tree IO -> Tree IO -> [FilePath] -> FilePath -> IO () moveToDir repository opts cur work moved finaldir = do let movetargets = map ((finaldir ) . takeFileName) moved moves = zip moved movetargets doMoves repository opts cur work moves putInfo opts $ hsep $ map text $ ["Moved:"] ++ moved ++ ["to:", finaldir] doMoves :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> [DarcsFlag] -> Tree IO -> Tree IO -> [(FilePath, FilePath)] -> IO () doMoves repository opts cur work moves = do patches <- forM moves $ \(old, new) -> do prePatch <- generatePreMovePatches opts cur work (old,new) return (prePatch, old, new) withSignalsBlocked $ do forM_ patches $ \(prePatch, old, new) -> do let -- Add any pre patches before the move patch pendingDiff = joinGap (+>+) (fromMaybe (emptyGap NilFL) prePatch) (freeGap $ Darcs.Patch.move old new :>: NilFL) addPendingDiffToPending repository YesUpdateWorking pendingDiff moveFileOrDir work old new updateIndex repository -- Take the recorded/ working trees and the old and intended new filenames; -- check if the new path is safe on windows. We potentially need to create -- extra patches that are required to keep the repository consistent, in order -- to allow the move patch to be applied. generatePreMovePatches :: PrimPatch prim => [DarcsFlag] -> Tree IO -> Tree IO -> (FilePath, FilePath) -> IO (Maybe (FreeLeft (FL prim))) generatePreMovePatches opts cur work (old,new) = do -- Only allow Windows-invalid paths if we've been told to do so unless newIsOkWindowsPath $ fail newNotOkWindowsPathMsg -- Check if the first directory above the new path is in the repo (this -- is the new path if itself is a directory), handling the case where -- a user moves a file into a directory not known by darcs. let dirPath = fn2fp $ superName $ fp2fn new haveNewParent <- treeHasDir cur dirPath unless haveNewParent $ fail $ "The target directory " ++ dirPath ++ " isn't known in the repository, did you forget to add it?" newInRecorded <- hasNew cur newInWorking <- hasNew work oldInWorking <- treeHas work old if oldInWorking -- We need to move the object then do -- We can't move if the target already exists in working when newInWorking $ fail $ alreadyExists "working directory" if newInRecorded then Just <$> deleteNewFromRepoPatches else return Nothing else do putInfo opts $ text "Detected post-hoc move." -- Post-hoc move - user has moved/deleted the file in working, so -- we can hopefully make a move patch to make the repository -- consistent. -- If we don't have the old or new in working, we're stuck unless newInWorking $ fail $ "Cannot determine post-hoc move target, " ++ "no file/dir named:\n" ++ new Just <$> if newInRecorded then deleteNewFromRepoPatches else return $ emptyGap NilFL where newIsOkWindowsPath = allowWindowsReservedFilenames ? opts || WindowsFilePath.isValid new newNotOkWindowsPathMsg = "The filename " ++ new ++ " is not valid under Windows.\n" ++ "Use --reserved-ok to allow such filenames." -- If we're moving to a file/dir that was recorded, but has been deleted, -- we need to add patches to pending that remove the original. deleteNewFromRepoPatches = do putInfo opts $ text $ "Existing recorded contents of " ++ new ++ " will be overwritten." ftf <- filetypeFunction let curNoNew = modifyTree cur (floatPath new) Nothing -- Return patches to remove new, so that the move patch -- can move onto new treeDiff MyersDiff ftf cur curNoNew -- Check if the passed tree has the new filepath. The old path is removed -- from the tree before checking if the new path is present. hasNew s = treeHas_case (modifyTree s (floatPath old) Nothing) new treeHas_case = if allowCaseDifferingFilenames ? opts then treeHas else treeHasAnycase alreadyExists inWhat = if allowCaseDifferingFilenames ? opts then "A file or dir named "++new++" already exists in " ++ inWhat ++ "." else "A file or dir named "++new++" (or perhaps differing " ++ "only in case)\nalready exists in "++ inWhat ++ ".\n" ++ "Use --case-ok to allow files differing only in case." moveFileOrDir :: Tree IO -> FilePath -> FilePath -> IO () moveFileOrDir work old new = do has_file <- treeHasFile work old has_dir <- treeHasDir work old when has_file $ do debugMessage $ unwords ["renameFile",old,new] renameFile old new when has_dir $ do debugMessage $ unwords ["renameDirectory",old,new] renameDirectory old new mv :: DarcsCommand [DarcsFlag] mv = commandAlias "mv" Nothing move darcs-2.14.5/src/Darcs/UI/Commands/Optimize.hs0000644000000000000000000006043007346545000017130 0ustar0000000000000000-- Copyright (C) 2003-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE OverloadedStrings #-} module Darcs.UI.Commands.Optimize ( optimize ) where import Prelude () import Darcs.Prelude import Control.Monad ( when, unless, forM_ ) import Data.List ( nub ) import Data.Maybe ( fromJust, isJust ) import System.Directory ( getDirectoryContents , doesDirectoryExist , renameFile , createDirectoryIfMissing , removeFile , getHomeDirectory ) import qualified Data.ByteString.Char8 as BC import Darcs.UI.Commands ( DarcsCommand(..), nodefaults , amInHashedRepository, amInRepository, putInfo , normalCommand, withStdOpts ) import Darcs.UI.Completion ( noArgs ) import Darcs.Repository.Prefs ( getPreflist, getCaches, globalCacheDir ) import Darcs.Repository ( Repository , repoLocation , withRepoLock , RepoJob(..) , readRepo , reorderInventory , cleanRepository , replacePristine ) import Darcs.Repository.Job ( withOldRepoLock ) import Darcs.Repository.Identify ( findAllReposInDir ) import Darcs.Repository.Hashed ( inventoriesDir, patchesDir, pristineDir, hashedInventory, listInventoriesRepoDir, listPatchesLocalBucketed, diffHashLists, peekPristineHash ) import Darcs.Repository.Packs ( createPacks ) import Darcs.Repository.Pending ( pendingName ) import Darcs.Repository.HashedIO ( getHashedFiles ) import Darcs.Patch.Witnesses.Ordered ( mapFL , bunchFL , lengthRL ) import Darcs.Patch ( IsRepoType, RepoPatch ) import Darcs.Patch.Set ( patchSet2RL , patchSet2FL , progressPatchSet ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Util.ByteString ( gzReadFilePS ) import Darcs.Util.Printer ( text ) import Darcs.Util.Lock ( maybeRelink , gzWriteAtomicFilePS , writeAtomicFilePS , rmRecursive , removeFileMayNotExist , writeBinFile ) import Darcs.Util.File ( withCurrentDirectory , getRecursiveContents , doesDirectoryReallyExist ) import Darcs.UI.External ( catchall ) import Darcs.Util.Progress ( beginTedious , endTedious , tediousSize , debugMessage ) import Darcs.Util.Global ( darcsdir ) import System.FilePath.Posix ( takeExtension , () , joinPath ) import Text.Printf ( printf ) import Darcs.UI.Flags ( DarcsFlag, verbosity, useCache, umask ) import Darcs.UI.Options ( DarcsOption, (^), oid, odesc, ocheck, onormalise , defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking (..), DryRun ( NoDryRun ), UseCache (..), UMask (..) , WithWorkingDir(WithWorkingDir), PatchFormat(PatchFormat1) ) import Darcs.Patch.Progress ( progressFL ) import Darcs.Repository.Cache ( hashedDir, bucketFolder, HashedDir(HashedPristineDir) ) import Darcs.Repository.Format ( identifyRepoFormat , createRepoFormat , writeRepoFormat , formatHas , RepoProperty ( HashedInventory ) ) import Darcs.Repository.PatchIndex import qualified Darcs.Repository.Hashed as HashedRepo import Darcs.Repository.State ( readRecorded ) import Darcs.Util.Tree ( Tree , TreeItem(..) , list , expand , emptyTree ) import Darcs.Util.Path( anchorPath, toFilePath, AbsolutePath ) import Darcs.Util.Tree.Plain( readPlainTree ) import Darcs.Util.Tree.Hashed ( writeDarcsHashed , decodeDarcsSize ) optimizeDescription :: String optimizeDescription = "Optimize the repository." optimizeHelp :: String optimizeHelp = "The `darcs optimize` command modifies the current repository in an\n" ++ "attempt to reduce its resource requirements." optimize :: DarcsCommand [DarcsFlag] optimize = SuperCommand { commandProgramName = "darcs" , commandName = "optimize" , commandHelp = optimizeHelp , commandDescription = optimizeDescription , commandPrereq = amInRepository , commandSubCommands = [ normalCommand optimizeClean, normalCommand optimizeHttp, normalCommand optimizeReorder, normalCommand optimizeEnablePatchIndex, normalCommand optimizeDisablePatchIndex, normalCommand optimizeCompress, normalCommand optimizeUncompress, normalCommand optimizeRelink, normalCommand optimizePristine, normalCommand optimizeUpgrade, normalCommand optimizeGlobalCache ] } commonBasicOpts :: DarcsOption a (Maybe String -> UMask -> a) commonBasicOpts = O.repoDir ^ O.umask commonAdvancedOpts :: DarcsOption a a commonAdvancedOpts = oid common :: DarcsCommand [DarcsFlag] common = DarcsCommand { commandProgramName = "darcs" , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandPrereq = amInHashedRepository , commandArgdefaults = nodefaults , commandName = undefined , commandHelp = undefined , commandDescription = undefined , commandCommand = undefined , commandCompleteArgs = noArgs , commandAdvancedOptions = odesc commonAdvancedOpts , commandBasicOptions = odesc commonBasicOpts , commandDefaults = defaultFlags commonOpts , commandCheckOptions = ocheck commonOpts , commandParseOptions = onormalise commonOpts } where commonOpts = commonBasicOpts `withStdOpts` commonAdvancedOpts optimizeClean :: DarcsCommand [DarcsFlag] optimizeClean = common { commandName = "clean" , commandHelp = "This command deletes obsolete files within the repository." , commandDescription = "garbage collect pristine, inventories and patches" , commandCommand = optimizeCleanCmd } optimizeCleanCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizeCleanCmd _ opts _ = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do cleanRepository repository -- garbage collect pristine.hashed, inventories and patches directories putInfo opts "Done cleaning repository!" optimizeUpgrade :: DarcsCommand [DarcsFlag] optimizeUpgrade = common { commandName = "upgrade" , commandHelp = "Convert old-fashioned repositories to the current default hashed format." , commandDescription = "upgrade repository to latest compatible format" , commandPrereq = amInRepository , commandCommand = optimizeUpgradeCmd } optimizeHttp :: DarcsCommand [DarcsFlag] optimizeHttp = common { commandName = "http" , commandHelp = optimizeHelpHttp , commandDescription = "optimize repository for getting over network" , commandCommand = optimizeHttpCmd } optimizeHttpCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizeHttpCmd _ opts _ = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do cleanRepository repository -- garbage collect pristine.hashed, inventories and patches directories createPacks repository putInfo opts "Done creating packs!" optimizePristine :: DarcsCommand [DarcsFlag] optimizePristine = common { commandName = "pristine" , commandHelp = "This command updates the format of `_darcs/pristine.hashed/`, which was different\n" ++ "before darcs 2.3.1." , commandDescription = "optimize hashed pristine layout" , commandCommand = optimizePristineCmd } optimizePristineCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizePristineCmd _ opts _ = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do cleanRepository repository -- garbage collect pristine.hashed, inventories and patches directories doOptimizePristine opts repository putInfo opts "Done optimizing pristine!" optimizeCompress :: DarcsCommand [DarcsFlag] optimizeCompress = common { commandName = "compress" , commandHelp = optimizeHelpCompression , commandDescription = "compress patches and inventories" , commandCommand = optimizeCompressCmd } optimizeUncompress :: DarcsCommand [DarcsFlag] optimizeUncompress = common { commandName = "uncompress" , commandHelp = optimizeHelpCompression , commandDescription = "uncompress patches and inventories" , commandCommand = optimizeUncompressCmd } optimizeCompressCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizeCompressCmd _ opts _ = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do cleanRepository repository -- garbage collect pristine.hashed, inventories and patches directories optimizeCompression O.GzipCompression opts putInfo opts "Done optimizing by compression!" optimizeUncompressCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizeUncompressCmd _ opts _ = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do cleanRepository repository -- garbage collect pristine.hashed, inventories and patches directories optimizeCompression O.NoCompression opts putInfo opts "Done optimizing by uncompression!" optimizeCompression :: O.Compression -> [DarcsFlag] -> IO () optimizeCompression compression opts = do putInfo opts "Optimizing (un)compression of patches..." do_compress (darcsdir ++ "/patches") putInfo opts "Optimizing (un)compression of inventories..." do_compress (darcsdir ++ "/inventories") where do_compress f = do isd <- doesDirectoryExist f if isd then withCurrentDirectory f $ do fs <- filter notdot `fmap` getDirectoryContents "." mapM_ do_compress fs else gzReadFilePS f >>= case compression of O.GzipCompression -> gzWriteAtomicFilePS f O.NoCompression -> writeAtomicFilePS f notdot ('.':_) = False notdot _ = True optimizeEnablePatchIndex :: DarcsCommand [DarcsFlag] optimizeEnablePatchIndex = common { commandName = "enable-patch-index" , commandHelp = "Build the patch index, an internal data structure that accelerates\n" ++ "commands that need to know what patches touch a given file. Such as\n" ++ "annotate and log." , commandDescription = "Enable patch index" , commandCommand = optimizeEnablePatchIndexCmd } optimizeDisablePatchIndex :: DarcsCommand [DarcsFlag] optimizeDisablePatchIndex = common { commandName = "disable-patch-index" , commandHelp = "Delete and stop maintaining the patch index from the repository." , commandDescription = "Disable patch index" , commandCommand = optimizeDisablePatchIndexCmd } optimizeEnablePatchIndexCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizeEnablePatchIndexCmd _ opts _ = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do ps <- readRepo repository createOrUpdatePatchIndexDisk repository ps putInfo opts "Done enabling patch index!" optimizeDisablePatchIndexCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizeDisablePatchIndexCmd _ opts _ = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repo -> do deletePatchIndex (repoLocation repo) putInfo opts "Done disabling patch index!" optimizeReorder :: DarcsCommand [DarcsFlag] optimizeReorder = common { commandName = "reorder" , commandHelp = "This command moves recent patches (those not included in\n" ++ "the latest tag) to the \"front\", reducing the amount that a typical\n" ++ "remote command needs to download. It should also reduce the CPU time\n" ++ "needed for some operations." , commandDescription = "reorder the patches in the repository" , commandCommand = optimizeReorderCmd } optimizeReorderCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizeReorderCmd _ opts _ = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do reorderInventory repository (O.compress ? opts) YesUpdateWorking (verbosity ? opts) putInfo opts "Done reordering!" optimizeRelink :: DarcsCommand [DarcsFlag] optimizeRelink = common { commandName = "relink" , commandHelp = optimizeHelpRelink , commandDescription = "relink random internal data to a sibling" , commandCommand = optimizeRelinkCmd , commandAdvancedOptions = odesc commonAdvancedOpts , commandBasicOptions = odesc optimizeRelinkBasicOpts , commandDefaults = defaultFlags optimizeRelinkOpts , commandCheckOptions = ocheck optimizeRelinkOpts , commandParseOptions = onormalise optimizeRelinkOpts } where optimizeRelinkBasicOpts = commonBasicOpts ^ O.siblings optimizeRelinkOpts = optimizeRelinkBasicOpts `withStdOpts` commonAdvancedOpts optimizeRelinkCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizeRelinkCmd _ opts _ = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do cleanRepository repository -- garbage collect pristine.hashed, inventories and patches directories doRelink opts putInfo opts "Done relinking!" optimizeHelpHttp :: String optimizeHelpHttp = unlines [ "Using this option creates 'repository packs' that could dramatically" , "speed up performance when a user does a `darcs clone` of the repository" , "over HTTP. To make use of packs, the clients must have a darcs of at" , "least version 2.10." ] optimizeHelpCompression :: String optimizeHelpCompression = "By default patches are compressed with zlib (RFC 1951) to reduce\n" ++ "storage (and download) size. In exceptional circumstances, it may be\n" ++ "preferable to avoid compression. In this case the `--dont-compress`\n" ++ "option can be used (e.g. with `darcs record`) to avoid compression.\n" ++ "\n" ++ "The `darcs optimize uncompress` and `darcs optimize compress`\n" ++ "commands can be used to ensure existing patches in the current\n" ++ "repository are respectively uncompressed or compressed." optimizeHelpRelink :: String optimizeHelpRelink = "The `darcs optimize relink` command hard-links patches that the\n" ++ "current repository has in common with its peers. Peers are those\n" ++ "repositories listed in `_darcs/prefs/sources`, or defined with the\n" ++ "`--sibling` option (which can be used multiple times).\n" ++ "\n" ++ "Darcs uses hard-links automatically, so this command is rarely needed.\n" ++ "It is most useful if you used `cp -r` instead of `darcs clone` to copy a\n" ++ "repository, or if you pulled the same patch from a remote repository\n" ++ "into multiple local repositories." doOptimizePristine :: [DarcsFlag] -> Repository rt p wR wU wT -> IO () doOptimizePristine opts repo = do inv <- BC.readFile (darcsdir "hashed_inventory") let linesInv = BC.split '\n' inv case linesInv of [] -> return () (pris_line:_) -> let size = decodeDarcsSize $ BC.drop 9 pris_line in when (isJust size) $ do putInfo opts "Optimizing hashed pristine..." readRecorded repo >>= replacePristine repo cleanRepository repo doRelink :: [DarcsFlag] -> IO () doRelink opts = do let some_siblings = parseFlags O.siblings opts defrepolist <- getPreflist "defaultrepo" let siblings = map toFilePath some_siblings ++ defrepolist if null siblings then putInfo opts "No siblings -- no relinking done." else do debugMessage "Relinking patches..." patch_tree <- expand =<< readPlainTree (darcsdir "patches") let patches = [ anchorPath "" p | (p, File _) <- list patch_tree ] maybeRelinkFiles siblings patches $ darcsdir "patches" debugMessage "Done relinking." maybeRelinkFiles :: [String] -> [String] -> String -> IO () maybeRelinkFiles src dst dir = mapM_ (maybeRelinkFile src . ((dir ++ "/") ++)) dst maybeRelinkFile :: [String] -> String -> IO () maybeRelinkFile [] _ = return () maybeRelinkFile (h:t) f = do done <- maybeRelink (h ++ "/" ++ f) f unless done $ maybeRelinkFile t f -- Only 'optimize' commands that works on old-fashionned repositories optimizeUpgradeCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizeUpgradeCmd _ opts _ = do rf <- identifyRepoFormat "." debugMessage "Found our format" if formatHas HashedInventory rf then putInfo opts "No action taken because this repository already is hashed." else do putInfo opts "Upgrading to hashed..." withOldRepoLock $ RepoJob actuallyUpgradeFormat actuallyUpgradeFormat :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> IO () actuallyUpgradeFormat repository = do -- convert patches/inventory patches <- readRepo repository let k = "Hashing patch" beginTedious k tediousSize k (lengthRL $ patchSet2RL patches) let patches' = progressPatchSet k patches cache <- getCaches YesUseCache "." -- TODO Why use the default and not what the user provided? -- Is it because the author couldn't be bothered to add the option? -- Or is there a more profound reason? -- Such things justify a few lines of comment! let compressDefault = O.compress ? [] HashedRepo.writeTentativeInventory cache compressDefault patches' endTedious k -- convert pristine by applying patches -- the faster alternative would be to copy pristine, but the apply method is more reliable let patchesToApply = progressFL "Applying patch" $ patchSet2FL patches' createDirectoryIfMissing False $ darcsdir hashedDir HashedPristineDir -- We ignore the returned root hash, we don't use it. _ <- writeDarcsHashed emptyTree $ darcsdir hashedDir HashedPristineDir writeBinFile (darcsdir++"/tentative_pristine") "" sequence_ $ mapFL HashedRepo.applyToTentativePristineCwd $ bunchFL 100 patchesToApply -- now make it official HashedRepo.finalizeTentativeChanges repository compressDefault writeRepoFormat (createRepoFormat PatchFormat1 WithWorkingDir) (darcsdir "format") -- clean out old-fashioned junk debugMessage "Cleaning out old-fashioned repository files..." removeFileMayNotExist $ darcsdir "inventory" removeFileMayNotExist $ darcsdir "tentative_inventory" rmRecursive (darcsdir "pristine") `catchall` rmRecursive (darcsdir "current") rmGzsIn (darcsdir "patches") rmGzsIn (darcsdir "inventories") let checkpointDir = darcsdir "checkpoints" hasCheckPoints <- doesDirectoryExist checkpointDir when hasCheckPoints $ rmRecursive checkpointDir removeFileMayNotExist (pendingName ++ ".tentative") removeFileMayNotExist pendingName where rmGzsIn dir = withCurrentDirectory dir $ do gzs <- filter ((== ".gz") . takeExtension) `fmap` getDirectoryContents "." mapM_ removeFile gzs optimizeBucketed :: [DarcsFlag] -> IO () optimizeBucketed opts = do putInfo opts "Migrating global cache to bucketed format." gCacheDir <- globalCacheDir case gCacheDir of Nothing -> fail "New global cache doesn't exist." Just gCacheDir' -> do let gCachePristineDir = joinPath [gCacheDir', pristineDir] gCacheInventoriesDir = joinPath [gCacheDir', inventoriesDir] gCachePatchesDir = joinPath [gCacheDir', patchesDir] debugMessage "Making bucketed cache from new cache." toBucketed gCachePristineDir gCachePristineDir toBucketed gCacheInventoriesDir gCacheInventoriesDir toBucketed gCachePatchesDir gCachePatchesDir putInfo opts "Done making bucketed cache!" where toBucketed :: FilePath -> FilePath -> IO () toBucketed src dest = do srcExist <- doesDirectoryExist src if srcExist then do debugMessage $ "Making " ++ src ++ " bucketed in " ++ dest forM_ subDirSet $ \subDir -> createDirectoryIfMissing True (dest subDir) fileNames <- getDirectoryContents src forM_ fileNames $ \file -> do exists <- doesDirectoryReallyExist (src file) if not $ exists then renameFile' src dest file else return () else do debugMessage $ show src ++ " didn't exist, doing nothing." return () renameFile' :: FilePath -> FilePath -> FilePath -> IO () renameFile' s d f = renameFile (s f) (joinPath [d, bucketFolder f, f]) subDirSet :: [String] subDirSet = map toStrHex [0..255] toStrHex :: Int -> String toStrHex = printf "%02x" optimizeGlobalCache :: DarcsCommand [DarcsFlag] optimizeGlobalCache = common { commandName = "cache" , commandExtraArgs = -1 , commandExtraArgHelp = [ " ..." ] , commandHelp = optimizeHelpGlobalCache , commandDescription = "garbage collect global cache" , commandCommand = optimizeGlobalCacheCmd , commandPrereq = \_ -> return $ Right () } optimizeHelpGlobalCache :: String optimizeHelpGlobalCache = unlines [ "This command deletes obsolete files within the global cache." , "It takes one or more directories as arguments, and recursively" , "searches all repositories within these directories. Then it deletes" , "all files in the global cache not belonging to these repositories." , "When no directory is given, it searches repositories in the user's" , "home directory." , "" , "It also automatically migrates the global cache to the (default)" , "bucketed format." ] optimizeGlobalCacheCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () optimizeGlobalCacheCmd _ opts args = do optimizeBucketed opts home <- getHomeDirectory let args' = if null args then [home] else args cleanGlobalCache args' opts putInfo opts "Done cleaning global cache!" cleanGlobalCache :: [String] -> [DarcsFlag] -> IO () cleanGlobalCache dirs opts = do putInfo opts "\nLooking for repositories in the following directories:" putInfo opts $ text $ unlines dirs gCacheDir' <- globalCacheDir repoPaths' <- mapM findAllReposInDir dirs putInfo opts "Finished listing repositories." let repoPaths = nub $ concat repoPaths' gCache = fromJust gCacheDir' gCacheInvDir = gCache inventoriesDir gCachePatchesDir = gCache patchesDir gCachePristineDir = gCache pristineDir createDirectoryIfMissing True gCacheInvDir createDirectoryIfMissing True gCachePatchesDir createDirectoryIfMissing True gCachePristineDir remove listInventoriesRepoDir gCacheInvDir repoPaths remove (listPatchesLocalBucketed gCache . ( darcsdir)) gCachePatchesDir repoPaths remove getPristine gCachePristineDir repoPaths where remove fGetFiles cacheSubDir repoPaths = do s1 <- mapM fGetFiles repoPaths s2 <- getRecursiveContents cacheSubDir remove' cacheSubDir s2 (concat s1) remove' :: String -> [String] -> [String] -> IO () remove' dir s1 s2 = mapM_ (removeFileMayNotExist . (\hashedFile -> dir bucketFolder hashedFile hashedFile)) (diffHashLists s1 s2) getPristine :: String -> IO [String] getPristine darcsDir = do i <- gzReadFilePS (darcsDir darcsdir hashedInventory) getHashedFiles (darcsDir darcsdir pristineDir) [peekPristineHash i] darcs-2.14.5/src/Darcs/UI/Commands/Pull.hs0000644000000000000000000003412107346545000016242 0ustar0000000000000000-- Copyright (C) 2002-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Pull ( -- * Commands. pull, fetch, pullCmd, StandardPatchApplier, -- * Utility functions. fetchPatches, revertable ) where import Prelude () import Darcs.Prelude import System.Exit ( exitSuccess ) import Control.Monad ( when, unless, (>=>) ) import Data.List ( nub ) import Data.Maybe ( fromMaybe ) import Darcs.UI.Commands ( DarcsCommand(..) , withStdOpts , putInfo , putVerbose , setEnvDarcsPatches , defaultRepo , amInHashedRepository ) import Darcs.UI.Flags ( DarcsFlag , fixUrl, getOutput , changesReverse, verbosity, dryRun, umask, useCache, selectDeps , remoteRepos, reorder, setDefault , withContext, hasXmlOutput , isInteractive, quiet ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking (..) ) import Darcs.Repository ( Repository , identifyRepositoryFor , withRepoLock , RepoJob(..) , readRepo , modifyCache , modifyCache , Cache(..) , CacheLoc(..) , WritableOrNot(..) , filterOutConflicts ) import qualified Darcs.Repository.Cache as DarcsCache import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info, hopefully, patchDesc ) import Darcs.Patch ( IsRepoType, RepoPatch, description ) import Darcs.Patch.Bundle( makeBundleN, patchFilename ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Set ( Origin, PatchSet(..), SealedPatchSet ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), seal ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoercePEnd ) import Darcs.Patch.Witnesses.Ordered ( (:>)(..), (:\/:)(..), FL(..), RL(..) , mapFL, nullFL, reverseFL, mapFL_FL ) import Darcs.Patch.Permutations ( partitionFL ) import Darcs.Repository.Prefs ( addToPreflist, addRepoSource, getPreflist, showMotd ) import Darcs.Patch.Depends ( findUncommon, findCommonWithThem, patchSetIntersection, patchSetUnion ) import Darcs.UI.ApplyPatches ( PatchApplier(..), StandardPatchApplier(..) ) import Darcs.UI.Completion ( prefArgs ) import Darcs.UI.Commands.Util ( checkUnrelatedRepos ) import Darcs.UI.SelectChanges ( WhichChanges(..) , runSelection , selectionContext ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions (..) ) import Darcs.Util.Exception ( clarifyErrors ) import Darcs.Util.Printer ( vcat, ($$), text, putDoc ) import Darcs.Util.Lock ( writeDocBinFile ) import Darcs.Util.Path ( useAbsoluteOrStd, stdOut, AbsolutePath ) import Darcs.Util.Workaround ( getCurrentDirectory ) import Darcs.Util.Text ( quote ) import Darcs.Util.Tree( Tree ) pullDescription :: String pullDescription = "Copy and apply patches from another repository to this one." fetchDescription :: String fetchDescription = "Fetch patches from another repository, but don't apply them." pullHelp :: String pullHelp = unlines [ "Pull is used to bring patches made in another repository into the current" , "repository (that is, either the one in the current directory, or the one" , "specified with the `--repodir` option). Pull accepts arguments, which are" , "URLs from which to pull, and when called without an argument, pull will" , "use the repository specified at `_darcs/prefs/defaultrepo`." , "" , "The default (`--union`) behavior is to pull any patches that are in any of" , "the specified repositories. If you specify the `--intersection` flag, darcs" , "will only pull those patches which are present in all source repositories." , "If you specify the `--complement` flag, darcs will only pull elements in the" , "first repository that do not exist in any of the remaining repositories." , "" , "If `--reorder` is supplied, the set of patches that exist only in the current" , "repository is brought at the top of the current history. This will work even" , "if there are no new patches to pull." , "" , "See `darcs help apply` for detailed description of many options." ] fetchHelp :: String fetchHelp = unlines [ "Fetch is similar to `pull` except that it does not apply any patches" , "to the current repository. Instead, it generates a patch bundle that" , "you can apply later with `apply`." , "" , "Fetch's behaviour is essentially similar to pull's, so please consult" , "the help of `pull` to know more." ] fetch :: DarcsCommand [DarcsFlag] fetch = DarcsCommand { commandProgramName = "darcs" , commandName = "fetch" , commandHelp = fetchHelp , commandDescription = fetchDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[REPOSITORY]..."] , commandCommand = fetchCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = prefArgs "repos" , commandArgdefaults = defaultRepo , commandAdvancedOptions = odesc advancedOpts , commandBasicOptions = odesc basicOpts , commandDefaults = defaultFlags allOpts , commandCheckOptions = ocheck allOpts , commandParseOptions = onormalise allOpts } where basicOpts = O.matchSeveral ^ O.interactive -- True ^ O.dryRun ^ O.summary ^ O.selectDeps ^ O.setDefault ^ O.repoDir ^ O.output ^ O.allowUnrelatedRepos ^ O.diffAlgorithm advancedOpts = O.repoCombinator ^ O.remoteRepos ^ O.network allOpts = basicOpts `withStdOpts` advancedOpts pull :: DarcsCommand [DarcsFlag] pull = DarcsCommand { commandProgramName = "darcs" , commandName = "pull" , commandHelp = pullHelp , commandDescription = pullDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[REPOSITORY]..."] , commandCommand = pullCmd StandardPatchApplier , commandPrereq = amInHashedRepository , commandCompleteArgs = prefArgs "repos" , commandArgdefaults = defaultRepo , commandAdvancedOptions = odesc advancedOpts , commandBasicOptions = odesc basicOpts , commandDefaults = defaultFlags allOpts , commandCheckOptions = ocheck allOpts , commandParseOptions = onormalise allOpts } where basicOpts = O.matchSeveral ^ O.reorder ^ O.interactive ^ O.conflictsYes ^ O.externalMerge ^ O.runTest ^ O.dryRunXml ^ O.summary ^ O.selectDeps ^ O.setDefault ^ O.repoDir ^ O.allowUnrelatedRepos ^ O.diffAlgorithm advancedOpts = O.repoCombinator ^ O.compress ^ O.useIndex ^ O.remoteRepos ^ O.setScriptsExecutable ^ O.umask ^ O.restrictPaths ^ O.changesReverse ^ O.pauseForGui ^ O.network allOpts = basicOpts `withStdOpts` advancedOpts pullCmd :: PatchApplier pa => pa -> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () pullCmd patchApplier (_,o) opts repos = do pullingFrom <- mapM (fixUrl o) repos withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ repoJob patchApplier opts $ \patchProxy initRepo -> do let repository = modifyCache initRepo $ addReposToCache pullingFrom (_, Sealed (us' :\/: to_be_pulled)) <- fetchPatches o opts repos "pull" repository let from_whom = error "Internal error: pull shouldn't need a 'from' address" applyPatches patchApplier patchProxy "pull" opts from_whom repository us' to_be_pulled where addReposToCache repos' (Ca cache) = Ca $ [ toReadOnlyCache r | r <- repos' ] ++ cache toReadOnlyCache = Cache DarcsCache.Repo NotWritable fetchCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () fetchCmd (_,o) opts repos = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ fetchPatches o opts repos "fetch" >=> makeBundle opts fetchPatches :: forall rt p wR wU . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => AbsolutePath -> [DarcsFlag] -> [String] -> String -> Repository rt p wR wU wR -> IO (SealedPatchSet rt p Origin, Sealed ((FL (PatchInfoAnd rt p) :\/: FL (PatchInfoAnd rt p)) wR)) fetchPatches o opts unfixedrepodirs@(_:_) jobname repository = do here <- getCurrentDirectory repodirs <- (nub . filter (/= here)) `fmap` mapM (fixUrl o) unfixedrepodirs -- Test to make sure we aren't trying to pull from the current repo when (null repodirs) $ fail "Can't pull from current repository!" old_default <- getPreflist "defaultrepo" when (old_default == repodirs && not (hasXmlOutput opts)) $ let pulling = case dryRun ? opts of O.YesDryRun -> "Would pull" O.NoDryRun -> "Pulling" in putInfo opts $ text $ pulling++" from "++concatMap quote repodirs++"..." (Sealed them, Sealed compl) <- readRepos repository opts repodirs addRepoSource (head repodirs) (dryRun ? opts) (remoteRepos ? opts) (setDefault False opts) mapM_ (addToPreflist "repos") repodirs unless (quiet opts || hasXmlOutput opts) $ mapM_ showMotd repodirs us <- readRepo repository checkUnrelatedRepos (parseFlags O.allowUnrelatedRepos opts) us them common :> _ <- return $ findCommonWithThem us them us' :\/: them' <- return $ findUncommon us them _ :\/: compl' <- return $ findUncommon us compl let avoided = mapFL info compl' ps :> _ <- return $ partitionFL (not . (`elem` avoided) . info) them' putVerbose opts $ case us' of (x@(_ :>: _)) -> text "We have the following new (to them) patches:" $$ vcat (mapFL description x) _ -> mempty unless (nullFL ps) $ putVerbose opts $ text "They have the following patches to pull:" $$ vcat (mapFL description ps) (hadConflicts, Sealed psFiltered) <- if O.conflictsYes ? opts == Nothing then filterOutConflicts (reverseFL us') repository ps else return (False, Sealed ps) when hadConflicts $ putInfo opts $ text "Skipping some patches which would cause conflicts." when (nullFL psFiltered) $ do putInfo opts $ text "No remote patches to pull in!" setEnvDarcsPatches psFiltered when (reorder ? opts /= O.Reorder) exitSuccess let direction = if changesReverse ? opts then FirstReversed else First context = selectionContext direction jobname (pullPatchSelOpts opts) Nothing Nothing (to_be_pulled :> _) <- runSelection psFiltered context return (seal common, seal $ us' :\/: to_be_pulled) fetchPatches _ _ [] jobname _ = fail $ "No default repository to " ++ jobname ++ " from, please specify one" makeBundle :: forall rt p wR . (RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> (SealedPatchSet rt p Origin, Sealed ((FL (PatchInfoAnd rt p) :\/: FL (PatchInfoAnd rt p)) wR)) -> IO () makeBundle opts (Sealed common, Sealed (_ :\/: to_be_fetched)) = do bundle <- makeBundleN Nothing (unsafeCoercePEnd common) $ mapFL_FL hopefully to_be_fetched let fname = case to_be_fetched of (x:>:_)-> patchFilename $ patchDesc x _ -> impossible o = fromMaybe stdOut (getOutput opts fname) useAbsoluteOrStd writeDocBinFile putDoc o bundle revertable :: IO a -> IO a revertable x = x `clarifyErrors` unlines ["Error applying patch to the working directory.","", "This may have left your working directory an inconsistent", "but recoverable state. If you had no un-recorded changes", "by using 'darcs revert' you should be able to make your", "working directory consistent again."] {- Read in the specified pull-from repositories. Perform Intersection, Union, or Complement read. In patch-theory terms (stated in set algebra, where + is union and & is intersection and \ is complement): Union = ((R1 + R2 + ... + Rn) \ Rc) Intersection = ((R1 & R2 & ... & Rn) \ Rc) Complement = (R1 \ Rc) \ ((R2 + R3 + ... + Rn) \ Rc) where Rc = local repo R1 = 1st specified pull repo R2, R3, Rn = other specified pull repo Since Rc is not provided here yet, the result of readRepos is a tuple: the first patchset(s) to be complemented against Rc and then the second patchset(s) to be complemented against Rc. -} readRepos :: (IsRepoType rt, RepoPatch p) => Repository rt p wR wU wT -> [DarcsFlag] -> [String] -> IO (SealedPatchSet rt p Origin,SealedPatchSet rt p Origin) readRepos _ _ [] = impossible readRepos to_repo opts us = do rs <- mapM (\u -> do r <- identifyRepositoryFor to_repo (useCache ? opts) u ps <- readRepo r return $ seal ps) us return $ case parseFlags O.repoCombinator opts of O.Intersection -> (patchSetIntersection rs, seal (PatchSet NilRL NilRL)) O.Complement -> (head rs, patchSetUnion $ tail rs) O.Union -> (patchSetUnion rs, seal (PatchSet NilRL NilRL)) pullPatchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions pullPatchSelOpts flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = parseFlags O.matchSeveral flags , S.interactive = isInteractive True flags , S.selectDeps = selectDeps ? flags , S.summary = O.summary ? flags , S.withContext = withContext ? flags } darcs-2.14.5/src/Darcs/UI/Commands/Push.hs0000644000000000000000000002573507346545000016260 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE TypeOperators #-} module Darcs.UI.Commands.Push ( push ) where import Prelude () import Darcs.Prelude import System.Exit ( exitWith, ExitCode( ExitSuccess, ExitFailure ), exitSuccess ) import Control.Monad ( when, unless ) import Data.Maybe ( isJust ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts , putVerbose , putInfo , abortRun , setEnvDarcsPatches , defaultRepo , amInHashedRepository ) import Darcs.UI.Commands.Util ( printDryRunMessageAndExit, checkUnrelatedRepos ) import Darcs.UI.Completion ( prefArgs ) import Darcs.UI.Flags ( DarcsFlag , isInteractive, verbosity, withContext , xmlOutput, selectDeps, applyAs, remoteDarcs , changesReverse, dryRun, useCache, remoteRepos, setDefault, fixUrl ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise , defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( DryRun (..) ) import qualified Darcs.Repository.Flags as R ( remoteDarcs ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, hopefully ) import Darcs.Repository ( Repository, withRepository, RepoJob(..), identifyRepositoryFor, readRepo ) import Darcs.Patch ( IsRepoType, RepoPatch, description ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Witnesses.Ordered ( (:>)(..), RL, FL, nullRL, nullFL, reverseFL, mapFL_FL, mapRL ) import Darcs.Repository.Prefs ( addRepoSource, getPreflist ) import Darcs.UI.External ( signString, darcsProgram , pipeDoc, pipeDocSSH ) import Darcs.Util.Exception ( die ) import Darcs.Util.URL ( isHttpUrl, isValidLocalPath , isSshUrl, splitSshUrl, SshFilePath(..) ) import Darcs.Util.Path ( AbsolutePath ) import Darcs.UI.SelectChanges ( WhichChanges(..) , selectionContext , runSelection ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions (..) ) import Darcs.Patch.Depends ( findCommonWithThem, countUsThem ) import Darcs.Patch.Bundle ( makeBundleN ) import Darcs.Patch.Show( ShowPatch ) import Darcs.Patch.Set ( PatchSet, Origin ) import Darcs.Util.Printer ( Doc, vcat, empty, text, ($$) ) import Darcs.UI.Email ( makeEmail ) import Darcs.Util.English (englishNum, Noun(..)) import Darcs.Util.Workaround ( getCurrentDirectory ) import Darcs.Util.Text ( quote ) import Darcs.Util.Tree( Tree ) pushDescription :: String pushDescription = "Copy and apply patches from this repository to another one." pushHelp :: String pushHelp = unlines [ "Push is the opposite of pull. Push allows you to copy patches from the" , "current repository into another repository." , "" , "If you give the `--apply-as` flag, darcs will use `sudo` to apply the" , "patches as a different user. This can be useful if you want to set up a" , "system where several users can modify the same repository, but you don't" , "want to allow them full write access. This isn't secure against skilled" , "malicious attackers, but at least can protect your repository from clumsy," , "inept or lazy users." , "" , "`darcs push` will compress the patch data before sending it to a remote" , "location via ssh. This works as long as the remote darcs is not older" , "than version 2.5. If you get errors that indicate a corrupt patch bundle," , "you should try again with the `--no-compress` option." ] push :: DarcsCommand [DarcsFlag] push = DarcsCommand { commandProgramName = "darcs" , commandName = "push" , commandHelp = pushHelp , commandDescription = pushDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[REPOSITORY]"] , commandCommand = pushCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = prefArgs "repos" , commandArgdefaults = defaultRepo , commandAdvancedOptions = odesc pushAdvancedOpts , commandBasicOptions = odesc pushBasicOpts , commandDefaults = defaultFlags pushOpts , commandCheckOptions = ocheck pushOpts , commandParseOptions = onormalise pushOpts } where pushBasicOpts = O.matchSeveral ^ O.selectDeps ^ O.interactive ^ O.sign ^ O.dryRunXml ^ O.summary ^ O.repoDir ^ O.setDefault ^ O.allowUnrelatedRepos pushAdvancedOpts = O.applyAs ^ O.remoteRepos ^ O.changesReverse ^ O.compress ^ O.network pushOpts = pushBasicOpts `withStdOpts` pushAdvancedOpts pushCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () pushCmd (_, o) opts [unfixedrepodir] = do repodir <- fixUrl o unfixedrepodir here <- getCurrentDirectory checkOptionsSanity opts repodir -- make sure we aren't trying to push to the current repo when (repodir == here) $ die "Cannot push from repository to itself." bundle <- withRepository (useCache ? opts) $ RepoJob $ prepareBundle opts repodir sbundle <- signString (parseFlags O.sign opts) bundle let body = if isValidLocalPath repodir then sbundle else makeEmail repodir [] Nothing Nothing sbundle Nothing rval <- remoteApply opts repodir body case rval of ExitFailure ec -> do putStrLn "Apply failed!" exitWith (ExitFailure ec) ExitSuccess -> putInfo opts $ text "Push successful." pushCmd _ _ [] = die "No default repository to push to, please specify one." pushCmd _ _ _ = die "Cannot push to more than one repo." prepareBundle :: forall rt p wR wU wT. (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> String -> Repository rt p wR wU wT -> IO Doc prepareBundle opts repodir repository = do old_default <- getPreflist "defaultrepo" when (old_default == [repodir]) $ let pushing = if dryRun ? opts == YesDryRun then "Would push" else "Pushing" in putInfo opts $ text $ pushing++" to "++quote repodir++"..." them <- identifyRepositoryFor repository (useCache ? opts) repodir >>= readRepo addRepoSource repodir (dryRun ? opts) (remoteRepos ? opts) (setDefault False opts) us <- readRepo repository common :> us' <- return $ findCommonWithThem us them prePushChatter opts us (reverseFL us') them let direction = if changesReverse ? opts then FirstReversed else First context = selectionContext direction "push" (pushPatchSelOpts opts) Nothing Nothing runSelection us' context >>= bundlePatches opts common prePushChatter :: forall rt p a wX wY wT . (RepoPatch p, ShowPatch a) => [DarcsFlag] -> PatchSet rt p Origin wX -> RL a wT wX -> PatchSet rt p Origin wY -> IO () prePushChatter opts us us' them = do checkUnrelatedRepos (parseFlags O.allowUnrelatedRepos opts) us them let num_to_pull = snd $ countUsThem us them pull_reminder = if num_to_pull > 0 then text $ "The remote repository has " ++ show num_to_pull ++ " " ++ englishNum num_to_pull (Noun "patch") " to pull." else empty putVerbose opts $ text "We have the following patches to push:" $$ vcat (mapRL description us') unless (nullRL us') $ putInfo opts pull_reminder when (nullRL us') $ do putInfo opts $ text "No recorded local patches to push!" exitSuccess bundlePatches :: forall t rt p wZ wW wA. (RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> PatchSet rt p wA wZ -> (FL (PatchInfoAnd rt p) :> t) wZ wW -> IO Doc bundlePatches opts common (to_be_pushed :> _) = do setEnvDarcsPatches to_be_pushed printDryRunMessageAndExit "push" (verbosity ? opts) (O.summary ? opts) (dryRun ? opts) (xmlOutput ? opts) (isInteractive True opts) to_be_pushed when (nullFL to_be_pushed) $ do putInfo opts $ text "You don't want to push any patches, and that's fine with me!" exitSuccess makeBundleN Nothing common (mapFL_FL hopefully to_be_pushed) checkOptionsSanity :: [DarcsFlag] -> String -> IO () checkOptionsSanity opts repodir = if isHttpUrl repodir then do when (isJust $ applyAs ? opts) $ abortRun opts $ text "Cannot --apply-as when pushing to URLs" let lprot = takeWhile (/= ':') repodir msg = text ("Pushing to "++lprot++" URLs is not supported.") abortRun opts msg else when (parseFlags O.sign opts /= O.NoSign) $ abortRun opts $ text "Signing doesn't make sense for local repositories or when pushing over ssh." pushPatchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions pushPatchSelOpts flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = parseFlags O.matchSeveral flags , S.interactive = isInteractive True flags , S.selectDeps = selectDeps ? flags , S.summary = O.summary ? flags , S.withContext = withContext ? flags } remoteApply :: [DarcsFlag] -> String -> Doc -> IO ExitCode remoteApply opts repodir bundle = case applyAs ? opts of Nothing | isSshUrl repodir -> applyViaSsh opts (splitSshUrl repodir) bundle | otherwise -> applyViaLocal opts repodir bundle Just un | isSshUrl repodir -> applyViaSshAndSudo opts (splitSshUrl repodir) un bundle | otherwise -> applyViaSudo un repodir bundle applyViaSudo :: String -> String -> Doc -> IO ExitCode applyViaSudo user repo bundle = darcsProgram >>= \darcs -> pipeDoc "sudo" ["-u",user,darcs,"apply","--all","--repodir",repo] bundle applyViaLocal :: [DarcsFlag] -> String -> Doc -> IO ExitCode applyViaLocal opts repo bundle = darcsProgram >>= \darcs -> pipeDoc darcs ("apply":"--all":"--repodir":repo:applyopts opts) bundle applyViaSsh :: [DarcsFlag] -> SshFilePath -> Doc -> IO ExitCode applyViaSsh opts repo = pipeDocSSH (parseFlags O.compress opts) repo [R.remoteDarcs (remoteDarcs opts) ++" apply --all "++unwords (applyopts opts)++ " --repodir '"++sshRepo repo++"'"] applyViaSshAndSudo :: [DarcsFlag] -> SshFilePath -> String -> Doc -> IO ExitCode applyViaSshAndSudo opts repo username = pipeDocSSH (parseFlags O.compress opts) repo ["sudo -u "++username++" "++R.remoteDarcs (remoteDarcs opts)++ " apply --all --repodir '"++sshRepo repo++"'"] applyopts :: [DarcsFlag] -> [String] applyopts opts = if parseFlags O.debug opts then ["--debug"] else [] darcs-2.14.5/src/Darcs/UI/Commands/Rebase.hs0000644000000000000000000011063707346545000016536 0ustar0000000000000000-- Copyright (C) 2009 Ganesh Sittampalam -- -- BSD3 {-# LANGUAGE TypeOperators #-} module Darcs.UI.Commands.Rebase ( rebase ) where import Prelude () import Darcs.Prelude import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts , normalCommand, hiddenCommand , commandAlias , defaultRepo, nodefaults , putInfo, putVerbose , setEnvDarcsPatches , amInHashedRepository ) import Darcs.UI.Commands.Util ( printDryRunMessageAndExit ) import Darcs.UI.Commands.Apply ( applyCmd ) import Darcs.UI.Commands.Log ( changelog, getLogInfo ) import Darcs.UI.Commands.Pull ( pullCmd, revertable ) import Darcs.UI.Commands.Unrecord ( getLastPatches, matchingHead ) import Darcs.UI.CommandsAux ( checkPaths ) import Darcs.UI.Completion ( fileArgs, prefArgs, noArgs ) import Darcs.UI.Flags ( DarcsFlag , externalMerge, allowConflicts , compress, diffingOpts , dryRun, reorder, verbosity, verbose , useCache, wantGuiPause , umask, matchAny, changesReverse , onlyToFiles , diffAlgorithm, maxCount, isInteractive , selectDeps, xmlOutput, hasXmlOutput ) import Darcs.UI.Options ( (^), oid, odesc, ocheck, onormalise , defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.PatchHeader ( HijackT, HijackOptions(..), runHijackT , getAuthor , updatePatchHeader, AskAboutDeps(..) ) import Darcs.Repository ( Repository, RepoJob(..), withRepoLock, withRepository , RebaseJobFlags(..) , tentativelyAddPatch, finalizeRepositoryChanges , invalidateIndex , tentativelyRemovePatches, readRepo , tentativelyAddToPending, unrecordedChanges, applyToWorking , revertRepositoryChanges , setScriptsExecutablePatches ) import Darcs.Repository.Flags ( UpdateWorking(..), ExternalMerge(..) ) import Darcs.Repository.Merge ( tentativelyMergePatches, announceMergeConflicts ) import Darcs.Repository.Resolution ( standardResolution ) import Darcs.Patch ( invert, effect, commute, RepoPatch, description ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.Commute ( selfCommuter ) import Darcs.Patch.CommuteFn ( commuterIdFL ) import Darcs.Patch.Info ( displayPatchInfo ) import Darcs.Patch.Match ( firstMatch, secondMatch, splitSecondFL ) import Darcs.Patch.Named ( Named, fmapFL_Named, patchcontents, patch2patchinfo ) import Darcs.Patch.Named.Wrapped ( mkRebase, toRebasing, fromRebasing ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info, n2pia, hopefully ) import Darcs.Patch.Prim ( PrimOf, canonizeFL, fromPrim ) import Darcs.Patch.Rebase ( takeHeadRebase, takeHeadRebaseFL ) import Darcs.Patch.Rebase.Container ( Suspended(..) ) import Darcs.Patch.Rebase.Fixup ( RebaseFixup(..), flToNamesPrims ) import Darcs.Patch.Rebase.Item ( RebaseItem(..), simplifyPush, simplifyPushes ) import Darcs.Patch.Rebase.Name ( RebaseName(..), commuteNameNamed ) import Darcs.Patch.Rebase.Viewing ( RebaseSelect(RSFwd), rsToPia , toRebaseSelect, fromRebaseSelect, extractRebaseSelect, reifyRebaseSelect , partitionUnconflicted , WithDroppedDeps(..), WDDNamed, commuterIdWDD , toRebaseChanges ) import Darcs.Patch.Permutations ( partitionConflictingFL ) import Darcs.Patch.Progress ( progressFL ) import Darcs.Patch.RepoType ( RepoType(..), RebaseType(..) ) import Darcs.Patch.Set ( PatchSet(..), appendPSFL ) import Darcs.Patch.Show ( showNicely ) import Darcs.Patch.Split ( primSplitter ) import Darcs.UI.ApplyPatches ( PatchApplier(..), PatchProxy(..) ) import Darcs.UI.SelectChanges ( runSelection , selectionContext, selectionContextGeneric, selectionContextPrim , WhichChanges(First, Last, LastReversed) , viewChanges ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions (..) ) import Darcs.Patch.Witnesses.Eq ( EqCheck(..) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (+>+), mapFL_FL , concatFL, mapFL, nullFL, lengthFL , (:>)(..) , RL(..), reverseRL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), seal, unseal , FlippedSeal(..) , Sealed2(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Util.English ( englishNum, Noun(Noun) ) import Darcs.Util.Printer ( vcat, text, ($$), redText , putDocLnWith, simplePrinters , renderString ) import Darcs.Util.Printer.Color ( fancyPrinters ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Path ( AbsolutePath ) import Darcs.Util.Tree ( Tree ) import Control.Exception ( catch, IOException ) import Control.Monad ( when ) import Control.Monad.Trans ( liftIO ) import System.Exit ( exitSuccess ) rebaseDescription :: String rebaseDescription = "Edit several patches at once." rebaseHelp :: String rebaseHelp = "The `darcs rebase' command is used to edit a collection of darcs patches.\n" rebase :: DarcsCommand [DarcsFlag] rebase = SuperCommand { commandProgramName = "darcs" , commandName = "rebase" , commandHelp = rebaseHelp , commandDescription = rebaseDescription , commandPrereq = amInHashedRepository , commandSubCommands = [ normalCommand pull , normalCommand apply , normalCommand suspend , normalCommand unsuspend , hiddenCommand reify , hiddenCommand inject , normalCommand obliterate , normalCommand log , hiddenCommand changes ] } suspend :: DarcsCommand [DarcsFlag] suspend = DarcsCommand { commandProgramName = "darcs" , commandName = "suspend" , commandHelp = "Select patches to move into a suspended state at the end of the repo.\n" , commandDescription = "Select patches to move into a suspended state at the end of the repo." , commandPrereq = amInHashedRepository , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = suspendCmd , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc suspendAdvancedOpts , commandBasicOptions = odesc suspendBasicOpts , commandDefaults = defaultFlags suspendOpts , commandCheckOptions = ocheck suspendOpts , commandParseOptions = onormalise suspendOpts } where suspendBasicOpts = O.matchSeveralOrLast ^ O.selectDeps ^ O.interactive ^ O.summary ^ O.diffAlgorithm suspendAdvancedOpts = O.changesReverse ^ O.useIndex suspendOpts = suspendBasicOpts `withStdOpts` suspendAdvancedOpts suspendCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () suspendCmd _ opts _args = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ StartRebaseJob (RebaseJobFlags (compress ? opts) (verbosity ? opts) YesUpdateWorking) $ \repository -> do allpatches <- readRepo repository (rOld, suspended, allpatches_tail) <- return $ takeHeadRebase allpatches (_ :> patches) <- return $ if firstMatch (parseFlags O.matchSeveralOrLast opts) then getLastPatches (parseFlags O.matchSeveralOrLast opts) allpatches_tail else matchingHead (parseFlags O.matchSeveralOrLast opts) allpatches_tail let direction = if changesReverse ? opts then Last else LastReversed patches_context = selectionContext direction "suspend" (patchSelOpts True opts) Nothing Nothing (_ :> psToSuspend) <- runSelection patches patches_context when (nullFL psToSuspend) $ do putStrLn "No patches selected!" exitSuccess -- test all patches for hijacking and abort if rejected runHijackT RequestHijackPermission $ mapM_ (getAuthor "suspend" False Nothing) $ mapFL info psToSuspend repository' <- doSuspend opts repository suspended rOld psToSuspend finalizeRepositoryChanges repository' YesUpdateWorking (compress ? opts) return () doSuspend :: forall p wR wU wT wX . (RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> Repository ('RepoType 'IsRebase) p wR wU wT -> Suspended p wT wT -> PatchInfoAnd ('RepoType 'IsRebase) p wT wT -> FL (PatchInfoAnd ('RepoType 'IsRebase) p) wX wT -> IO (Repository ('RepoType 'IsRebase) p wR wU wX) doSuspend opts repository (Items qs) rOld psToSuspend = do pend <- unrecordedChanges (diffingOpts opts) O.NoLookForMoves O.NoLookForReplaces repository Nothing FlippedSeal psAfterPending <- let effectPsToSuspend = effect psToSuspend in case commute (effectPsToSuspend :> pend) of Just (_ :> res) -> return (FlippedSeal res) Nothing -> do putVerbose opts $ let invPsEffect = invert effectPsToSuspend doPartition = partitionConflictingFL (commuterIdFL selfCommuter) in case (doPartition invPsEffect pend, doPartition pend invPsEffect) of (_ :> invSuspendedConflicts, _ :> pendConflicts) -> let suspendedConflicts = invert invSuspendedConflicts in redText "These changes in the suspended patches:" $$ showNicely suspendedConflicts $$ redText "...conflict with these local changes:" $$ showNicely pendConflicts fail $ "Can't suspend selected patches without reverting some unrecorded change." ++ if (verbose opts) then "" else " Use --verbose to see the details." rNew <- mkRebase (Items (mapFL_FL (ToEdit . fromRebasing . hopefully) psToSuspend +>+ qs)) invalidateIndex repository -- remove the old rebase patch and the patches to suspend repository' <- tentativelyRemovePatches repository (compress ? opts) YesUpdateWorking (psToSuspend +>+ (rOld :>: NilFL)) tentativelyAddToPending repository' YesUpdateWorking $ invert $ effect psToSuspend -- add the new rebase patch repository'' <- tentativelyAddPatch repository' (compress ? opts) (unVerbose (verbosity ? opts)) YesUpdateWorking (n2pia rNew) _ <- applyToWorking repository'' (verbosity ? opts) (invert psAfterPending) `catch` \(e :: IOException) -> fail ("Couldn't undo patch in working dir.\n" ++ show e) return repository'' -- Certain repository functions will display the rebase patch in verbose mode -- so we use this function to suppress it when passing the verbosity. unVerbose :: O.Verbosity -> O.Verbosity unVerbose O.Verbose = O.NormalVerbosity unVerbose x = x unsuspend :: DarcsCommand [DarcsFlag] unsuspend = DarcsCommand { commandProgramName = "darcs" , commandName = "unsuspend" , commandHelp = "Selected patches to restore from a suspended state to the end of the repo.\n" , commandDescription = "Select suspended patches to restore to the end of the repo." , commandPrereq = amInHashedRepository , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = unsuspendCmd False , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc unsuspendAdvancedOpts , commandBasicOptions = odesc unsuspendBasicOpts , commandDefaults = defaultFlags unsuspendOpts , commandCheckOptions = ocheck unsuspendOpts , commandParseOptions = onormalise unsuspendOpts } where unsuspendBasicOpts = O.conflictsYes ^ O.matchSeveralOrFirst ^ O.interactive ^ O.summary ^ O.externalMerge ^ O.keepDate ^ O.author ^ O.diffAlgorithm unsuspendAdvancedOpts = O.useIndex unsuspendOpts = unsuspendBasicOpts `withStdOpts` unsuspendAdvancedOpts reify :: DarcsCommand [DarcsFlag] reify = DarcsCommand { commandProgramName = "darcs" , commandName = "reify" , commandHelp = "Select suspended patches to restore to the end of the repo, reifying any fixup patches.\n" , commandDescription = "Select suspended patches to restore to the end of the repo, reifying any fixup patches." , commandPrereq = amInHashedRepository , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = unsuspendCmd True , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc reifyBasicOpts , commandDefaults = defaultFlags reifyOpts , commandCheckOptions = ocheck reifyOpts , commandParseOptions = onormalise reifyOpts } where reifyBasicOpts = O.matchSeveralOrFirst ^ O.interactive ^ O.keepDate ^ O.author ^ O.diffAlgorithm reifyOpts = reifyBasicOpts `withStdOpts` oid unsuspendCmd :: Bool -> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () unsuspendCmd reifyFixups _ opts _args = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RebaseJob (RebaseJobFlags (compress ? opts) (verbosity ? opts) YesUpdateWorking) $ \(repository :: Repository ('RepoType 'IsRebase) p wR wU wR) -> (do patches <- readRepo repository pend <- unrecordedChanges (diffingOpts opts) O.NoLookForMoves O.NoLookForReplaces repository Nothing let checkChanges :: FL (PrimOf p) wA wB -> IO (EqCheck wA wB) checkChanges NilFL = return IsEq checkChanges _ = error "can't unsuspend when there are unrecorded changes" IsEq <- checkChanges pend :: IO (EqCheck wR wU) (rOld, Items ps, _) <- return $ takeHeadRebase patches let selects = toRebaseSelect ps let matchFlags = matchAny ? opts inRange :> outOfRange <- return $ if secondMatch matchFlags then splitSecondFL rsToPia matchFlags selects else selects :> NilFL offer :> dontoffer <- return $ case O.conflictsYes ? opts of Nothing -> partitionUnconflicted inRange -- skip conflicts Just _ -> inRange :> NilRL let warnSkip :: RL q wX wY -> IO () warnSkip NilRL = return () warnSkip _ = putStrLn "Skipping some patches which would cause conflicts." warnSkip dontoffer let patches_context = selectionContextGeneric rsToPia First "unsuspend" (patchSelOpts True opts) Nothing (chosen :> keep) <- runSelection offer patches_context when (nullFL chosen) $ do putStrLn "No patches selected!" exitSuccess (ps_to_unsuspend :: FL (WDDNamed p) wR wZ) :> chosen_fixups <- (if reifyFixups then reifyRebaseSelect else return . extractRebaseSelect) chosen let da = diffAlgorithm ? opts ps_to_keep = simplifyPushes da chosen_fixups . fromRebaseSelect $ keep +>+ reverseRL dontoffer +>+ outOfRange Sealed standard_resolved_p <- return $ standardResolution $ concatFL $ progressFL "Examining patches for conflicts" $ mapFL_FL (patchcontents . wddPatch) ps_to_unsuspend :: IO (Sealed (FL (PrimOf p) wZ)) have_conflicts <- announceMergeConflicts "unsuspend" (allowConflicts opts) (externalMerge ? opts) standard_resolved_p Sealed (resolved_p :: FL (PrimOf p) wA wB) <- case (externalMerge ? opts, have_conflicts) of (NoExternalMerge, _) -> case O.conflictsYes ? opts of Just O.YesAllowConflicts -> return $ seal NilFL -- i.e. don't mark them _ -> return $ seal standard_resolved_p (_, False) -> return $ seal standard_resolved_p (YesExternalMerge _, True) -> error "external resolution for unsuspend not implemented yet" let effect_to_apply = concatFL (mapFL_FL effect ps_to_unsuspend) +>+ resolved_p invalidateIndex repository repository' <- tentativelyRemovePatches repository (compress ? opts) YesUpdateWorking (rOld :>: NilFL) -- TODO should catch logfiles (fst value from updatePatchHeader) and clean them up as in AmendRecord tentativelyAddToPending repository' YesUpdateWorking effect_to_apply -- we can just let hijack attempts through here because we already asked about them on suspend time (repository'', renames) <- runHijackT IgnoreHijack $ doAdd repository' ps_to_unsuspend rNew <- unseal (mkRebase . Items) . unseal (simplifyPushes da (mapFL_FL NameFixup renames)) $ ps_to_keep repository''' <- tentativelyAddPatch repository'' (compress ? opts) (verbosity ? opts) YesUpdateWorking (n2pia rNew) finalizeRepositoryChanges repository''' YesUpdateWorking (compress ? opts) _ <- applyToWorking repository''' (verbosity ? opts) effect_to_apply `catch` \(e :: IOException) -> fail ("couldn't apply patch in working dir.\n" ++ show e) return () ) :: IO () where doAdd :: (RepoPatch p, ApplyState p ~ Tree) => Repository ('RepoType 'IsRebase) p wR wU wT -> FL (WDDNamed p) wT wT2 -> HijackT IO (Repository ('RepoType 'IsRebase) p wR wU wT2, FL (RebaseName p) wT2 wT2) doAdd repo NilFL = return (repo, NilFL) doAdd repo ((p :: WDDNamed p wT wU) :>:ps) = do case wddDependedOn p of [] -> return () deps -> liftIO $ do -- It might make sense to only print out this message once, but we might find -- that the dropped dependencies are interspersed with other output, -- e.g. if running with --ask-deps putStr $ "Warning: dropping the following explicit " ++ englishNum (length deps) (Noun "dependency") ":\n\n" let printIndented n = mapM_ (putStrLn . (replicate n ' '++)) . lines . renderString . displayPatchInfo putStrLn . renderString . displayPatchInfo . patch2patchinfo $ wddPatch p putStr " depended on:\n" mapM_ (printIndented 2) deps putStr "\n" -- TODO should catch logfiles (fst value from updatePatchHeader) and clean them up as in AmendRecord p' <- snd <$> updatePatchHeader "unsuspend" NoAskAboutDeps (patchSelOpts True opts) (diffAlgorithm ? opts) (parseFlags O.keepDate opts) (parseFlags O.selectAuthor opts) (parseFlags O.author opts) (parseFlags O.patchname opts) (parseFlags O.askLongComment opts) (n2pia (toRebasing (wddPatch p))) NilFL repo' <- liftIO $ tentativelyAddPatch repo (compress ? opts) (verbosity ? opts) YesUpdateWorking p' -- create a rename that undoes the change we just made, so the contexts match up let rename :: RebaseName p wU wU rename = Rename (info p') (patch2patchinfo (wddPatch p)) -- push it through the remaining patches to fix them up Just (ps2 :> (rename2 :: RebaseName p wV wT2)) <- return (commuterIdFL (commuterIdWDD commuteNameNamed) (rename :> ps)) -- assert that the rename still has a null effect on the context after commuting IsEq <- return (unsafeCoerceP IsEq :: EqCheck wV wT2) (repo'', renames) <- doAdd repo' ps2 -- return the renames so that the suspended patch can be fixed up return (repo'', rename2 :>: renames) inject :: DarcsCommand [DarcsFlag] inject = DarcsCommand { commandProgramName = "darcs" , commandName = "inject" , commandHelp = "Merge a change from the fixups of a patch into the patch itself.\n" , commandDescription = "Merge a change from the fixups of a patch into the patch itself." , commandPrereq = amInHashedRepository , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = injectCmd , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc injectBasicOpts , commandDefaults = defaultFlags injectOpts , commandCheckOptions = ocheck injectOpts , commandParseOptions = onormalise injectOpts } where injectBasicOpts = O.keepDate ^ O.author ^ O.diffAlgorithm injectOpts = injectBasicOpts `withStdOpts` oid injectCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () injectCmd _ opts _args = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RebaseJob (RebaseJobFlags (compress ? opts) (verbosity ? opts) YesUpdateWorking) $ \(repository :: Repository ('RepoType 'IsRebase) p wR wU wR) -> do patches <- readRepo repository (rOld, Items ps, _) <- return $ takeHeadRebase patches let selects = toRebaseSelect ps -- TODO this selection doesn't need to respect dependencies -- TODO we only want to select one patch: generalise withSelectedPatchFromRepo let patches_context = selectionContextGeneric rsToPia First "inject into" (patchSelOpts True opts) Nothing (chosens :> rest_selects) <- runSelection selects patches_context let extractSingle :: FL (RebaseSelect p) wX wY -> (FL (RebaseFixup p) :> Named p) wX wY extractSingle (RSFwd fixups toedit :>: NilFL) = fixups :> toedit extractSingle (_ :>: NilFL) = impossible extractSingle _ = error "You must select precisely one patch!" fixups :> toedit <- return $ extractSingle chosens name_fixups :> prim_fixups <- return $ flToNamesPrims fixups let changes_context = selectionContextPrim Last "inject" (patchSelOpts True opts) (Just (primSplitter (diffAlgorithm ? opts))) Nothing Nothing (rest_fixups :> injects) <- runSelection prim_fixups changes_context when (nullFL injects) $ do putStrLn "No changes selected!" exitSuccess -- Don't bother to update patch header since unsuspend will do that later let da = diffAlgorithm ? opts toeditNew = fmapFL_Named (mapFL_FL fromPrim . canonizeFL da . (injects +>+) . effect) toedit rNew <- unseal (mkRebase . Items) $ unseal (simplifyPushes da (mapFL_FL NameFixup name_fixups)) $ simplifyPushes da (mapFL_FL PrimFixup rest_fixups) $ ToEdit toeditNew :>: fromRebaseSelect rest_selects repository' <- tentativelyRemovePatches repository (compress ? opts) YesUpdateWorking (rOld :>: NilFL) repository'' <- tentativelyAddPatch repository' (compress ? opts) (verbosity ? opts) YesUpdateWorking (n2pia rNew) finalizeRepositoryChanges repository'' YesUpdateWorking (compress ? opts) return () obliterate :: DarcsCommand [DarcsFlag] obliterate = DarcsCommand { commandProgramName = "darcs" , commandName = "obliterate" , commandHelp = "Obliterate a patch that is currently suspended.\n" , commandDescription = "Obliterate a patch that is currently suspended.\n" , commandPrereq = amInHashedRepository , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = obliterateCmd , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc obliterateBasicOpts , commandDefaults = defaultFlags obliterateOpts , commandCheckOptions = ocheck obliterateOpts , commandParseOptions = onormalise obliterateOpts } where obliterateBasicOpts = O.diffAlgorithm obliterateOpts = obliterateBasicOpts `withStdOpts` oid obliterateCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () obliterateCmd _ opts _args = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RebaseJob (RebaseJobFlags (compress ? opts) (verbosity ? opts) YesUpdateWorking) $ \(repository :: Repository ('RepoType 'IsRebase) p wR wU wR) -> (do patches <- readRepo repository (rOld, Items ps, _) <- return $ takeHeadRebase patches let selects = toRebaseSelect ps -- TODO this selection doesn't need to respect dependencies let patches_context = selectionContextGeneric rsToPia First "obliterate" (obliteratePatchSelOpts opts) Nothing (chosen :> keep) <- runSelection selects patches_context when (nullFL chosen) $ do putStrLn "No patches selected!" exitSuccess let da = diffAlgorithm ? opts do_obliterate :: FL (RebaseItem p) wX wY -> FL (RebaseItem p) wY wZ -> Sealed (FL (RebaseItem p) wX) do_obliterate NilFL = Sealed do_obliterate (Fixup f :>: qs) = unseal (simplifyPush da f) . do_obliterate qs do_obliterate (ToEdit e :>: qs) = -- since Named doesn't have any witness context for the -- patch names, the AddName here will be inferred to be wX wX unseal (simplifyPush da (NameFixup (AddName (patch2patchinfo e)))) . unseal (simplifyPushes da (mapFL_FL PrimFixup (effect (patchcontents e)))) . do_obliterate qs let ps_to_keep = do_obliterate (fromRebaseSelect chosen) (fromRebaseSelect keep) rNew <- unseal (mkRebase . Items) ps_to_keep repository' <- tentativelyRemovePatches repository (compress ? opts) YesUpdateWorking (rOld :>: NilFL) repository'' <- tentativelyAddPatch repository' (compress ? opts) (verbosity ? opts) YesUpdateWorking (n2pia rNew) finalizeRepositoryChanges repository'' YesUpdateWorking (compress ? opts) return () ) :: IO () pullDescription :: String pullDescription = "Copy and apply patches from another repository, suspending any local patches that conflict." pullHelp :: String pullHelp = "Copy and apply patches from another repository, suspending any local patches that conflict." pull :: DarcsCommand [DarcsFlag] pull = DarcsCommand { commandProgramName = "darcs" , commandName = "pull" , commandHelp = pullHelp , commandDescription = pullDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[REPOSITORY]..."] , commandCommand = pullCmd RebasePatchApplier , commandPrereq = amInHashedRepository , commandCompleteArgs = prefArgs "repos" , commandArgdefaults = defaultRepo , commandAdvancedOptions = odesc pullAdvancedOpts , commandBasicOptions = odesc pullBasicOpts , commandDefaults = defaultFlags pullOpts , commandCheckOptions = ocheck pullOpts , commandParseOptions = onormalise pullOpts } where pullBasicOpts = O.matchSeveral ^ O.reorder ^ O.interactive ^ O.conflictsYes ^ O.externalMerge ^ O.runTest ^ O.dryRunXml ^ O.summary ^ O.selectDeps ^ O.setDefault ^ O.repoDir ^ O.allowUnrelatedRepos ^ O.diffAlgorithm pullAdvancedOpts = O.repoCombinator ^ O.compress ^ O.useIndex ^ O.remoteRepos ^ O.setScriptsExecutable ^ O.umask ^ O.restrictPaths ^ O.changesReverse ^ O.network pullOpts = pullBasicOpts `withStdOpts` pullAdvancedOpts applyDescription :: String applyDescription = "Apply a patch bundle, suspending any local patches that conflict." applyHelp :: String applyHelp = "Apply a patch bundle, suspending any local patches that conflict." stdindefault :: a -> [String] -> IO [String] stdindefault _ [] = return ["-"] stdindefault _ x = return x apply :: DarcsCommand [DarcsFlag] apply = DarcsCommand { commandProgramName = "darcs" , commandName = "apply" , commandHelp = applyHelp , commandDescription = applyDescription , commandExtraArgs = 1 , commandExtraArgHelp = [""] , commandCommand = applyCmd RebasePatchApplier , commandPrereq = amInHashedRepository , commandCompleteArgs = fileArgs , commandArgdefaults = const stdindefault , commandAdvancedOptions = odesc applyAdvancedOpts , commandBasicOptions = odesc applyBasicOpts , commandDefaults = defaultFlags applyOpts , commandCheckOptions = ocheck applyOpts , commandParseOptions = onormalise applyOpts } where applyBasicOpts = O.verify ^ O.reorder ^ O.interactive ^ O.dryRunXml ^ O.matchSeveral ^ O.repoDir ^ O.diffAlgorithm applyAdvancedOpts = O.reply ^ O.ccApply ^ O.happyForwarding ^ O.sendmail ^ O.useIndex ^ O.compress ^ O.setScriptsExecutable ^ O.umask ^ O.restrictPaths ^ O.changesReverse ^ O.pauseForGui applyOpts = applyBasicOpts `withStdOpts` applyAdvancedOpts data RebasePatchApplier = RebasePatchApplier instance PatchApplier RebasePatchApplier where type ApplierRepoTypeConstraint RebasePatchApplier rt = rt ~ 'RepoType 'IsRebase repoJob RebasePatchApplier opts f = StartRebaseJob (RebaseJobFlags (compress ? opts) (verbosity ? opts) YesUpdateWorking) (f PatchProxy) applyPatches RebasePatchApplier PatchProxy = applyPatchesForRebaseCmd applyPatchesForRebaseCmd :: forall p wR wU wX wT wZ . ( RepoPatch p, ApplyState p ~ Tree ) => String -> [DarcsFlag] -> String -> Repository ('RepoType 'IsRebase) p wR wU wT -> FL (PatchInfoAnd ('RepoType 'IsRebase) p) wX wT -> FL (PatchInfoAnd ('RepoType 'IsRebase) p) wX wZ -> IO () applyPatchesForRebaseCmd cmdName opts _from_whom repository us' to_be_applied = do printDryRunMessageAndExit cmdName (verbosity ? opts) (O.summary ? opts) (dryRun ? opts) (xmlOutput ? opts) (isInteractive True opts) to_be_applied setEnvDarcsPatches to_be_applied when (nullFL to_be_applied) $ do putStrLn $ "You don't want to " ++ cmdName ++ " any patches, and that's fine with me!" exitSuccess checkPaths opts to_be_applied putVerbose opts $ text $ "Will " ++ cmdName ++ " the following patches:" putVerbose opts $ vcat $ mapFL description to_be_applied usOk :> usConflicted <- return $ partitionConflictingFL (commuterIdFL selfCommuter) us' to_be_applied when (lengthFL usConflicted > 0) $ putInfo opts $ text "The following local patches are in conflict:" -- TODO: we assume the options apply only to the main -- command, review if there are any we should keep let patches_context = selectionContext LastReversed "suspend" applyPatchSelOpts Nothing Nothing (usKeep :> usToSuspend) <- runSelection usConflicted patches_context -- test all patches for hijacking and abort if rejected runHijackT RequestHijackPermission $ mapM_ (getAuthor "suspend" False Nothing) $ mapFL info usToSuspend (rOld, suspended, _) <- return $ takeHeadRebaseFL us' repository' <- doSuspend opts repository suspended rOld usToSuspend -- the new rebase patch containing the suspended patches is now in the repo -- and the suspended patches have been removed -- TODO This is a nasty hack, caused by the fact that readUnrecorded -- claims to read the tentative state but actual reads the committed state -- as a result we have to commit here so that tentativelyMergePatches does -- the right thing. finalizeRepositoryChanges repository' YesUpdateWorking (compress ? opts) >> revertRepositoryChanges repository' YesUpdateWorking Sealed pw <- tentativelyMergePatches repository' cmdName (allowConflicts opts) YesUpdateWorking (externalMerge ? opts) (wantGuiPause opts) (compress ? opts) (verbosity ? opts) (reorder ? opts) (diffingOpts opts) (usOk +>+ usKeep) to_be_applied invalidateIndex repository finalizeRepositoryChanges repository' YesUpdateWorking (compress ? opts) _ <- revertable $ applyToWorking repository' (verbosity ? opts) pw when (O.setScriptsExecutable ? opts == O.YesSetScriptsExecutable) $ setScriptsExecutablePatches pw putInfo opts $ text $ "Finished " ++ cmdName ++ "ing." -- TODO I doubt this is right, e.g. withContext should be inherited applyPatchSelOpts :: S.PatchSelectionOptions applyPatchSelOpts = S.PatchSelectionOptions { S.verbosity = O.NormalVerbosity , S.matchFlags = [] , S.interactive = True , S.selectDeps = O.PromptDeps -- option not supported, use default , S.summary = O.NoSummary , S.withContext = O.NoContext } obliteratePatchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions obliteratePatchSelOpts opts = (patchSelOpts True opts) { S.selectDeps = O.NoDeps } patchSelOpts :: Bool -> [DarcsFlag] -> S.PatchSelectionOptions patchSelOpts defInteractive flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = parseFlags O.matchSeveralOrLast flags , S.interactive = isInteractive defInteractive flags , S.selectDeps = selectDeps ? flags , S.summary = O.summary ? flags , S.withContext = O.NoContext } log :: DarcsCommand [DarcsFlag] log = DarcsCommand { commandProgramName = "darcs" , commandName = "log" , commandHelp = "List the currently suspended changes.\n" , commandDescription = "List the currently suspended changes" , commandPrereq = amInHashedRepository , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = logCmd , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc logAdvancedOpts , commandBasicOptions = odesc logBasicOpts , commandDefaults = defaultFlags logOpts , commandCheckOptions = ocheck logOpts , commandParseOptions = onormalise logOpts } where logBasicOpts = O.summary ^ O.interactive -- False logAdvancedOpts = oid logOpts = logBasicOpts `withStdOpts` logAdvancedOpts logCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () logCmd _ opts _files = withRepository (useCache ? opts) $ RebaseJob (RebaseJobFlags (compress ? opts) (verbosity ? opts) YesUpdateWorking) $ \repository -> do patches <- readRepo repository (_, Items ps, _) <- return $ takeHeadRebase patches let psToShow = toRebaseChanges ps if isInteractive False opts then viewChanges (patchSelOpts False opts) (mapFL Sealed2 psToShow) else do debugMessage "About to print the changes..." let printers = if hasXmlOutput opts then simplePrinters else fancyPrinters emptyPatchSet = PatchSet NilRL NilRL patchSet = appendPSFL emptyPatchSet psToShow logInfo <- getLogInfo (maxCount ? opts) (matchAny ? opts) (onlyToFiles ? opts) Nothing (\_ qs -> return qs) patchSet let logDoc = changelog opts patchSet logInfo putDocLnWith printers logDoc -- | changes is an alias for log changes :: DarcsCommand [DarcsFlag] changes = commandAlias "changes" Nothing log {- TODO: - amend-record shows the diff between the conflicted state and the resolution, which is unhelpful - testing - make aggregate commands - argument handling - what should happen to patch comment on unsuspend? - don't just drop explicit dependencies: - turn patchnames/explicit deps into patch type and use commutation - repo representation - seem to be able to get a messed up unrevert context - darcs pull/get can setup a rebase patch in a remote repo without the right format - rebase patches seem to parse as empty rather than failing?? - warn about suspending conflicts - indication of expected conflicts on unsuspend - why isn't ! when you do x accurate? - rebase obliterate for more efficient removing of suspended patches - rebase pull needs more UI work - automatically answer yes re suspension - offer all patches (so they can be kept in order) - or perhaps rebase suspend --complement? - rebase changes for viewing suspended patch - matching options for rebase unsuspend (etc) - make unsuspend actually display the patch helpfully like normal selection - amended patches will often be in both the target repo and in the rebase context, detect? - can we be more intelligent about conflict resolutions? - --all option to unsuspend - review other conflict options for unsuspend - warning message on suspend about not being able to unsuspend with unrecorded changes - aborting during a rebase pull or rebase suspend causes it to leave the repo marked for rebase - rebase suspend needs --match - patch count: get English right in suspended patch(es) - darcs check should check integrity of rebase patch - review existence of reify and inject commands - bit of an internals hack - need to move rebase to front before adding amend-record hint (and test this) - print something while moving rebase to front -} darcs-2.14.5/src/Darcs/UI/Commands/Record.hs0000644000000000000000000004012007346545000016540 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE OverloadedStrings #-} module Darcs.UI.Commands.Record ( record , commit , recordConfig, RecordConfig(..) -- needed for darcsden ) where import Prelude () import Darcs.Prelude import Data.Foldable ( traverse_ ) import Control.Exception ( handleJust ) import Control.Monad ( when, unless, void ) import Data.List ( sort ) import Data.Char ( ord ) import System.Exit ( exitFailure, exitSuccess, ExitCode(..) ) import System.Directory ( removeFile ) import Darcs.Patch.PatchInfoAnd ( n2pia ) import Darcs.Repository ( Repository , withRepoLock , RepoJob(..) , tentativelyAddPatch , finalizeRepositoryChanges , invalidateIndex , unrecordedChanges , readRecorded ) import Darcs.Patch ( IsRepoType, RepoPatch, PrimOf, fromPrims ) import Darcs.Patch.Named.Wrapped ( namepatch, adddeps ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (:>)(..), nullFL ) import Darcs.Patch.Info ( PatchInfo ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Split ( primSplitter ) import Darcs.UI.SelectChanges ( WhichChanges(..) , selectionContextPrim , runSelection , askAboutDepends ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions(..) ) import Darcs.Util.Path ( SubPath, toFilePath, AbsolutePath ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts , nodefaults , commandAlias , setEnvDarcsFiles , setEnvDarcsPatches , amInHashedRepository ) import Darcs.UI.Commands.Util ( announceFiles, filterExistingPaths, testTentativeAndMaybeExit ) import Darcs.UI.Completion ( modifiedFileArgs ) import Darcs.UI.Flags ( DarcsFlag , fileHelpAuthor , getAuthor , getDate , diffOpts , scanKnown , fixSubPaths ) import Darcs.UI.Options ( DarcsOption, (^), odesc, ocheck, oparse, defaultFlags ) import Darcs.UI.PatchHeader ( getLog ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking (..), DryRun(NoDryRun), ScanKnown(..) ) import Darcs.Util.Exception ( clarifyErrors ) import Darcs.Util.Prompt ( promptYorn ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Global ( darcsLastMessage ) import Darcs.Patch.Progress ( progressFL ) import Darcs.Util.Printer ( putDocLn, text, (<+>) ) import Darcs.Util.Text ( pathlist ) import Darcs.Util.Tree( Tree ) recordDescription :: String recordDescription = "Create a patch from unrecorded changes." recordHelp :: String recordHelp = "The `darcs record` command is used to create a patch from changes in\n" ++ "the working tree. If you specify a set of files and directories,\n" ++ "changes to other files will be skipped.\n" ++ "\n" ++ recordHelp' ++ "\n" ++ recordHelp'' recordBasicOpts :: DarcsOption a (Maybe String -> Maybe String -> O.TestChanges -> Maybe Bool -> Bool -> Bool -> Maybe O.AskLongComment -> O.LookFor -> Maybe String -> O.WithContext -> O.DiffAlgorithm -> a) recordBasicOpts = O.patchname ^ O.author ^ O.testChanges ^ O.interactive ^ O.pipe ^ O.askDeps ^ O.askLongComment ^ O.lookfor ^ O.repoDir ^ O.withContext ^ O.diffAlgorithm recordAdvancedOpts :: DarcsOption a (O.Logfile -> O.Compression -> O.UseIndex -> O.UMask -> O.SetScriptsExecutable -> O.IncludeBoring -> a) recordAdvancedOpts = O.logfile ^ O.compress ^ O.useIndex ^ O.umask ^ O.setScriptsExecutable ^ O.includeBoring data RecordConfig = RecordConfig { patchname :: Maybe String , author :: Maybe String , testChanges :: O.TestChanges , interactive :: Maybe Bool , pipe :: Bool , askDeps :: Bool , askLongComment :: Maybe O.AskLongComment , lookfor :: O.LookFor , _workingRepoDir :: Maybe String , withContext :: O.WithContext , diffAlgorithm :: O.DiffAlgorithm , verbosity :: O.Verbosity , logfile :: O.Logfile , compress :: O.Compression , useIndex :: O.UseIndex , umask :: O.UMask , sse :: O.SetScriptsExecutable , includeBoring :: O.IncludeBoring , useCache :: O.UseCache } recordConfig :: [DarcsFlag] -> RecordConfig recordConfig = oparse (recordBasicOpts ^ O.verbosity ^ recordAdvancedOpts ^ O.useCache) RecordConfig record :: DarcsCommand RecordConfig record = DarcsCommand { commandProgramName = "darcs" , commandName = "record" , commandHelp = recordHelp , commandDescription = recordDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[FILE or DIRECTORY]..."] , commandCommand = recordCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = modifiedFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc recordAdvancedOpts , commandBasicOptions = odesc recordBasicOpts , commandDefaults = defaultFlags recordOpts , commandCheckOptions = ocheck recordOpts , commandParseOptions = recordConfig } where recordOpts = recordBasicOpts `withStdOpts` recordAdvancedOpts -- | commit is an alias for record commit :: DarcsCommand RecordConfig commit = commandAlias "commit" Nothing record reportNonExisting :: ScanKnown -> ([SubPath], [SubPath]) -> IO () reportNonExisting scan (paths_only_in_working, _) = do unless (scan /= ScanKnown || null paths_only_in_working) $ putDocLn $ "These paths are not yet in the repository and will be added:" <+> pathlist (map toFilePath paths_only_in_working) recordCmd :: (AbsolutePath, AbsolutePath) -> RecordConfig -> [String] -> IO () recordCmd fps cfg args = do checkNameIsNotOption (patchname cfg) (isInteractive cfg) withRepoLock NoDryRun (useCache cfg) YesUpdateWorking (umask cfg) $ RepoJob $ \(repository :: Repository rt p wR wU wR) -> do let scan = scanKnown (O.adds (lookfor cfg)) (includeBoring cfg) existing_files <- do files <- if null args then return Nothing else Just . sort <$> fixSubPaths fps args when (files == Just []) $ fail "No valid arguments were given." files' <- traverse (filterExistingPaths repository (verbosity cfg) (useIndex cfg) scan (O.moves (lookfor cfg))) files when (verbosity cfg /= O.Quiet) $ traverse_ (reportNonExisting scan) files' let files'' = fmap snd files' when (files'' == Just []) $ fail "None of the files you specified exist." return files'' announceFiles (verbosity cfg) existing_files "Recording changes in" debugMessage "About to get the unrecorded changes." changes <- unrecordedChanges (diffingOpts cfg) (O.moves (lookfor cfg)) (O.replaces (lookfor cfg)) repository existing_files debugMessage "I've got unrecorded changes." case changes of NilFL | not (askDeps cfg) -> do -- We need to grab any input waiting for us, since we -- might break scripts expecting to send it to us; we -- don't care what that input is, though. void (getDate (pipe cfg)) putStrLn "No changes!" exitFailure _ -> doRecord repository cfg existing_files changes -- | Check user specified patch name is not accidentally a command line flag checkNameIsNotOption :: Maybe String -> Bool -> IO () checkNameIsNotOption Nothing _ = return () checkNameIsNotOption _ False = return () checkNameIsNotOption (Just name) True = when (length name == 1 || (length name == 2 && head name == '-')) $ do confirmed <- promptYorn $ "You specified " ++ show name ++ " as the patch name. Is that really what you want?" unless confirmed $ putStrLn "Okay, aborting the record." >> exitFailure doRecord :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wR -> RecordConfig -> Maybe [SubPath] -> FL (PrimOf p) wR wX -> IO () doRecord repository cfg files ps = do date <- getDate (pipe cfg) my_author <- getAuthor (author cfg) (pipe cfg) debugMessage "I'm slurping the repository." pristine <- readRecorded repository debugMessage "About to select changes..." (chs :> _ ) <- runSelection ps $ selectionContextPrim First "record" (patchSelOpts cfg) (Just (primSplitter (diffAlgorithm cfg))) (map toFilePath <$> files) (Just pristine) when (not (askDeps cfg) && nullFL chs) $ do putStrLn "Ok, if you don't want to record anything, that's fine!" exitSuccess handleJust onlySuccessfulExits (\_ -> return ()) $ do deps <- if askDeps cfg then askAboutDepends repository chs (patchSelOpts cfg) [] else return [] when (askDeps cfg) $ debugMessage "I've asked about dependencies." if nullFL chs && null deps then putStrLn "Ok, if you don't want to record anything, that's fine!" else do setEnvDarcsFiles chs (name, my_log, logf) <- getLog (patchname cfg) (pipe cfg) (logfile cfg) (askLongComment cfg) Nothing chs debugMessage ("Patch name as received from getLog: " ++ show (map ord name)) doActualRecord repository cfg name date my_author my_log logf deps chs doActualRecord :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wR -> RecordConfig -> String -> String -> String -> [String] -> Maybe String -> [PatchInfo] -> FL (PrimOf p) wR wX -> IO () doActualRecord repository cfg name date my_author my_log logf deps chs = do debugMessage "Writing the patch file..." mypatch <- namepatch date name my_author my_log $ fromPrims $ progressFL "Writing changes:" chs let pia = n2pia $ adddeps mypatch deps -- We don't care about the returned updated repository _ <- tentativelyAddPatch repository (compress cfg) (verbosity cfg) YesUpdateWorking $ pia invalidateIndex repository debugMessage "Applying to pristine..." testTentativeAndMaybeExit repository (verbosity cfg) (testChanges cfg) (sse cfg) (isInteractive cfg) ("you have a bad patch: '" ++ name ++ "'") "record it" (Just failuremessage) finalizeRepositoryChanges repository YesUpdateWorking (compress cfg) `clarifyErrors` failuremessage debugMessage "Syncing timestamps..." removeLogFile logf unless (verbosity cfg == O.Quiet) $ putDocLn $ text $ "Finished recording patch '" ++ name ++ "'" setEnvDarcsPatches (pia :>: NilFL) where removeLogFile :: Maybe String -> IO () removeLogFile Nothing = return () removeLogFile (Just lf) | lf == darcsLastMessage = return () | otherwise = removeFile lf failuremessage = "Failed to record patch '"++name++"'" ++ case logf of Just lf -> "\nLogfile left in "++lf++"." Nothing -> "" recordHelp' :: String recordHelp' = unlines [ "Every patch has a name, an optional description, an author and a date." , "" , "Darcs will launch a text editor (see `darcs help environment`) after the" , "interactive selection, to let you enter the patch name (first line) and" , "the patch description (subsequent lines)." , "" , "You can supply the patch name in advance with the `-m` option, in which" , "case no text editor is launched, unless you use `--edit-long-comment`." , "" , "The patch description is an optional block of free-form text. It is" , "used to supply additional information that doesn't fit in the patch" , "name. For example, it might include a rationale of WHY the change was" , "necessary." , "" , "A technical difference between patch name and patch description, is" , "that matching with the flag `-p` is only done on patch names." , "" , "Finally, the `--logfile` option allows you to supply a file that already" , "contains the patch name and description. This is useful if a previous" , "record failed and left a `_darcs/patch_description.txt` file." , "" , unlines fileHelpAuthor , "If you want to manually define any explicit dependencies for your patch," , "you can use the `--ask-deps` flag. Some dependencies may be automatically" , "inferred from the patch's content and cannot be removed. A patch with" , "specific dependencies can be empty." , "" , "The patch date is generated automatically. It can only be spoofed by" , "using the `--pipe` option." , "" , "If you run record with the `--pipe` option, you will be prompted for" , "the patch date, author, and the long comment. The long comment will extend" , "until the end of file or stdin is reached. This interface is intended for" , "scripting darcs, in particular for writing repository conversion scripts." , "The prompts are intended mostly as a useful guide (since scripts won't" , "need them), to help you understand the input format. Here's an example of" , "what the `--pipe` prompts look like:" , "" , " What is the date? Mon Nov 15 13:38:01 EST 2004" , " Who is the author? David Roundy" , " What is the log? One or more comment lines" ] onlySuccessfulExits :: ExitCode -> Maybe () onlySuccessfulExits ExitSuccess = Just () onlySuccessfulExits _ = Nothing recordHelp'' :: String recordHelp'' = "If a test command has been defined with `darcs setpref`, attempting to\n" ++ "record a patch will cause the test command to be run in a clean copy\n" ++ "of the working tree (that is, including only recorded changes). If\n" ++ "the test fails, you will be offered to abort the record operation.\n" ++ "\n" ++ "The `--set-scripts-executable` option causes scripts to be made\n" ++ "executable in the clean copy of the working tree, prior to running the\n" ++ "test. See `darcs clone` for an explanation of the script heuristic.\n" ++ "\n" ++ "If your test command is tediously slow (e.g. `make all`) and you are\n" ++ "recording several patches in a row, you may wish to use `--no-test` to\n" ++ "skip all but the final test.\n" ++ "\n" ++ "To see some context (unchanged lines) around each change, use the\n" ++ "`--unified` option.\n" patchSelOpts :: RecordConfig -> S.PatchSelectionOptions patchSelOpts cfg = S.PatchSelectionOptions { S.verbosity = verbosity cfg , S.matchFlags = [] , S.interactive = isInteractive cfg , S.selectDeps = O.PromptDeps -- option not supported, use default , S.summary = O.NoSummary -- option not supported, use default , S.withContext = withContext cfg } diffingOpts :: RecordConfig -> (O.UseIndex, O.ScanKnown, O.DiffAlgorithm) diffingOpts cfg = diffOpts (useIndex cfg) (O.adds (lookfor cfg)) O.NoIncludeBoring (diffAlgorithm cfg) isInteractive :: RecordConfig -> Bool isInteractive = maybe True id . interactive darcs-2.14.5/src/Darcs/UI/Commands/Remove.hs0000644000000000000000000002054207346545000016565 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Remove ( remove, rm, unadd ) where import Prelude () import Darcs.Prelude import Control.Monad ( when, foldM ) import Darcs.UI.Commands ( DarcsCommand(..) , withStdOpts, nodefaults , commandAlias, commandStub , putWarning, putInfo , amInHashedRepository ) import Darcs.UI.Commands.Util ( expandDirs ) import Darcs.UI.Completion ( knownFileArgs ) import Darcs.UI.Flags ( DarcsFlag, useCache, dryRun, umask, diffAlgorithm, fixSubPaths, quiet ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking (..) ) import Darcs.Repository ( Repository , withRepoLock , RepoJob(..) , addToPending , readRecordedAndPending , readUnrecorded ) import Darcs.Repository.Diff( treeDiff ) import Darcs.Patch ( RepoPatch, PrimOf, PrimPatch, adddir, rmdir, addfile, rmfile, listTouchedFiles ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (+>+), nullFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), Gap(..), FreeLeft, unFreeLeft ) import Darcs.Repository.Prefs ( filetypeFunction, FileType ) import Darcs.Util.Tree( Tree, TreeItem(..), find, modifyTree, expand, list ) import Darcs.Util.Path( anchorPath, AnchoredPath, fn2fp, SubPath, sp2fn , AbsolutePath, floatPath ) import Darcs.Util.Printer ( text, vcat ) removeDescription :: String removeDescription = "Remove files from version control." removeHelp :: String removeHelp = "The `darcs remove` command exists primarily for symmetry with `darcs\n" ++ "add`, as the normal way to remove a file from version control is\n" ++ "simply to delete it from the working tree. This command is only\n" ++ "useful in the unusual case where one wants to record a removal patch\n" ++ "WITHOUT deleting the copy in the working tree (which can be re-added).\n" ++ "\n" ++ "Note that applying a removal patch to a repository (e.g. by pulling\n" ++ "the patch) will ALWAYS affect the working tree of that repository.\n" remove :: DarcsCommand [DarcsFlag] remove = DarcsCommand { commandProgramName = "darcs" , commandName = "remove" , commandHelp = removeHelp , commandDescription = removeDescription , commandExtraArgs = -1 , commandExtraArgHelp = [" ..."] , commandCommand = removeCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = knownFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc removeAdvancedOpts , commandBasicOptions = odesc removeBasicOpts , commandDefaults = defaultFlags removeOpts , commandCheckOptions = ocheck removeOpts , commandParseOptions = onormalise removeOpts } where removeBasicOpts = O.repoDir ^ O.recursive removeAdvancedOpts = O.umask removeOpts = removeBasicOpts `withStdOpts` removeAdvancedOpts removeCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () removeCmd fps opts relargs = do when (null relargs) $ fail "Nothing specified, nothing removed." origfiles <- fixSubPaths fps relargs when (null origfiles) $ fail "No valid arguments were given." withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do args <- if parseFlags O.recursive opts then reverse `fmap` expandDirs False origfiles else return origfiles Sealed p <- makeRemovePatch opts repository args -- TODO whether command fails depends on verbosity BAD BAD BAD when (nullFL p && not (null origfiles) && not (quiet opts)) $ fail "No files were removed." addToPending repository YesUpdateWorking p putInfo opts $ vcat $ map text $ ["Will stop tracking:"] ++ listTouchedFiles p -- | makeRemovePatch builds a list of patches to remove the given filepaths. -- This function does not recursively process directories. The 'Recursive' -- flag should be handled by the caller by adding all offspring of a directory -- to the files list. makeRemovePatch :: (RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> Repository rt p wR wU wT -> [SubPath] -> IO (Sealed (FL (PrimOf p) wU)) makeRemovePatch opts repository files = do recorded <- expand =<< readRecordedAndPending repository unrecorded <- readUnrecorded repository $ Just files ftf <- filetypeFunction result <- foldM removeOnePath (ftf,recorded,unrecorded, []) $ map (floatPath . fn2fp . sp2fn) files case result of (_, _, _, patches) -> return $ unFreeLeft $ foldr (joinGap (+>+)) (emptyGap NilFL) $ reverse patches where removeOnePath (ftf, recorded, unrecorded, patches) f = do let recorded' = modifyTree recorded f Nothing unrecorded' = modifyTree unrecorded f Nothing local <- makeRemoveGap opts ftf recorded unrecorded unrecorded' f -- we can tell if the remove succeeded by looking if local is -- empty. If the remove succeeded, we should pass on updated -- recorded and unrecorded that reflect the removal return $ case local of Just gap -> (ftf, recorded', unrecorded', gap : patches) _ -> (ftf, recorded, unrecorded, patches) -- | Takes a file path and returns the FL of patches to remove that, wrapped in -- a 'Gap'. -- Returns 'Nothing' in case the path cannot be removed (if it is not tracked, -- or if it's a directory and it's not tracked). -- The three 'Tree' arguments are the recorded state, the unrecorded state -- excluding the removal of this file, and the unrecorded state including the -- removal of this file. makeRemoveGap :: PrimPatch prim => [DarcsFlag] -> (FilePath -> FileType) -> Tree IO -> Tree IO -> Tree IO -> AnchoredPath -> IO (Maybe (FreeLeft (FL prim))) makeRemoveGap opts ftf recorded unrecorded unrecorded' f = case (find recorded f, find unrecorded f) of (Just (SubTree _), Just (SubTree unrecordedChildren)) -> if not $ null (list unrecordedChildren) then skipAndWarn "it is not empty" else return $ Just $ freeGap (rmdir f_fp :>: NilFL) (Just (File _), Just (File _)) -> do Just `fmap` treeDiff (diffAlgorithm ? opts) ftf unrecorded unrecorded' (Just (File _), _) -> return $ Just $ freeGap (addfile f_fp :>: rmfile f_fp :>: NilFL) (Just (SubTree _), _) -> return $ Just $ freeGap (adddir f_fp :>: rmdir f_fp :>: NilFL) (_, _) -> skipAndWarn "it is not tracked by darcs" where f_fp = anchorPath "" f skipAndWarn reason = do putWarning opts . text $ "Can't remove " ++ f_fp ++ " (" ++ reason ++ ")" return Nothing rmDescription :: String rmDescription = "Help newbies find `darcs remove'." rmHelp :: String rmHelp = "The `darcs rm' command does nothing.\n" ++ "\n" ++ "The normal way to remove a file from version control is simply to\n" ++ "delete it from the working tree. To remove a file from version\n" ++ "control WITHOUT affecting the working tree, see `darcs remove'.\n" rm :: DarcsCommand [DarcsFlag] rm = commandStub "rm" rmHelp rmDescription remove unadd :: DarcsCommand [DarcsFlag] unadd = commandAlias "unadd" Nothing remove darcs-2.14.5/src/Darcs/UI/Commands/Repair.hs0000644000000000000000000001667007346545000016561 0ustar0000000000000000-- Copyright (C) 2002-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE RecordWildCards #-} module Darcs.UI.Commands.Repair ( repair, check ) where import Prelude () import Darcs.Prelude import Control.Monad ( when, unless ) import Control.Exception ( catch, IOException ) import System.Exit ( ExitCode(..), exitWith ) import System.Directory( renameFile ) import System.FilePath ( () ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults , putInfo, amInHashedRepository ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags ( DarcsFlag, verbosity, dryRun, umask, useIndex , useCache, compress, diffAlgorithm, quiet ) import Darcs.UI.Options ( DarcsOption, (^), oid , odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking (..) ) import Darcs.Repository.Repair ( replayRepository, checkIndex, replayRepositoryInTemp , RepositoryConsistency(..) ) import Darcs.Repository ( Repository, withRepository, readRecorded, RepoJob(..) , withRepoLock, replacePristine, writePatchSet ) import Darcs.Repository.Prefs ( filetypeFunction ) import Darcs.Repository.Diff( treeDiff ) import Darcs.Patch ( RepoPatch, showNicely, PrimOf ) import Darcs.Patch.Witnesses.Ordered ( FL(..) ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), unFreeLeft ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Printer ( text, ($$), (<+>) ) import Darcs.Util.Tree( Tree ) repairDescription :: String repairDescription = "Repair a corrupted repository." repairHelp :: String repairHelp = "The `darcs repair` command attempts to fix corruption in the current\n" ++ "repository. Currently it can only repair damage to the pristine tree,\n" ++ "which is where most corruption occurs.\n" ++ "This command rebuilds a pristine tree by applying successively the\n" ++ "patches in the repository to an empty tree.\n" ++ "\n" ++ "The flag `--dry-run` make this operation read-only, making darcs exit\n" ++ "unsuccessfully (with a non-zero exit status) if the rebuilt pristine is\n" ++ "different from the current pristine.\n" commonBasicOpts :: DarcsOption a (Maybe String -> O.UseIndex -> O.DiffAlgorithm -> a) commonBasicOpts = O.repoDir ^ O.useIndex ^ O.diffAlgorithm repair :: DarcsCommand [DarcsFlag] repair = DarcsCommand { commandProgramName = "darcs" , commandName = "repair" , commandHelp = repairHelp , commandDescription = repairDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = withFpsAndArgs repairCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , .. } where basicOpts = commonBasicOpts ^ O.dryRun advancedOpts = O.umask allOpts = basicOpts `withStdOpts` advancedOpts commandAdvancedOptions = odesc advancedOpts commandBasicOptions = odesc basicOpts commandDefaults = defaultFlags allOpts commandCheckOptions = ocheck allOpts commandParseOptions = onormalise allOpts withFpsAndArgs :: (b -> d) -> a -> b -> c -> d withFpsAndArgs cmd _ opts _ = cmd opts repairCmd :: [DarcsFlag] -> IO () repairCmd opts = case dryRun ? opts of O.YesDryRun -> checkCmd opts O.NoDryRun -> withRepoLock O.NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do replayRepository (diffAlgorithm ? opts) repository (compress ? opts) (verbosity ? opts) $ \state -> case state of RepositoryConsistent -> putStrLn "The repository is already consistent, no changes made." BrokenPristine tree -> do putStrLn "Fixing pristine tree..." replacePristine repository tree BrokenPatches tree newps -> do putStrLn "Writing out repaired patches..." _ <- writePatchSet newps (useCache ? opts) putStrLn "Fixing pristine tree..." replacePristine repository tree index_ok <- checkIndex repository (quiet opts) unless index_ok $ do renameFile (darcsdir "index") (darcsdir "index.bad") putStrLn "Bad index discarded." -- |check is an alias for repair, with implicit DryRun flag. check :: DarcsCommand [DarcsFlag] check = DarcsCommand { commandProgramName = "darcs" , commandName = "check" , commandHelp = "See `darcs repair` for details." , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = withFpsAndArgs checkCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , .. } where basicOpts = commonBasicOpts advancedOpts = oid allOpts = basicOpts `withStdOpts` advancedOpts commandAdvancedOptions = odesc advancedOpts commandBasicOptions = odesc basicOpts commandDefaults = defaultFlags allOpts commandCheckOptions = ocheck allOpts commandParseOptions = onormalise allOpts commandDescription = "Alias for `darcs " ++ commandName repair ++ " --dry-run'." checkCmd :: [DarcsFlag] -> IO () checkCmd opts = withRepository (useCache ? opts) $ RepoJob $ \repository -> do state <- replayRepositoryInTemp (diffAlgorithm ? opts) repository (compress ? opts) (verbosity ? opts) failed <- case state of RepositoryConsistent -> do putInfo opts $ text "The repository is consistent!" return False BrokenPristine newpris -> do brokenPristine opts repository newpris return True BrokenPatches newpris _ -> do brokenPristine opts repository newpris putInfo opts $ text "Found broken patches." return True bad_index <- if useIndex ? opts == O.IgnoreIndex then return False else not <$> checkIndex repository (quiet opts) when bad_index $ putInfo opts $ text "Bad index." exitWith $ if failed || bad_index then ExitFailure 1 else ExitSuccess brokenPristine :: forall rt p wR wU wT . (RepoPatch p) => [DarcsFlag] -> Repository rt p wR wU wT -> Tree IO -> IO () brokenPristine opts repository newpris = do putInfo opts $ text "Looks like we have a difference..." mc' <- (Just `fmap` readRecorded repository) `catch` (\(_ :: IOException) -> return Nothing) case mc' of Nothing -> do putInfo opts $ text "cannot compute that difference, try repair" putInfo opts $ text "" $$ text "Inconsistent repository" Just mc -> do ftf <- filetypeFunction Sealed (diff :: FL (PrimOf p) wR wR2) <- unFreeLeft `fmap` treeDiff (diffAlgorithm ? opts) ftf newpris mc :: IO (Sealed (FL (PrimOf p) wR)) putInfo opts $ case diff of NilFL -> text "Nothing" patch -> text "Difference: " <+> showNicely patch putInfo opts $ text "" $$ text "Inconsistent repository!" darcs-2.14.5/src/Darcs/UI/Commands/Replace.hs0000644000000000000000000003067207346545000016710 0ustar0000000000000000-- Copyright (C) 2002-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Replace ( replace , defaultToks ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString as B import Data.Char ( isSpace ) import Data.Maybe ( fromJust, isJust ) import Control.Exception ( catch, IOException ) import Control.Monad ( unless, filterM, void ) import Darcs.Util.Tree( readBlob, modifyTree, findFile, TreeItem(..), Tree , makeBlobBS ) import Darcs.Util.Path( SubPath, toFilePath, AbsolutePath ) import Darcs.UI.Flags ( DarcsFlag , verbosity, useCache, dryRun, umask, diffAlgorithm, fixSubPaths ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking(..) ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInHashedRepository ) import Darcs.UI.Completion ( knownFileArgs ) import Darcs.Repository.Diff( treeDiff ) import Darcs.Patch ( PrimPatch, tokreplace, forceTokReplace , maybeApplyToTree ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.RegChars ( regChars ) import Darcs.Repository ( withRepoLock , RepoJob(..) , addToPending , applyToWorking , readUnrecorded ) import Darcs.Patch.TokenReplace ( defaultToks ) import Darcs.Repository.Prefs ( FileType(TextFile) ) import Darcs.Util.Path ( floatSubPath ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (+>+), concatFL, toFL, nullFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), mapSeal, FreeLeft, Gap(..), unFreeLeft, unseal ) replaceDescription :: String replaceDescription = "Substitute one word for another." replaceHelp :: String replaceHelp = "In addition to line-based patches, Darcs supports a limited form of\n" ++ "lexical substitution. Files are treated as sequences of words, and\n" ++ "each occurrence of the old word is replaced by the new word.\n" ++ "This is intended to provide a clean way to rename a function or\n" ++ "variable. Such renamings typically affect lines all through the\n" ++ "source code, so a traditional line-based patch would be very likely to\n" ++ "conflict with other branches, requiring manual merging.\n" ++ "\n" ++ "Files are tokenized according to one simple rule: words are strings of\n" ++ "valid token characters, and everything between them (punctuation and\n" ++ -- FIXME: this heuristic is ham-fisted and silly. Can we drop it? "whitespace) is discarded. By default, valid token characters are\n" ++ "letters, numbers and the underscore (i.e. `[A-Za-z0-9_]`). However if\n" ++ "the old and/or new token contains either a hyphen or period, BOTH\n" ++ "hyphen and period are treated as valid (i.e. `[A-Za-z0-9_.-]`).\n" ++ "\n" ++ "The set of valid characters can be customized using the `--token-chars`\n" ++ "option. The argument must be surrounded by square brackets. If a\n" ++ "hyphen occurs between two characters in the set, it is treated as a\n" ++ "set range. For example, in most locales `[A-Z]` denotes all uppercase\n" ++ "letters. If the first character is a caret, valid tokens are taken to\n" ++ "be the complement of the remaining characters. For example, `[^:\\n]`\n" ++ "could be used to match fields in the passwd(5), where records and\n" ++ "fields are separated by newlines and colons respectively.\n" ++ "\n" ++ "If you choose to use `--token-chars`, you are STRONGLY encouraged to do\n" ++ "so consistently. The consequences of using multiple replace patches\n" ++ "with different `--token-chars` arguments on the same file are not well\n" ++ "tested nor well understood.\n" ++ "\n" ++ "By default Darcs will refuse to perform a replacement if the new token\n" ++ "is already in use, because the replacements would be not be\n" ++ "distinguishable from the existing tokens. This behaviour can be\n" ++ "overridden by supplying the `--force` option, but an attempt to `darcs\n" ++ "rollback` the resulting patch will affect these existing tokens.\n" ++ "\n" ++ "Limitations:\n" ++ "\n" ++ "The tokenizer treats files as byte strings, so it is not possible for\n" ++ "`--token-chars` to include multi-byte characters, such as the non-ASCII\n" ++ "parts of UTF-8. Similarly, trying to replace a \"high-bit\" character\n" ++ "from a unibyte encoding will also result in replacement of the same\n" ++ "byte in files with different encodings. For example, an acute a from\n" ++ "ISO 8859-1 will also match an alpha from ISO 8859-7.\n" ++ "\n" ++ "Due to limitations in the patch file format, `--token-chars` arguments\n" ++ "cannot contain literal whitespace. For example, `[^ \\n\\t]` cannot be\n" ++ "used to declare all characters except the space, tab and newline as\n" ++ "valid within a word, because it contains a literal space.\n" ++ "\n" ++ "Unlike POSIX regex(7) bracket expressions, character classes (such as\n" ++ "`[[:alnum:]]`) are NOT supported by `--token-chars`, and will be silently\n" ++ "treated as a simple set of characters.\n" replace :: DarcsCommand [DarcsFlag] replace = DarcsCommand { commandProgramName = "darcs" , commandName = "replace" , commandHelp = replaceHelp , commandDescription = replaceDescription , commandExtraArgs = -1 , commandExtraArgHelp = [ "" , "" , " ..." ] , commandCommand = replaceCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = replaceArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc replaceAdvancedOpts , commandBasicOptions = odesc replaceBasicOpts , commandDefaults = defaultFlags replaceOpts , commandCheckOptions = ocheck replaceOpts , commandParseOptions = onormalise replaceOpts } where replaceBasicOpts = O.tokens ^ O.forceReplace ^ O.repoDir replaceAdvancedOpts = O.useIndex ^ O.umask replaceOpts = replaceBasicOpts `withStdOpts` replaceAdvancedOpts replaceArgs :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO [String] replaceArgs fps flags args = if length args < 2 then return [] else knownFileArgs fps flags args replaceCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () replaceCmd fps opts (old : new : relfs@(_ : _)) = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do fs <- fixSubPaths fps relfs toks <- chooseToks (O.tokens ? opts) old new let checkToken tok = unless (isTok toks tok) $ fail $ "'" ++ tok ++ "' is not a valid token!" mapM_ checkToken [ old, new ] working <- readUnrecorded repository Nothing files <- filterM (exists working) fs Sealed replacePs <- mapSeal concatFL . toFL <$> mapM (doReplace toks working) files -- Note: addToPending takes care of commuting the replace patch and -- everything it depends on past the diff between pending and working addToPending repository YesUpdateWorking replacePs void $ applyToWorking repository (verbosity ? opts) replacePs `catch` \(e :: IOException) -> bug $ "Can't do replace on working!\n" ++ show e where exists tree file = if isJust $ findFile tree (floatSubPath file) then return True else do putStrLn $ skipmsg file return False skipmsg f = "Skipping file '" ++ toFilePath f ++ "' which isn't in the repository." doReplace :: forall prim . (PrimPatch prim, ApplyState prim ~ Tree) => String -> Tree IO -> SubPath -> IO (FreeLeft (FL prim)) doReplace toks work f = do workReplaced <- maybeApplyToTree replacePatch work case workReplaced of Just _ -> do return $ joinGap (:>:) (freeGap replacePatch) gapNilFL Nothing | O.forceReplace ? opts -> getForceReplace f toks work | otherwise -> putStrLn existsMsg >> return gapNilFL where existsMsg = "Skipping file '" ++ fp ++ "'\nPerhaps the working" ++ " version of this file already contains '" ++ new ++ "'?\nUse the --force option to override." gapNilFL = emptyGap NilFL fp = toFilePath f replacePatch = tokreplace fp toks old new ftf _ = TextFile -- | getForceReplace returns the list of patches that consists first of -- hunk patches to normalise all occurences of the target token (changing -- them back to the source token) and then the replace patches from -- oldToken -> newToken. getForceReplace :: PrimPatch prim => SubPath -> String -> Tree IO -> IO (FreeLeft (FL prim)) getForceReplace f toks tree = do let path = floatSubPath f content <- readBlob $ fromJust $ findFile tree path let newcontent = forceTokReplace toks (BC.pack new) (BC.pack old) (B.concat $ BL.toChunks content) tree' = modifyTree tree path . Just . File $ makeBlobBS newcontent normaliseNewTokPatch <- treeDiff (diffAlgorithm ? opts) ftf tree tree' unless (unseal nullFL (unFreeLeft normaliseNewTokPatch)) $ putStrLn $ "Don't be surprised!\n" ++ "I've changed all instances of '" ++ new ++ "' to '" ++ old ++ "' first\n" ++ "so that darcs replace can token-replace them" ++ " back into '" ++ new ++ "' again." return . joinGap (+>+) normaliseNewTokPatch $ freeGap $ tokreplace (toFilePath f) toks old new :>: NilFL replaceCmd _ _ [_, _] = fail "You need to supply a list of files to replace in!" replaceCmd _ _ _ = fail "Usage: darcs replace ..." filenameToks :: String filenameToks = "A-Za-z_0-9\\-\\." -- | Given a set of characters and a string, returns true iff the string -- contains only characters from the set. A set beginning with a caret (@^@) is -- treated as a complementary set. isTok :: String -> String -> Bool isTok _ "" = False isTok toks s = all (regChars toks) s -- | This function checks for @--token-chars@ on the command-line. If found, -- it validates the argument and returns it, without the surrounding square -- brackets. Otherwise, it returns either 'defaultToks' or 'filenameToks' as -- explained in 'replaceHelp'. -- -- Note: Limitations in the current replace patch file format prevents tokens -- and token-char specifiers from containing any whitespace. chooseToks :: Maybe String -> String -> String -> IO String chooseToks (Just t) a b | length t <= 2 = badTokenSpec $ "It must contain more than 2 characters, because it" ++ " should be enclosed in square brackets" | head t /= '[' || last t /= ']' = badTokenSpec "It should be enclosed in square brackets" | '^' == head tok && length tok == 1 = badTokenSpec "Must be at least one character in the complementary set" | any isSpace t = badTokenSpec "Space is not allowed in the spec" | any isSpace a = badTokenSpec $ spaceyToken a | any isSpace b = badTokenSpec $ spaceyToken b | not (isTok tok a) = badTokenSpec $ notAToken a | not (isTok tok b) = badTokenSpec $ notAToken b | otherwise = return tok where tok = init $ tail t :: String badTokenSpec msg = fail $ "Bad token spec: '" ++ t ++ "' (" ++ msg ++ ")" spaceyToken x = x ++ " must not contain any space" notAToken x = x ++ " is not a token, according to your spec" chooseToks Nothing a b = if isTok defaultToks a && isTok defaultToks b then return defaultToks else return filenameToks darcs-2.14.5/src/Darcs/UI/Commands/Revert.hs0000644000000000000000000001415007346545000016575 0ustar0000000000000000-- Copyright (C) 2002-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE OverloadedStrings #-} module Darcs.UI.Commands.Revert ( revert ) where import Prelude () import Darcs.Prelude import Control.Exception ( catch, IOException ) import Data.List ( sort ) import Darcs.UI.Flags ( DarcsFlag, diffingOpts, verbosity, diffAlgorithm, isInteractive, withContext , dryRun, umask, useCache, fixSubPaths ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking(..) ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInHashedRepository, putInfo ) import Darcs.UI.Commands.Util ( announceFiles ) import Darcs.UI.Commands.Unrevert ( writeUnrevert ) import Darcs.UI.Completion ( modifiedFileArgs ) import Darcs.Util.Global ( debugMessage ) import Darcs.Util.Path ( toFilePath, AbsolutePath ) import Darcs.Repository ( withRepoLock , RepoJob(..) , addToPending , applyToWorking , readRecorded , unrecordedChanges ) import Darcs.Patch ( invert, effectOnFilePaths, commute ) import Darcs.Patch.Split ( reversePrimSplitter ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (:>)(..), nullFL, (+>+) ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..) ) import Darcs.UI.SelectChanges ( WhichChanges(Last) , selectionContextPrim , runSelection ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions(..) ) import Darcs.Patch.TouchesFiles ( chooseTouching ) revertDescription :: String revertDescription = "Discard unrecorded changes." revertHelp :: String revertHelp = "The `darcs revert` command discards unrecorded changes the working\n" ++ "tree. As with `darcs record`, you will be asked which hunks (changes)\n" ++ "to revert. The `--all` switch can be used to avoid such prompting. If\n" ++ "files or directories are specified, other parts of the working tree\n" ++ "are not reverted.\n" ++ "\n" ++ "In you accidentally reverted something you wanted to keep (for\n" ++ "example, typing `darcs rev -a` instead of `darcs rec -a`), you can\n" ++ "immediately run `darcs unrevert` to restore it. This is only\n" ++ "guaranteed to work if the repository has not changed since `darcs\n" ++ "revert` ran.\n" patchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions patchSelOpts flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = [] , S.interactive = isInteractive True flags , S.selectDeps = O.PromptDeps -- option not supported, use default , S.summary = O.NoSummary -- option not supported, use default , S.withContext = withContext ? flags } revert :: DarcsCommand [DarcsFlag] revert = DarcsCommand { commandProgramName = "darcs" , commandName = "revert" , commandHelp = revertHelp , commandDescription = revertDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[FILE or DIRECTORY]..."] , commandCommand = revertCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = modifiedFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc revertAdvancedOpts , commandBasicOptions = odesc revertBasicOpts , commandDefaults = defaultFlags revertOpts , commandCheckOptions = ocheck revertOpts , commandParseOptions = onormalise revertOpts } where revertBasicOpts = O.interactive -- True ^ O.repoDir ^ O.withContext ^ O.diffAlgorithm revertAdvancedOpts = O.useIndex ^ O.umask revertOpts = revertBasicOpts `withStdOpts` revertAdvancedOpts revertCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () revertCmd fps opts args = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do files <- if null args then return Nothing else Just . sort <$> fixSubPaths fps args announceFiles (verbosity ? opts) files "Reverting changes in" changes <- unrecordedChanges (diffingOpts opts {- always ScanKnown here -}) O.NoLookForMoves O.NoLookForReplaces repository files let pre_changed_files = effectOnFilePaths (invert changes) . map toFilePath <$> files recorded <- readRecorded repository Sealed touching_changes <- return (chooseTouching pre_changed_files changes) case touching_changes of NilFL -> putInfo opts "There are no changes to revert!" _ -> do let context = selectionContextPrim Last "revert" (patchSelOpts opts) (Just (reversePrimSplitter (diffAlgorithm ? opts))) pre_changed_files (Just recorded) (norevert:>p) <- runSelection changes context if nullFL p then putInfo opts $ "If you don't want to revert after all, that's fine with me!" else do addToPending repository YesUpdateWorking $ invert p debugMessage "About to write the unrevert file." case commute (norevert:>p) of Just (p':>_) -> writeUnrevert repository p' recorded NilFL Nothing -> writeUnrevert repository (norevert+>+p) recorded NilFL debugMessage "About to apply to the working directory." _ <- applyToWorking repository (verbosity ? opts) (invert p) `catch` \(e :: IOException) -> fail ("Unable to apply inverse patch!" ++ show e) return () putInfo opts "Finished reverting." darcs-2.14.5/src/Darcs/UI/Commands/Rollback.hs0000644000000000000000000001745507346545000017072 0ustar0000000000000000-- Copyright (C) 2002-2004,2007 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Rollback ( rollback ) where import Prelude () import Darcs.Prelude import Control.Exception ( catch, IOException ) import Control.Monad ( when ) import Data.List ( sort ) import Darcs.Util.Tree( Tree ) import System.Exit ( exitSuccess ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Match ( firstMatch ) import Darcs.Patch.PatchInfoAnd ( n2pia ) import Darcs.Patch ( IsRepoType, RepoPatch, invert, effect, fromPrims, sortCoalesceFL, canonize, PrimOf ) import Darcs.Patch.Named.Wrapped ( anonymous ) import Darcs.Patch.Set ( PatchSet(..), patchSet2FL ) import Darcs.Patch.Split ( reversePrimSplitter ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (:>)(..), RL(..), concatFL, nullFL, mapFL_FL ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..) ) import Darcs.Repository.Flags ( AllowConflicts (..), UseIndex(..), Reorder(..), ScanKnown(..), UpdateWorking(..), DryRun(NoDryRun)) import Darcs.Repository ( Repository, withRepoLock, RepoJob(..), applyToWorking, readRepo, finalizeRepositoryChanges, tentativelyAddToPending, considerMergeToWorking ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, setEnvDarcsPatches, amInHashedRepository, putInfo ) import Darcs.UI.Commands.Unrecord ( getLastPatches ) import Darcs.UI.Commands.Util ( announceFiles ) import Darcs.UI.Completion ( knownFileArgs ) import Darcs.UI.Flags ( DarcsFlag, verbosity, umask, useCache, compress, externalMerge, wantGuiPause, diffAlgorithm, fixSubPaths, isInteractive ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise , defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.SelectChanges ( WhichChanges(..), selectionContext, selectionContextPrim, runSelection ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions(..) ) import Darcs.Util.Path ( toFilePath, AbsolutePath ) import Darcs.Util.Printer ( text ) import Darcs.Util.Progress ( debugMessage ) rollbackDescription :: String rollbackDescription = "Apply the inverse of recorded changes to the working tree." rollbackHelp :: String rollbackHelp = unlines [ "Rollback is used to undo the effects of some changes from patches" , "in the repository. The selected changes are undone in your working" , "tree, but the repository is left unchanged. First you are offered a" , "choice of which patches to undo, then which changes within the" , "patches to undo." , "" , "Before doing `rollback`, you may want to temporarily undo the changes" , "of your working tree (if there are) and save them for later use." , "To do so, you can run `revert`, then run `rollback`, record a patch," , "and run `unrevert` to restore the saved changes into your working tree." ] patchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions patchSelOpts flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = parseFlags O.matchSeveralOrLast flags , S.interactive = isInteractive True flags , S.selectDeps = O.PromptDeps , S.summary = O.NoSummary , S.withContext = O.NoContext } rollback :: DarcsCommand [DarcsFlag] rollback = DarcsCommand { commandProgramName = "darcs" , commandName = "rollback" , commandHelp = rollbackHelp , commandDescription = rollbackDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[FILE or DIRECTORY]..."] , commandCommand = rollbackCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = knownFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc rollbackAdvancedOpts , commandBasicOptions = odesc rollbackBasicOpts , commandDefaults = defaultFlags rollbackOpts , commandCheckOptions = ocheck rollbackOpts , commandParseOptions = onormalise rollbackOpts } where rollbackBasicOpts = O.matchSeveralOrLast ^ O.interactive -- True ^ O.repoDir ^ O.diffAlgorithm rollbackAdvancedOpts = O.umask rollbackOpts = rollbackBasicOpts `withStdOpts` rollbackAdvancedOpts exitIfNothingSelected :: FL p wX wY -> String -> IO () exitIfNothingSelected ps what = when (nullFL ps) $ putStrLn ("No " ++ what ++ " selected!") >> exitSuccess rollbackCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () rollbackCmd fps opts args = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do files <- if null args then return Nothing else Just . sort <$> fixSubPaths fps args when (files == Just []) $ fail "No valid arguments were given." announceFiles (verbosity ? opts) files "Rolling back changes in" allpatches <- readRepo repository let matchFlags = parseFlags O.matchSeveralOrLast opts (_ :> patches) <- return $ if firstMatch matchFlags then getLastPatches matchFlags allpatches else PatchSet NilRL NilRL :> patchSet2FL allpatches let filesFps = map toFilePath <$> files patchCtx = selectionContext LastReversed "rollback" (patchSelOpts opts) Nothing filesFps (_ :> ps) <- runSelection patches patchCtx exitIfNothingSelected ps "patches" setEnvDarcsPatches ps let hunkContext = selectionContextPrim Last "rollback" (patchSelOpts opts) (Just (reversePrimSplitter (diffAlgorithm ? opts))) filesFps Nothing hunks = concatFL . mapFL_FL (canonize $ diffAlgorithm ? opts) . sortCoalesceFL . effect $ ps whatToUndo <- runSelection hunks hunkContext undoItNow opts repository whatToUndo undoItNow :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> Repository rt p wR wU wT -> (q :> FL (PrimOf p)) wA wT -> IO () undoItNow opts repo (_ :> prims) = do exitIfNothingSelected prims "changes" rbp <- n2pia `fmap` anonymous (fromPrims $ invert prims) Sealed pw <- considerMergeToWorking repo "rollback" YesAllowConflictsAndMark YesUpdateWorking (externalMerge ? opts) (wantGuiPause opts) (compress ? opts) (verbosity ? opts) NoReorder (UseIndex, ScanKnown, diffAlgorithm ? opts) NilFL (rbp :>: NilFL) tentativelyAddToPending repo YesUpdateWorking pw finalizeRepositoryChanges repo YesUpdateWorking (compress ? opts) _ <- applyToWorking repo (verbosity ? opts) pw `catch` \(e :: IOException) -> fail $ "error applying rolled back patch to working directory\n" ++ show e debugMessage "Finished applying unrecorded rollback patch" putInfo opts $ text "Changes rolled back in working directory" darcs-2.14.5/src/Darcs/UI/Commands/Send.hs0000644000000000000000000006522507346545000016230 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE CPP, TypeOperators, OverloadedStrings #-} module Darcs.UI.Commands.Send ( send ) where import Prelude () import Darcs.Prelude import System.Exit ( exitSuccess #ifndef HAVE_MAPI , ExitCode ( ExitFailure ) , exitWith #endif ) import System.IO.Error ( ioeGetErrorString ) import System.IO ( hClose ) import Control.Exception ( catch, IOException ) import Control.Monad ( when, unless, forM_ ) import Darcs.Util.Tree ( Tree ) import Data.List ( intercalate, isPrefixOf ) import Data.List ( stripPrefix ) import Data.Maybe ( isNothing, fromMaybe ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts , putInfo , putVerbose , setEnvDarcsPatches , defaultRepo , amInHashedRepository ) import Darcs.UI.Commands.Util ( printDryRunMessageAndExit, checkUnrelatedRepos ) import Darcs.UI.Flags ( DarcsFlag , willRemoveLogFile, changesReverse, dryRun, useCache, remoteRepos, setDefault , fixUrl , getCc , getAuthor , getSubject , getInReplyTo , getSendmailCmd , getOutput , charset , verbosity , isInteractive , author , hasLogfile , selectDeps , minimize , editDescription ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise , defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, hopefully, patchDesc ) import Darcs.Repository ( Repository , repoLocation , PatchSet , identifyRepositoryFor , withRepository , RepoJob(..) , readRepo , readRecorded , prefsUrl ) import Darcs.Patch.Set ( Origin ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch ( IsRepoType, RepoPatch, description, applyToTree, invert ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..) ) import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (:>)(..), (:\/:)(..), mapFL, mapFL_FL, lengthFL, nullFL ) import Darcs.Patch.Bundle ( minContext, makeBundleN, scanContextFile, patchFilename ) import Darcs.Repository.Prefs ( addRepoSource, getPreflist ) import Darcs.Repository.Flags ( DryRun(..) ) import Darcs.Util.External ( fetchFilePS, Cachable(..) ) import Darcs.UI.External ( signString , sendEmailDoc , generateEmail , editFile , catchall , getSystemEncoding , isUTF8Locale #ifndef HAVE_MAPI , haveSendmail #endif ) import Darcs.Util.ByteString ( mmapFilePS, isAscii ) import qualified Data.ByteString.Char8 as BC (unpack) import Darcs.Util.Lock ( withOpenTemp , writeDocBinFile , readDocBinFile , removeFileMayNotExist ) import Darcs.UI.SelectChanges ( WhichChanges(..) , selectionContext , runSelection ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions(..) ) import Darcs.Patch.Depends ( findCommonWithThem ) import Darcs.Util.Prompt ( askUser, promptYorn ) import Data.Text.Encoding ( decodeUtf8' ) import Darcs.Util.Progress ( debugMessage ) import Darcs.UI.Email ( makeEmail ) import Darcs.UI.Completion ( prefArgs ) import Darcs.Util.Printer ( Doc, vsep, text, ($$), (<+>), putDoc, putDocLn , renderPS, vcat ) import Darcs.Util.English ( englishNum, Noun(..) ) import Darcs.Util.Text ( sentence, quote ) import Darcs.Util.Path ( FilePathLike, toFilePath, AbsolutePath, AbsolutePathOrStd, getCurrentDirectory, useAbsoluteOrStd, makeAbsoluteOrStd ) import Darcs.Util.Download.HTTP ( postUrl ) import Darcs.Util.Workaround ( renameFile ) import Darcs.Util.Global ( darcsSendMessage, darcsSendMessageFinal ) import Darcs.Util.SignalHandler ( catchInterrupt ) patchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions patchSelOpts flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = parseFlags O.matchSeveral flags , S.interactive = isInteractive True flags , S.selectDeps = selectDeps ? flags , S.summary = O.summary ? flags , S.withContext = O.NoContext } send :: DarcsCommand [DarcsFlag] send = DarcsCommand { commandProgramName = "darcs" , commandName = "send" , commandHelp = cmdHelp , commandDescription = cmdDescription , commandExtraArgs = 1 , commandExtraArgHelp = ["[REPOSITORY]"] , commandCommand = sendCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = prefArgs "repos" , commandArgdefaults = defaultRepo , commandAdvancedOptions = odesc sendAdvancedOpts , commandBasicOptions = odesc sendBasicOpts , commandDefaults = defaultFlags sendOpts , commandCheckOptions = ocheck sendOpts , commandParseOptions = onormalise sendOpts } where sendBasicOpts = O.matchSeveral ^ O.selectDeps ^ O.interactive -- True ^ O.headerFields ^ O.author ^ O.charset ^ O.sendmail ^ O.output ^ O.sign ^ O.dryRunXml ^ O.summary ^ O.editDescription ^ O.setDefault ^ O.repoDir ^ O.minimize ^ O.allowUnrelatedRepos sendAdvancedOpts = O.logfile ^ O.remoteRepos ^ O.sendToContext ^ O.changesReverse ^ O.network sendOpts = sendBasicOpts `withStdOpts` sendAdvancedOpts sendCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () sendCmd fps opts [""] = sendCmd fps opts [] sendCmd (_,o) opts [unfixedrepodir] = withRepository (useCache ? opts) $ RepoJob $ \(repository :: Repository rt p wR wU wR) -> do context_ps <- the_context (O.sendToContext ? opts) case context_ps of Just them -> do wtds <- decideOnBehavior opts (Nothing :: Maybe (Repository rt p wR wU wR)) sendToThem repository opts wtds "CONTEXT" them Nothing -> do repodir <- fixUrl o unfixedrepodir -- Test to make sure we aren't trying to push to the current repo here <- getCurrentDirectory when (repodir == toFilePath here) $ fail cannotSendToSelf old_default <- getPreflist "defaultrepo" when (old_default == [repodir]) $ putInfo opts (creatingPatch repodir) repo <- identifyRepositoryFor repository (useCache ? opts) repodir them <- readRepo repo addRepoSource repodir (dryRun ? opts) (remoteRepos ? opts) (setDefault False opts) wtds <- decideOnBehavior opts (Just repo) sendToThem repository opts wtds repodir them where the_context Nothing = return Nothing the_context (Just foo) = Just `fmap` scanContextFile (toFilePath foo) sendCmd _ _ _ = impossible sendToThem :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> [DarcsFlag] -> [WhatToDo] -> String -> PatchSet rt p Origin wX -> IO () sendToThem repo opts wtds their_name them = do #ifndef HAVE_MAPI when (fst (O.sendmail ? opts) && dryRun ? opts == O.NoDryRun) $ do -- If --mail is used, check if the user has sendmail or -- provided a --sendmail-cmd sendmail <- haveSendmail sm_cmd <- getSendmailCmd opts when (not sendmail && sm_cmd == "") $ do putInfo opts noWorkingSendmail exitWith $ ExitFailure 1 #endif us <- readRepo repo common :> us' <- return $ findCommonWithThem us them checkUnrelatedRepos (O.allowUnrelatedRepos ? opts) us them case us' of NilFL -> do putInfo opts nothingSendable exitSuccess _ -> putVerbose opts $ selectionIs (mapFL description us') pristine <- readRecorded repo let direction = if changesReverse ? opts then FirstReversed else First context = selectionContext direction "send" (patchSelOpts opts) Nothing Nothing (to_be_sent :> _) <- runSelection us' context printDryRunMessageAndExit "send" (verbosity ? opts) (O.summary ? opts) (dryRun ? opts) O.NoXml (isInteractive True opts) to_be_sent when (nullFL to_be_sent) $ do putInfo opts selectionIsNull exitSuccess setEnvDarcsPatches to_be_sent let genFullBundle = prepareBundle opts common (Right (pristine, us':\/:to_be_sent)) bundle <- if not (minimize ? opts) then genFullBundle else do putInfo opts "Minimizing context, to send with full context hit ctrl-C..." ( case minContext common to_be_sent of Sealed (common' :> to_be_sent') -> prepareBundle opts common' (Left to_be_sent') ) `catchInterrupt` genFullBundle here <- getCurrentDirectory let make_fname (tb:>:_) = patchFilename $ patchDesc tb make_fname _ = impossible fname = make_fname to_be_sent outname = case getOutput opts fname of Just f -> Just f Nothing | fst (O.sendmail ? opts) -> Nothing | not $ null [ p | Post p <- wtds] -> Nothing | otherwise -> Just (makeAbsoluteOrStd here fname) case outname of Just fname' -> writeBundleToFile opts to_be_sent bundle fname' wtds their_name Nothing -> sendBundle opts to_be_sent bundle fname wtds their_name prepareBundle :: forall rt p wX wY wZ. (RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> PatchSet rt p Origin wZ -> Either (FL (PatchInfoAnd rt p) wX wY) (Tree IO, (FL (PatchInfoAnd rt p) :\/: FL (PatchInfoAnd rt p)) wX wY) -> IO Doc prepareBundle opts common e = do unsig_bundle <- case e of (Right (pristine, us' :\/: to_be_sent)) -> do pristine' <- applyToTree (invert $ mapFL_FL hopefully us') pristine makeBundleN (Just pristine') (unsafeCoerceP common) (mapFL_FL hopefully to_be_sent) Left to_be_sent -> makeBundleN Nothing (unsafeCoerceP common) (mapFL_FL hopefully to_be_sent) signString (parseFlags O.sign opts) unsig_bundle sendBundle :: forall rt p wX wY . (RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> FL (PatchInfoAnd rt p) wX wY -> Doc -> String -> [WhatToDo] -> String -> IO () sendBundle opts to_be_sent bundle fname wtds their_name= let auto_subject :: forall pp wA wB . FL (PatchInfoAnd rt pp) wA wB -> String auto_subject (p:>:NilFL) = "darcs patch: " ++ trim (patchDesc p) 57 auto_subject (p:>:ps) = "darcs patch: " ++ trim (patchDesc p) 43 ++ " (and " ++ show (lengthFL ps) ++ " more)" auto_subject _ = error "Tried to get a name from empty patch list." trim st n = if length st <= n then st else take (n-3) st ++ "..." in do thetargets <- getTargets wtds from <- getAuthor (author ? opts) False let thesubject = fromMaybe (auto_subject to_be_sent) $ getSubject opts (mailcontents, mailfile, mailcharset) <- getDescription opts their_name to_be_sent let warnMailBody = case mailfile of Just mf -> putDocLn $ emailBackedUp mf Nothing -> return () warnCharset msg = do confirmed <- promptYorn $ promptCharSetWarning msg unless confirmed $ do putDocLn charsetAborted warnMailBody exitSuccess thecharset <- case charset ? opts of -- Always trust provided charset providedCset@(Just _) -> return providedCset Nothing -> case mailcharset of Nothing -> do warnCharset charsetCouldNotGuess return mailcharset Just "utf-8" -> do -- Check the locale encoding for consistency encoding <- getSystemEncoding debugMessage $ currentEncodingIs encoding unless (isUTF8Locale encoding) $ warnCharset charsetUtf8MailDiffLocale return mailcharset -- Trust other cases (us-ascii) Just _ -> return mailcharset let body = makeEmail their_name (maybe [] (\x -> [("In-Reply-To", x), ("References", x)]) . getInReplyTo $ opts) (Just mailcontents) thecharset bundle (Just fname) contentAndBundle = Just (mailcontents, bundle) sendmail = do sm_cmd <- getSendmailCmd opts let to = generateEmailToString thetargets sendEmailDoc from to thesubject (getCc opts) sm_cmd contentAndBundle body >> putInfo opts (success to (getCc opts)) `catch` \e -> do warnMailBody fail $ ioeGetErrorString e when (null [ p | Post p <- thetargets]) sendmail nbody <- withOpenTemp $ \ (fh,fn) -> do let to = generateEmailToString thetargets generateEmail fh from to thesubject (getCc opts) body hClose fh mmapFilePS fn forM_ [ p | Post p <- thetargets] (\url -> do putInfo opts $ postingPatch url postUrl url (BC.unpack nbody) "message/rfc822") `catch` (\(_ :: IOException) -> sendmail) cleanup opts mailfile generateEmailToString :: [WhatToDo] -> String generateEmailToString = intercalate " , " . filter (/= "") . map extractEmail where extractEmail (SendMail t) = t extractEmail _ = "" cleanup :: (FilePathLike t) => [DarcsFlag] -> Maybe t -> IO () cleanup opts (Just mailfile) = when (isNothing (hasLogfile opts) || willRemoveLogFile opts) $ removeFileMayNotExist mailfile cleanup _ Nothing = return () writeBundleToFile :: forall rt p wX wY . (RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> FL (PatchInfoAnd rt p) wX wY -> Doc -> AbsolutePathOrStd -> [WhatToDo] -> String -> IO () writeBundleToFile opts to_be_sent bundle fname wtds their_name = do (d,f,_) <- getDescription opts their_name to_be_sent let putabs a = do writeDocBinFile a (d $$ bundle) putDocLn (wroteBundle a) putstd = putDoc (d $$ bundle) useAbsoluteOrStd putabs putstd fname let to = generateEmailToString wtds unless (null to) $ putInfo opts $ savedButNotSent to cleanup opts f data WhatToDo = Post String -- ^ POST the patch via HTTP | SendMail String -- ^ send patch via email decideOnBehavior :: [DarcsFlag] -> Maybe (Repository rt p wR wU wT) -> IO [WhatToDo] decideOnBehavior opts remote_repo = case the_targets of [] -> do wtds <- case remote_repo of Nothing -> return [] Just r -> check_post r unless (null wtds) $ announce_recipients wtds return wtds ts -> do announce_recipients ts return ts where the_targets = collectTargets opts check_post the_remote_repo = do p <- ((readPost . BC.unpack) `fmap` fetchFilePS (prefsUrl (repoLocation the_remote_repo) ++ "/post") (MaxAge 600)) `catchall` return [] emails <- who_to_email the_remote_repo return (p++emails) readPost = map parseLine . lines where parseLine t = maybe (Post t) SendMail $ stripPrefix "mailto:" t who_to_email repo = do email <- (BC.unpack `fmap` fetchFilePS (prefsUrl (repoLocation repo) ++ "/email") (MaxAge 600)) `catchall` return "" if '@' `elem` email then return . map SendMail $ lines email else return [] announce_recipients emails = let pn (SendMail s) = s pn (Post p) = p msg = willSendTo (dryRun ? opts) (map pn emails) in case dryRun ? opts of O.YesDryRun -> putInfo opts msg O.NoDryRun -> when (null the_targets && isNothing (getOutput opts "")) $ putInfo opts msg getTargets :: [WhatToDo] -> IO [WhatToDo] getTargets [] = fmap ((:[]) . SendMail) $ askUser promptTarget getTargets wtds = return wtds collectTargets :: [DarcsFlag] -> [WhatToDo] collectTargets flags = [ f t | t <- O._to (O.headerFields ? flags) ] where f url | "http:" `isPrefixOf` url = Post url f em = SendMail em getDescription :: (RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> String -> FL (PatchInfoAnd rt p) wX wY -> IO (Doc, Maybe String, Maybe String) getDescription opts their_name patches = case get_filename of Just file -> do when (editDescription ? opts) $ do when (isNothing $ hasLogfile opts) $ writeDocBinFile file patchdesc debugMessage $ aboutToEdit file (_, changed) <- editFile file unless changed $ do confirmed <- promptYorn promptNoDescriptionChange unless confirmed $ do putDocLn aborted exitSuccess return () updatedFile <- updateFilename file doc <- readDocBinFile updatedFile return (doc, Just updatedFile, tryGetCharset doc) Nothing -> return (patchdesc, Nothing, tryGetCharset patchdesc) where patchdesc = text (show len) <+> text (englishNum len (Noun "patch") "") <+> text "for repository" <+> text their_name <> text ":" $$ text "" $$ vsep (mapFL description patches) where len = lengthFL patches updateFilename file = maybe (renameFile file darcsSendMessageFinal >> return darcsSendMessageFinal) (return . toFilePath) $ hasLogfile opts get_filename = case hasLogfile opts of Just f -> Just $ toFilePath f Nothing -> if editDescription ? opts then Just darcsSendMessage else Nothing tryGetCharset content = let body = renderPS content in if isAscii body then Just "us-ascii" else either (const Nothing) (const $ Just "utf-8") (decodeUtf8' body) cmdDescription :: String cmdDescription = "Prepare a bundle of patches to be applied to some target repository." cmdHelp :: String cmdHelp = unlines [ "Send is used to prepare a bundle of patches that can be applied to a target" , "repository. Send accepts the URL of the repository as an argument. When" , "called without an argument, send will use the most recent repository that" , "was either pushed to, pulled from or sent to. By default, the patch bundle" , "is saved to a file, although you may directly send it by mail." , "" , "The `--output`, `--output-auto-name`, and `--to` flags determine" , "what darcs does with the patch bundle after creating it. If you provide an" , "`--output` argument, the patch bundle is saved to that file. If you" , "specify `--output-auto-name`, the patch bundle is saved to a file with an" , "automatically generated name. If you give one or more `--to` arguments," , "the bundle of patches is sent to those locations. The locations may either" , "be email addresses or urls that the patch should be submitted to via HTTP." , "" , "If you provide the `--mail` flag, darcs will look at the contents" , "of the `_darcs/prefs/email` file in the target repository (if it exists)," , "and send the patch by email to that address. In this case, you may use" , "the `--cc` option to specify additional recipients without overriding the" , "default repository email address." , "" , "If `_darcs/prefs/post` exists in the target repository, darcs will" , "upload to the URL contained in that file, which may either be a" , "`mailto:` URL, or an `http://` URL. In the latter case, the" , "patch is posted to that URL." , "" , "If there is no email address associated with the repository, darcs will" , "prompt you for an email address." , "" , "Use the `--subject` flag to set the subject of the e-mail to be sent." , "If you don't provide a subject on the command line, darcs will make one up" , "based on names of the patches in the patch bundle." , "" , "Use the `--in-reply-to` flag to set the In-Reply-To and References headers" , "of the e-mail to be sent. By default no additional headers are included so" , "e-mail will not be treated as reply by mail readers." , "" , "If you want to include a description or explanation along with the bundle" , "of patches, you need to specify the `--edit-description` flag, which" , "will cause darcs to open up an editor with which you can compose a message" , "to go along with your patches." , "" , "If you want to use a command different from the default one for sending" , "email, you need to specify a command line with the `--sendmail-command`" , "option. The command line can contain some format specifiers which are" , "replaced by the actual values. Accepted format specifiers are `%s` for" , "subject, `%t` for to, `%c` for cc, `%b` for the body of the mail, `%f` for" , "from, `%a` for the patch bundle and the same specifiers in uppercase for the" , "URL-encoded values." , "Additionally you can add `%<` to the end of the command line if the command" , "expects the complete email message on standard input. E.g. the command lines" , "for evolution and msmtp look like this:" , "" , " evolution \"mailto:%T?subject=%S&attach=%A&cc=%C&body=%B\"" , " msmtp -t %<" , "" , "Do not confuse the `--author` options with the return address" , "that `darcs send` will set for your patch bundle." , "" , "For example, if you have two email addresses A and B:" , "" , "* If you use `--author A` but your machine is configured to send mail from" , " address B by default, then the return address on your message will be B." , "* If you use `--from A` and your mail client supports setting the" , " From: address arbitrarily (some non-Unix-like mail clients, especially," , " may not support this), then the return address will be A; if it does" , " not support this, then the return address will be B." , "* If you supply neither `--from` nor `--author` then the return" , " address will be B." , "" , "In addition, unless you specify the sendmail command with" , "`--sendmail-command`, darcs sends email using the default email" , "command on your computer. This default command is determined by the" , "`configure` script. Thus, on some non-Unix-like OSes," , "`--from` is likely to not work at all." ] cannotSendToSelf :: String cannotSendToSelf = "Can't send to current repository! Did you mean send --context?" creatingPatch :: String -> Doc creatingPatch repodir = "Creating patch to" <+> text (quote repodir) <> "..." noWorkingSendmail :: Doc noWorkingSendmail = "No working sendmail instance on your machine!" nothingSendable :: Doc nothingSendable = "No recorded local changes to send!" selectionIs :: [Doc] -> Doc selectionIs descs = text "We have the following patches to send:" $$ vcat descs selectionIsNull :: Doc selectionIsNull = text "You don't want to send any patches, and that's fine with me!" emailBackedUp :: String -> Doc emailBackedUp mf = sentence $ "Email body left in" <+> text mf promptCharSetWarning :: String -> String promptCharSetWarning msg = "Warning: " ++ msg ++ " Send anyway?" charsetAborted :: Doc charsetAborted = "Aborted. You can specify charset with the --charset option." charsetCouldNotGuess :: String charsetCouldNotGuess = "darcs could not guess the charset of your mail." currentEncodingIs :: String -> String currentEncodingIs e = "Current locale encoding: " ++ e charsetUtf8MailDiffLocale :: String charsetUtf8MailDiffLocale = "your mail is valid UTF-8 but your locale differs." aborted :: Doc aborted = "Aborted." success :: String -> String -> Doc success to cc = sentence $ "Successfully sent patch bundle to:" <+> text to <+> copies cc where copies "" = "" copies x = "and cc'ed" <+> text x postingPatch :: String -> Doc postingPatch url = "Posting patch to" <+> text url wroteBundle :: FilePathLike a => a -> Doc wroteBundle a = sentence $ "Wrote patch to" <+> text (toFilePath a) savedButNotSent :: String -> Doc savedButNotSent to = text ("The usual recipent for this bundle is: " ++ to) $$ text "To send it automatically, make sure sendmail is working," <+> text "and add 'send mail' to _darcs/prefs/defaults or" <+> text " ~/.darcs/defaults" willSendTo :: DryRun -> [String] -> Doc willSendTo dr addresses = "Patch bundle" <+> will <+> " be sent to:" <+> text (unwords addresses) where will = case dr of { YesDryRun -> "would"; NoDryRun -> "will" } promptTarget :: String promptTarget = "What is the target email address? " aboutToEdit :: FilePath -> String aboutToEdit file = "About to edit file " ++ file promptNoDescriptionChange :: String promptNoDescriptionChange = "File content did not change. Continue anyway?" darcs-2.14.5/src/Darcs/UI/Commands/SetPref.hs0000644000000000000000000001205107346545000016674 0ustar0000000000000000-- Copyright (C) 2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.SetPref ( setpref ) where import Prelude () import Darcs.Prelude import System.Exit ( exitWith, ExitCode(..) ) import Control.Monad ( when ) import Data.Maybe ( fromMaybe ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInHashedRepository ) import Darcs.UI.Flags ( DarcsFlag, useCache, dryRun, umask) import Darcs.UI.Options ( odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository.Flags ( UpdateWorking (..) ) import Darcs.Repository ( addToPending, withRepoLock, RepoJob(..) ) import Darcs.Patch ( changepref ) import Darcs.Patch.Witnesses.Ordered ( FL(..) ) import Darcs.Repository.Prefs ( getPrefval, changePrefval ) import Darcs.Util.English ( orClauses ) import Darcs.Util.Path ( AbsolutePath ) -- | A list of all valid preferences for @_darcs/prefs/prefs@. validPrefData :: [(String, String)] -- ^ (name, one line description) validPrefData = [("test", "a shell command that runs regression tests"), ("predist", "a shell command to run before `darcs dist'"), ("boringfile", "the path to a version-controlled boring file"), ("binariesfile", "the path to a version-controlled binaries file")] validPrefs :: [String] validPrefs = map fst validPrefData setprefDescription :: String setprefDescription = "Set a preference (" ++ orClauses validPrefs ++ ")." setprefHelp :: String setprefHelp = "When working on project with multiple repositories and contributors,\n" ++ "it is sometimes desirable for a preference to be set consistently\n" ++ "project-wide. This is achieved by treating a preference set with\n" ++ "`darcs setpref` as an unrecorded change, which can then be recorded\n" ++ "and then treated like any other patch.\n" ++ "\n" ++ "Valid preferences are:\n" ++ "\n" ++ unlines ["* "++x++" -- "++y | (x,y) <- validPrefData] ++ "\n" ++ "For example, a project using GNU autotools, with a `make test` target\n" ++ "to perform regression tests, might enable Darcs' integrated regression\n" ++ "testing with the following command:\n" ++ "\n" ++ " darcs setpref test 'autoconf && ./configure && make && make test'\n" ++ "\n" ++ "Note that merging is not currently implemented for preferences: if two\n" ++ "patches attempt to set the same preference, the last patch applied to\n" ++ "the repository will always take precedence. This is considered a\n" ++ "low-priority bug, because preferences are seldom set.\n" setpref :: DarcsCommand [DarcsFlag] setpref = DarcsCommand { commandProgramName = "darcs" , commandName = "setpref" , commandHelp = setprefHelp , commandDescription = setprefDescription , commandExtraArgs = 2 , commandExtraArgHelp = ["", ""] , commandCommand = setprefCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = completeArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc setprefAdvancedOpts , commandBasicOptions = odesc setprefBasicOpts , commandDefaults = defaultFlags setprefOpts , commandCheckOptions = ocheck setprefOpts , commandParseOptions = onormalise setprefOpts } where setprefBasicOpts = O.repoDir setprefAdvancedOpts = O.umask setprefOpts = setprefBasicOpts `withStdOpts` setprefAdvancedOpts completeArgs _ _ [] = return validPrefs completeArgs _ _ _args = return [] setprefCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () setprefCmd _ opts [pref,val] = withRepoLock (dryRun ? opts) (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do when (' ' `elem` pref) $ do putStrLn $ "'"++pref++ "' is not a valid preference name: no spaces allowed!" exitWith $ ExitFailure 1 when (pref `notElem` validPrefs) $ do putStrLn $ "'"++pref++"' is not a valid preference name!" putStrLn $ "Try one of: " ++ unwords validPrefs exitWith $ ExitFailure 1 oval <- getPrefval pref let old = fromMaybe "" oval when ('\n' `elem` val) $ do putStrLn $ val ++ "is not a valid preference value: newlines forbidden!" exitWith $ ExitFailure 1 changePrefval pref old val putStrLn $ "Changing value of "++pref++" from '"++old++"' to '"++val++"'" addToPending repository YesUpdateWorking (changepref pref old val :>: NilFL) setprefCmd _ _ _ = impossible darcs-2.14.5/src/Darcs/UI/Commands/Show.hs0000644000000000000000000000561207346545000016251 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Show ( showCommand ) where import Prelude () import Darcs.Prelude import Darcs.UI.Commands ( DarcsCommand(..) , normalCommand , commandAlias, amInRepository ) import Darcs.UI.Commands.ShowAuthors ( showAuthors ) import Darcs.UI.Commands.ShowContents ( showContents ) import Darcs.UI.Commands.ShowDependencies ( showDeps ) import Darcs.UI.Commands.ShowFiles ( showFiles ) import Darcs.UI.Commands.ShowTags ( showTags ) import Darcs.UI.Commands.ShowRepo ( showRepo ) import Darcs.UI.Commands.ShowIndex ( showIndex, showPristineCmd ) import Darcs.UI.Commands.ShowPatchIndex ( showPatchIndex ) import Darcs.UI.Flags ( DarcsFlag ) showDescription :: String showDescription = "Show information about the given repository." showHelp :: String showHelp = "Use the `--help` option with the subcommands to obtain help for\n"++ "subcommands (for example, `darcs show files --help`).\n" showCommand :: DarcsCommand [DarcsFlag] showCommand = SuperCommand { commandProgramName = "darcs" , commandName = "show" , commandHelp = showHelp , commandDescription = showDescription , commandPrereq = amInRepository , commandSubCommands = [ normalCommand showContents , normalCommand showDeps , normalCommand showFiles , normalCommand showIndex , normalCommand showPristine , normalCommand showRepo , normalCommand showAuthors , normalCommand showTags , normalCommand showPatchIndex ] } -- unfortunately, aliases for sub-commands have to live in their parent command -- to avoid an import cycle showPristine :: DarcsCommand [DarcsFlag] showPristine = (commandAlias "pristine" (Just showCommand) showIndex) { commandCommand = showPristineCmd, commandDescription = "Dump contents of pristine cache.", commandHelp = "The `darcs show pristine` command lists all version-controlled files " ++ "and directories along with the hashes of their pristine copies. " ++ "For files, the fields correspond to file size, sha256 of the pristine " ++ "file content and the filename." } darcs-2.14.5/src/Darcs/UI/Commands/ShowAuthors.hs0000644000000000000000000002153107346545000017615 0ustar0000000000000000-- Copyright (C) 2004-2009 David Roundy, Eric Kow, Simon Michael, Tomas Caithaml -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.ShowAuthors ( showAuthors, Spelling, compiledAuthorSpellings, canonizeAuthor, rankAuthors ) where import Prelude () import Darcs.Prelude import Prelude hiding ( (^) ) import Control.Arrow ( (&&&), (***) ) import Data.Char ( toLower, isSpace ) import Data.Function ( on ) import Data.List ( isInfixOf, sortBy, groupBy, group, sort ) import Data.Maybe( isJust ) import Data.Ord ( comparing ) import System.IO.Error ( catchIOError ) import Text.ParserCombinators.Parsec hiding ( lower, count, Line ) import Text.ParserCombinators.Parsec.Error import Text.Regex ( Regex, mkRegexWithOpts, matchRegex ) import Darcs.UI.Flags ( DarcsFlag, useCache, verbose ) import Darcs.UI.Options ( oid, odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, putWarning, amInRepository ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.External ( viewDoc ) import Darcs.Patch.PatchInfoAnd ( info ) import Darcs.Patch.Info ( piAuthor ) import Darcs.Patch.Set ( patchSet2RL ) import Darcs.Repository ( readRepo, withRepository, RepoJob(..) ) import Darcs.Patch.Witnesses.Ordered ( mapRL ) import Darcs.Util.Lock ( readTextFile ) import Darcs.Util.Printer ( text ) import Darcs.Util.Path ( AbsolutePath ) data Spelling = Spelling String String [Regex] -- name, email, regexps type ParsedLine = Maybe Spelling -- Nothing for blank lines showAuthorsDescription :: String showAuthorsDescription = "List authors by patch count." showAuthorsHelp :: String showAuthorsHelp = "The `darcs show authors` command lists the authors of the current\n" ++ "repository, sorted by the number of patches contributed. With the\n" ++ "`--verbose` option, this command simply lists the author of each patch\n" ++ "(without aggregation or sorting).\n" ++ "\n" ++ "An author's name or email address may change over time. To tell Darcs\n" ++ "when multiple author strings refer to the same individual, create an\n" ++ "`.authorspellings` file in the root of the working tree. Each line in\n" ++ "this file begins with an author's canonical name and address, and may\n" ++ "be followed by a comma separated list of extended regular expressions.\n" ++ "Blank lines and lines beginning with two hyphens are ignored.\n" ++ "The format of `.authorspelling` can be described by this pattern:\n" ++ "\n" ++ " name
[, regexp ]*\n" ++ "\n" ++ "There are some pitfalls concerning special characters:\n" ++ "Whitespaces are stripped, if you need space in regexp use [ ]. \n" ++ "Because comma serves as a separator you have to escape it if you want\n" ++ "it in regexp. Note that `.authorspelling` use extended regular\n" ++ "expressions so +, ? and so on are metacharacters and you need to \n" ++ "escape them to be interpreted literally.\n" ++ "\n" ++ "Any patch with an author string that matches the canonical address or\n" ++ "any of the associated regexps is considered to be the work of that\n" ++ "author. All matching is case-insensitive and partial (it can match a\n" ++ "substring). Use ^,$ to match the whole string in regexps\n" ++ "\n" ++ "Currently this canonicalization step is done only in `darcs show\n" ++ "authors`. Other commands, such as `darcs log` use author strings\n" ++ "verbatim.\n" ++ "\n" ++ "An example `.authorspelling` file is:\n" ++ "\n" ++ " -- This is a comment.\n" ++ " Fred Nurk \n" ++ " John Snagge , John, snagge@, js@(si|mit).edu\n" ++ " Chuck Jones\\, Jr. , cj\\+user@example.com\n" showAuthors :: DarcsCommand [DarcsFlag] showAuthors = DarcsCommand { commandProgramName = "darcs" , commandName = "authors" , commandHelp = showAuthorsHelp , commandDescription = showAuthorsDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = authorsCmd , commandPrereq = amInRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc showAuthorsBasicOpts , commandDefaults = defaultFlags showAuthorsOpts , commandCheckOptions = ocheck showAuthorsOpts , commandParseOptions = onormalise showAuthorsOpts } where showAuthorsBasicOpts = O.repoDir showAuthorsOpts = showAuthorsBasicOpts `withStdOpts` oid authorsCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () authorsCmd _ flags _ = withRepository (useCache ? flags) $ RepoJob $ \repository -> do patches <- readRepo repository spellings <- compiledAuthorSpellings flags let authors = mapRL (piAuthor . info) $ patchSet2RL patches viewDoc $ text $ unlines $ if verbose flags then authors else rankAuthors spellings authors rankAuthors :: [Spelling] -> [String] -> [String] rankAuthors spellings authors = -- A list of the form ["# "]. -- Turn the final result into a list of strings. map (\ (rank, (count, name)) -> "#" ++ show rank ++ "\t" ++ show count ++ "\t" ++ name) . zip ([1..] :: [Int]) . -- Sort by descending patch count. reverse $ sortBy (comparing fst) . -- Combine duplicates from a list [(count, canonized name)] -- with duplicates canonized names (see next comment). map ((sum *** head) . unzip) . groupBy ((==) `on` snd) . sortBy (comparing snd) . -- Because it would take a long time to canonize "foo" into -- "foo " once per patch, the code below -- generates a list [(count, canonized name)]. map (length &&& (canonizeAuthor spellings . head)) . group $ sort authors canonizeAuthor :: [Spelling] -> String -> String canonizeAuthor spells author = getName canonicals where getName [] = author getName (Spelling name email _ : _) = name ++ " <" ++ email ++ ">" canonicals = filter (ismatch author) spells ismatch s (Spelling _ mail regexps) = s `correspondsTo` mail || any (s `contains_regex`) regexps contains_regex a r = isJust $ matchRegex r a correspondsTo a b = lower b `isInfixOf` lower a lower = map toLower compiledAuthorSpellings :: [DarcsFlag] -> IO [Spelling] compiledAuthorSpellings flags = do let as_file = ".authorspellings" content_lines <- readTextFile as_file `catchIOError` (const (return [])) let parse_results = map (parse sentence as_file) content_lines clean 1 parse_results where clean :: Int -> [Either ParseError ParsedLine] -> IO [Spelling] clean _ [] = return [] -- print parse error clean n (Left err : xs) = do let npos = setSourceLine (errorPos err) n putWarning flags . text . show $ setErrorPos npos err clean (n + 1) xs -- skip blank line clean n (Right Nothing : xs) = clean (n + 1) xs -- unwrap Spelling clean n (Right (Just a) : xs) = do as <- clean (n + 1) xs return (a : as) ---------- -- PARSERS sentence :: Parser ParsedLine sentence = spaces >> (comment <|> blank <|> addressline) where comment = string "--" >> return Nothing blank = eof >> return Nothing addressline :: Parser ParsedLine addressline = do name <- canonicalName "Canonical name" addr <- between (char '<') (char '>') (many1 (noneOf ">")) "Address" spaces rest <- option [] (char ',' >> regexp `sepBy` char ',') "List of regexps" return $ Just $ Spelling (strip name) addr (compile rest) where strip = dropWhile isSpace . reverse . dropWhile isSpace . reverse makeRegex s = mkRegexWithOpts s True False compile = map makeRegex . filter (not . null) . map strip parseComma = string "\\," >> return ',' regexp :: Parser String regexp = many1 p "Regular expression" where p = try parseComma <|> noneOf "," canonicalName :: Parser String canonicalName = many1 p where p = try parseComma <|> noneOf ",<" darcs-2.14.5/src/Darcs/UI/Commands/ShowContents.hs0000644000000000000000000001064407346545000017770 0ustar0000000000000000-- Copyright (C) 2007 Eric Kow -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.ShowContents ( showContents ) where import Prelude () import Darcs.Prelude import Prelude hiding ( (^) ) import Control.Monad ( filterM, forM_, forM ) import System.IO ( stdout ) import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, findRepository ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags ( DarcsFlag, useCache, fixSubPaths ) import Darcs.UI.Options ( (^), oid, odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Patch.Match ( haveNonrangeMatch ) import Darcs.Repository ( withRepository, RepoJob(..), readRecorded, repoPatchType ) import Darcs.Util.Lock ( withDelayedDir ) import Darcs.Repository.Match ( getNonrangeMatch ) import Darcs.Util.Tree.Plain( readPlainTree ) import qualified Darcs.Util.Tree.Monad as TM import Darcs.Util.Path( floatPath, sp2fn, toFilePath, AbsolutePath ) showContentsDescription :: String showContentsDescription = "Outputs a specific version of a file." showContentsHelp :: String showContentsHelp = "Show contents can be used to display an earlier version of some file(s).\n"++ "If you give show contents no version arguments, it displays the recorded\n"++ "version of the file(s).\n" showContents :: DarcsCommand [DarcsFlag] showContents = DarcsCommand { commandProgramName = "darcs" , commandName = "contents" , commandHelp = showContentsHelp , commandDescription = showContentsDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[FILE]..."] , commandCommand = showContentsCmd , commandPrereq = findRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc showContentsBasicOpts , commandDefaults = defaultFlags showContentsOpts , commandCheckOptions = ocheck showContentsOpts , commandParseOptions = onormalise showContentsOpts } where showContentsBasicOpts = O.matchUpToOne ^ O.repoDir showContentsOpts = O.matchUpToOne ^ O.repoDir `withStdOpts` oid showContentsCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () showContentsCmd _ _ [] = fail "show contents needs at least one argument." showContentsCmd fps opts args = do floatedPaths <- map (floatPath . toFilePath . sp2fn) `fmap` fixSubPaths fps args let matchFlags = parseFlags O.matchUpToOne opts withRepository (useCache ? opts) $ RepoJob $ \repository -> do let readContents = do okpaths <- filterM TM.fileExists floatedPaths forM okpaths $ \f -> (B.concat . BL.toChunks) `fmap` TM.readFile f -- Note: The two calls to execReadContents below are from -- different working directories. This matters despite our -- use of virtualTreeIO. execReadContents tree = fst `fmap` TM.virtualTreeIO readContents tree files <- if haveNonrangeMatch (repoPatchType repository) matchFlags then withDelayedDir "show.contents" $ \_ -> do -- this call populates our temporary directory, but note that -- it does so lazily: the tree gets (partly) expanded inside -- execReadContents, so it is important that we execute the -- latter from the same working directory. getNonrangeMatch repository matchFlags readPlainTree "." >>= execReadContents else do -- we can use the existing pristine tree because we don't modify -- anything in this case readRecorded repository >>= execReadContents forM_ files $ B.hPut stdout darcs-2.14.5/src/Darcs/UI/Commands/ShowDependencies.hs0000644000000000000000000001243207346545000020556 0ustar0000000000000000module Darcs.UI.Commands.ShowDependencies ( showDeps ) where import Control.Arrow ( (***) ) import Data.Maybe( fromMaybe ) import Data.GraphViz import Data.GraphViz.Algorithms ( transitiveReduction ) import Data.GraphViz.Attributes.Complete import Data.Graph.Inductive.Graph ( Graph(..), mkGraph, LNode, UEdge ) import Data.Graph.Inductive.PatriciaTree ( Gr ) import qualified Data.Text.Lazy as T import Darcs.Repository ( readRepo, withRepositoryLocation, RepoJob(..) ) import Darcs.UI.Flags ( DarcsFlag(..), getRepourl , useCache ) import Darcs.UI.Options ( oid, odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.Commands ( DarcsCommand(..), nodefaults, findRepository, withStdOpts ) import Darcs.UI.Commands.Unrecord ( matchingHead ) import Darcs.UI.Completion ( noArgs ) import Darcs.Util.Text ( formatText ) import Darcs.Util.Path ( AbsolutePath ) import Darcs.Patch.Info ( piName ) import Darcs.Patch.PatchInfoAnd ( hopefully ) import Darcs.Patch.Named ( Named (..), patch2patchinfo ) import Darcs.Patch.Named.Wrapped ( removeInternalFL ) import Darcs.Patch.Match ( firstMatch, matchFirstPatchset ) import Darcs.Patch.Choices ( unLabel, LabelledPatch, label, getLabelInt ) import Darcs.Patch.Depends ( SPatchAndDeps, getDeps, findCommonWithThem ) import Darcs.Patch.Witnesses.Sealed ( Sealed2(..), seal2, Sealed(..) ) import Darcs.Patch.Witnesses.Ordered ( (:>)(..), (:>)(..), foldlFL, mapFL_FL ) showDepsDescription :: String showDepsDescription = "Generate the graph of dependencies." showDepsHelp :: String showDepsHelp = formatText 80 [ unwords [ "The `darcs show dependencies` command is used to create" , "a graph of the dependencies between patches of the" , "repository (by default up to last tag)." ] , unwords [ "The resulting graph is described in Dot Language, a" , "general example of use could be:" ] , "darcs show dependencies | dot -Tpdf -o FILE.pdf" ] showDeps :: DarcsCommand [DarcsFlag] showDeps = DarcsCommand { commandProgramName = "darcs" , commandName = "dependencies" , commandHelp = showDepsHelp , commandDescription = showDepsDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = depsCmd , commandPrereq = findRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc showDepsBasicOpts , commandDefaults = defaultFlags showDepsOpts , commandCheckOptions = ocheck showDepsOpts , commandParseOptions = onormalise showDepsOpts } where showDepsBasicOpts = O.matchSeveralOrLast showDepsOpts = showDepsBasicOpts `withStdOpts` oid type DepsGraph = Gr String () depsCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () depsCmd _ opts _ = do let repodir = fromMaybe "." (getRepourl opts) withRepositoryLocation (useCache ? opts) repodir $ RepoJob $ \repo -> do Sealed2 rFl <- readRepo repo >>= pruneRepo let deps = getDeps (removeInternalFL . mapFL_FL hopefully $ rFl) rFl dGraph = transitiveReduction $ graphToDot nodeLabeledParams $ makeGraph deps putStrLn $ T.unpack $ printDotGraph dGraph where nodeLabeledParams :: GraphvizParams n String el () String nodeLabeledParams = defaultParams { globalAttributes = [GraphAttrs {attrs = [RankDir FromLeft]}] , fmtNode = \(_,l) -> [ toLabel l , ImageScale UniformScale ] } pruneRepo r = let matchFlags = O.matchSeveralOrLast ? opts in if firstMatch matchFlags then case getLastPatches matchFlags r of Sealed2 ps -> return $ seal2 ps else case matchingHead matchFlags r of _ :> patches -> return $ seal2 patches getLastPatches matchFlags ps = case matchFirstPatchset matchFlags ps of Sealed p1s -> case findCommonWithThem ps p1s of _ :> ps' -> seal2 ps' makeGraph :: [SPatchAndDeps p] -> DepsGraph makeGraph = uncurry mkGraph . (id *** concat) . unzip . map mkNodeWithEdges where mkNodeWithEdges :: SPatchAndDeps p -> (LNode String, [UEdge]) mkNodeWithEdges (Sealed2 father, Sealed2 childs) = (mkLNode father,mkUEdges) where mkNode :: LabelledPatch (Named p) wX wY -> Int mkNode = getLabelInt . label mkUEdge :: [UEdge] -> LabelledPatch (Named p) wX wY -> [UEdge] mkUEdge les child = (mkNode father, mkNode child,()) : les mkLabel :: LabelledPatch (Named p) wX wY -> String mkLabel = formatText 20 . (:[]) . piName . patch2patchinfo . unLabel mkLNode :: LabelledPatch (Named p) wX wY -> LNode String mkLNode p = (mkNode p, mkLabel p) mkUEdges :: [UEdge] mkUEdges = foldlFL mkUEdge [] childs darcs-2.14.5/src/Darcs/UI/Commands/ShowFiles.hs0000644000000000000000000001442507346545000017236 0ustar0000000000000000-- Copyright (C) 2005 Florian Weimer -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.ShowFiles ( showFiles ) where import Prelude () import Darcs.Prelude import Darcs.UI.Flags ( DarcsFlag, useCache ) import Darcs.UI.Options ( (^), oid, odesc, ocheck, onormalise , defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInRepository ) import Darcs.UI.Completion ( knownFileArgs ) import Darcs.Repository ( Repository, withRepository, RepoJob(..), repoPatchType ) import Darcs.Patch ( IsRepoType, RepoPatch ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Repository.State ( readRecorded, readRecordedAndPending ) import Darcs.Util.Tree( Tree, TreeItem(..), list, expand ) import Darcs.Util.Tree.Plain( readPlainTree ) import Darcs.Util.Path( anchorPath, AbsolutePath ) import System.FilePath ( splitDirectories ) import Data.List( isPrefixOf ) import Darcs.Patch.Match ( haveNonrangeExplicitMatch ) import Darcs.Repository.Match ( getNonrangeMatch ) import Darcs.Util.Lock ( withDelayedDir ) showFilesDescription :: String showFilesDescription = "Show version-controlled files in the working tree." showFilesHelp :: String showFilesHelp = "The `darcs show files` command lists those files and directories in\n" ++ "the working tree that are under version control. This command is\n" ++ "primarily for scripting purposes; end users will probably want `darcs\n" ++ "whatsnew --summary`.\n" ++ "\n" ++ "A file is \"pending\" if it has been added but not recorded. By\n" ++ "default, pending files (and directories) are listed; the `--no-pending`\n" ++ "option prevents this.\n" ++ "\n" ++ "By default `darcs show files` lists both files and directories, but the\n" ++ "`--no-files` and `--no-directories` flags modify this behaviour.\n" ++ "\n" ++ "By default entries are one-per-line (i.e. newline separated). This\n" ++ "can cause problems if the files themselves contain newlines or other\n" ++ "control characters. To get around this, the `--null` option uses the\n" ++ "null character instead. The script interpreting output from this\n" ++ "command needs to understand this idiom; `xargs -0` is such a command.\n" ++ "\n" ++ "For example, to list version-controlled files by size:\n" ++ "\n" ++ " darcs show files -0 | xargs -0 ls -ldS\n" showFiles :: DarcsCommand [DarcsFlag] showFiles = DarcsCommand { commandProgramName = "darcs" , commandName = "files" , commandHelp = showFilesHelp , commandDescription = showFilesDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[FILE or DIRECTORY]..."] , commandCommand = manifestCmd toListFiles , commandPrereq = amInRepository , commandCompleteArgs = knownFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc showFilesBasicOpts , commandDefaults = defaultFlags showFilesOpts , commandCheckOptions = ocheck showFilesOpts , commandParseOptions = onormalise showFilesOpts } where showFilesBasicOpts = O.files ^ O.directories ^ O.pending ^ O.nullFlag ^ O.matchUpToOne ^ O.repoDir showFilesOpts = showFilesBasicOpts `withStdOpts` oid toListFiles :: [DarcsFlag] -> Tree m -> [FilePath] toListFiles opts = filesDirs (parseFlags O.files opts) (parseFlags O.directories opts) filesDirs :: Bool -> Bool -> Tree m -> [FilePath] filesDirs False False _ = [] filesDirs False True t = "." : [ anchorPath "." p | (p, SubTree _) <- list t ] filesDirs True False t = [ anchorPath "." p | (p, File _) <- list t ] filesDirs True True t = "." : map (anchorPath "." . fst) (list t) manifestCmd :: ([DarcsFlag] -> Tree IO -> [FilePath]) -> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () manifestCmd to_list _ opts argList = mapM_ output =<< manifestHelper to_list opts argList where output_null name = do { putStr name ; putChar '\0' } output = if parseFlags O.nullFlag opts then output_null else putStrLn manifestHelper :: ([DarcsFlag] -> Tree IO -> [FilePath]) -> [DarcsFlag] -> [String] -> IO [FilePath] manifestHelper to_list opts argList = do list' <- to_list opts `fmap` withRepository (useCache ? opts) (RepoJob slurp) case argList of [] -> return list' prefixes -> return (onlysubdirs prefixes list') where matchFlags = parseFlags O.matchUpToOne opts slurp :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wR -> IO (Tree IO) slurp r = do let fUpto = haveNonrangeExplicitMatch (repoPatchType r) matchFlags fPending = parseFlags O.pending opts -- this covers all 4 possibilities case (fUpto,fPending) of (True, False) -> slurpUpto matchFlags r (True, True) -> error "can't mix match and pending flags" (False,False) -> expand =<< readRecorded r (False,True) -> expand =<< readRecordedAndPending r -- pending is default isParentDir a' b' = let a = splitDirectories a' b = splitDirectories b' in (a `isPrefixOf` b) || (("." : a) `isPrefixOf` b) onlysubdirs dirs = filter (\p -> any (`isParentDir` p) dirs) slurpUpto :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => [O.MatchFlag] -> Repository rt p wR wU wR -> IO (Tree IO) slurpUpto matchFlags r = withDelayedDir "show.files" $ \_ -> do getNonrangeMatch r matchFlags -- note: it is important that we expand the tree from inside the -- withDelayedDir action, else it has no effect. expand =<< readPlainTree "." darcs-2.14.5/src/Darcs/UI/Commands/ShowIndex.hs0000644000000000000000000001065607346545000017245 0ustar0000000000000000-- Copyright (C) 2009 Petr Rockai -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. module Darcs.UI.Commands.ShowIndex ( showIndex , showPristineCmd -- for alias ) where import Prelude () import Darcs.Prelude import Control.Monad ( (>=>) ) import Darcs.UI.Flags ( DarcsFlag, useCache ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInRepository ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Options ( (^), oid, odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository ( withRepository, RepoJob(..), readIndex ) import Darcs.Repository.State ( readRecorded ) import Darcs.Util.Hash( encodeBase16, Hash( NoHash ) ) import Darcs.Util.Tree( list, expand, itemHash, Tree, TreeItem( SubTree ) ) import Darcs.Util.Index( updateIndex, listFileIDs ) import Darcs.Util.Path( anchorPath, AbsolutePath, floatPath ) import System.Posix.Types ( FileID ) import qualified Data.ByteString.Char8 as BC import Data.Maybe ( fromJust ) import qualified Data.Map as M ( Map, lookup, fromList ) showIndex :: DarcsCommand [DarcsFlag] showIndex = DarcsCommand { commandProgramName = "darcs" , commandName = "index" , commandDescription = "Dump contents of working tree index." , commandHelp = "The `darcs show index` command lists all version-controlled files and " ++ "directories along with their hashes as stored in `_darcs/index`. " ++ "For files, the fields correspond to file size, sha256 of the current " ++ "file content and the filename." , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = showIndexCmd , commandPrereq = amInRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc showIndexBasicOpts , commandDefaults = defaultFlags showIndexOpts , commandCheckOptions = ocheck showIndexOpts , commandParseOptions = onormalise showIndexOpts } where showIndexBasicOpts = O.nullFlag ^ O.repoDir showIndexOpts = showIndexBasicOpts `withStdOpts` oid dump :: [DarcsFlag] -> Maybe (M.Map FilePath FileID) -> Tree IO -> IO () dump opts fileids tree = do let line | O.nullFlag ? opts = \t -> putStr t >> putChar '\0' | otherwise = putStrLn output (p, i) = do let hash = case itemHash i of NoHash -> "(no hash available)" h -> BC.unpack $ encodeBase16 h path = anchorPath "" p isdir = case i of SubTree _ -> "/" _ -> "" fileid = case fileids of Nothing -> "" Just fileids' -> " " ++ (show $ fromJust $ M.lookup path fileids') line $ hash ++ fileid ++ " " ++ path ++ isdir x <- expand tree mapM_ output $ (floatPath ".", SubTree x) : list x showIndexCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () showIndexCmd _ opts _ = withRepository (useCache ? opts) $ RepoJob $ \repo -> do index <- readIndex repo index_tree <- updateIndex index fileids <- (M.fromList . map (\((a,_),b) -> (anchorPath "" a,b))) <$> listFileIDs index dump opts (Just fileids) index_tree showPristineCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () showPristineCmd _ opts _ = withRepository (useCache ? opts) $ RepoJob $ readRecorded >=> dump opts Nothing darcs-2.14.5/src/Darcs/UI/Commands/ShowPatchIndex.hs0000644000000000000000000000446107346545000020222 0ustar0000000000000000module Darcs.UI.Commands.ShowPatchIndex ( showPatchIndex ) where import Prelude () import Darcs.Prelude import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInHashedRepository ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags ( DarcsFlag, useCache, verbose ) import Prelude hiding ( (^) ) import Darcs.UI.Options ( (^), oid, odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Util.Path ( AbsolutePath ) import Darcs.Repository ( withRepository, RepoJob(..), repoLocation ) import Darcs.Repository.PatchIndex ( dumpPatchIndex, piTest, doesPatchIndexExist, isPatchIndexInSync) showPatchIndex :: DarcsCommand [DarcsFlag] showPatchIndex = DarcsCommand { commandProgramName = "darcs" , commandName = "patch-index" , commandDescription = "Check integrity of patch index" , commandHelp = "When given the `--verbose` flag, the command dumps the complete content\n" ++ "of the patch index and checks its integrity." , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = showPatchIndexCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc showPatchIndexBasicOpts , commandDefaults = defaultFlags showPatchIndexOpts , commandCheckOptions = ocheck showPatchIndexOpts , commandParseOptions = onormalise showPatchIndexOpts } where showPatchIndexBasicOpts = O.nullFlag ^ O.repoDir showPatchIndexOpts = showPatchIndexBasicOpts `withStdOpts` oid showPatchIndexCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () showPatchIndexCmd _ opts _ | verbose opts = withRepository (useCache ? opts) $ RepoJob $ \repo -> let loc = repoLocation repo in dumpPatchIndex loc >> piTest loc | otherwise = withRepository (useCache ? opts) $ RepoJob $ \repo -> do ex <- doesPatchIndexExist (repoLocation repo) if ex then do sy <- isPatchIndexInSync repo if sy then putStrLn "Patch Index is in sync with repo." else putStrLn "Patch Index is outdated. Run darcs optimize enable-patch-index" else putStrLn "Patch Index is not yet created. Run darcs optimize enable-patch-index" darcs-2.14.5/src/Darcs/UI/Commands/ShowRepo.hs0000644000000000000000000001642007346545000017076 0ustar0000000000000000-- Copyright (C) 2007 Kevin Quick -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.ShowRepo ( showRepo ) where import Prelude () import Darcs.Prelude import Data.Char ( toLower, isSpace ) import Data.List ( intercalate ) import Control.Monad ( when, unless, liftM ) import Text.Html ( tag, stringToHtml ) import Darcs.Util.Path ( AbsolutePath ) import Darcs.UI.Flags ( DarcsFlag, useCache, hasXmlOutput, verbose, enumeratePatches ) import Darcs.UI.Options ( (^), oid, odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInRepository ) import Darcs.UI.Completion ( noArgs ) import Darcs.Repository ( Repository , repoFormat , repoLocation , repoPristineType , repoCache , withRepository , RepoJob(..) , readRepo ) import Darcs.Repository.Hashed( repoXor ) import Darcs.Repository.PatchIndex ( isPatchIndexDisabled, doesPatchIndexExist ) import Darcs.Repository.Prefs ( getPreflist, getMotd ) import Darcs.Patch ( IsRepoType, RepoPatch ) import Darcs.Patch.Set ( patchSet2RL ) import Darcs.Patch.Witnesses.Ordered ( lengthRL ) import qualified Data.ByteString.Char8 as BC (unpack) import Darcs.Patch.Apply( ApplyState ) import Darcs.Util.Tree ( Tree ) showRepoHelp :: String showRepoHelp = "The `darcs show repo` command displays statistics about the current\n" ++ "repository, allowing third-party scripts to access this information\n" ++ "without inspecting `_darcs` directly (and without breaking when the\n" ++ "`_darcs` format changes).\n" ++ "\n" ++ "The 'Weak Hash' identifies the set of patches of a repository independently\n" ++ "of ordering. It can be used to easily compare two repositories of a same\n" ++ "project. It is not cryptographically secure.\n" ++ "\n" ++ "By default, output includes statistics that require walking through the patches\n" ++ "recorded in the repository, namely the 'Weak Hash' and the count of patches.\n" ++ "If this data isn't needed, use `--no-enum-patches` to accelerate this command\n" ++ "from O(n) to O(1).\n" ++ "\n" ++ "By default, output is in a human-readable format. The `--xml-output`\n" ++ "option can be used to generate output for machine postprocessing.\n" showRepoDescription :: String showRepoDescription = "Show repository summary information" showRepo :: DarcsCommand [DarcsFlag] showRepo = DarcsCommand { commandProgramName = "darcs" , commandName = "repo" , commandHelp = showRepoHelp , commandDescription = showRepoDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = repoCmd , commandPrereq = amInRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc showRepoBasicOpts , commandDefaults = defaultFlags showRepoOpts , commandCheckOptions = ocheck showRepoOpts , commandParseOptions = onormalise showRepoOpts } where showRepoBasicOpts = O.repoDir ^ O.xmlOutput ^ O.enumPatches showRepoOpts = showRepoBasicOpts `withStdOpts` oid repoCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () repoCmd _ opts _ = let put_mode = if hasXmlOutput opts then showInfoXML else showInfoUsr in withRepository (useCache ? opts) $ RepoJob $ \repository -> actuallyShowRepo (putInfo put_mode) repository opts -- Some convenience functions to output a labelled text string or an -- XML tag + value (same API). If no value, output is suppressed -- entirely. Borrow some help from Text.Html to perform XML output. type ShowInfo = String -> String -> String showInfoXML :: ShowInfo showInfoXML t i = show $ tag (safeTag t) $ stringToHtml i safeTag :: String -> String safeTag [] = [] safeTag (' ':cs) = safeTag cs safeTag ('#':cs) = "num_" ++ safeTag cs safeTag (c:cs) = toLower c : safeTag cs -- labelled strings: labels are right-aligned at 15 characters; -- subsequent lines in multi-line output are indented accordingly. showInfoUsr :: ShowInfo showInfoUsr t i = replicate (15 - length t) ' ' ++ t ++ ": " ++ intercalate ('\n' : replicate 17 ' ') (lines i) ++ "\n" type PutInfo = String -> String -> IO () putInfo :: ShowInfo -> PutInfo putInfo m t i = unless (null i) (putStr $ m t i) -- Primary show-repo operation. Determines ordering of output for -- sub-displays. The `out' argument is one of the above operations to -- output a labelled text string or an XML tag and contained value. actuallyShowRepo :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => PutInfo -> Repository rt p wR wU wR -> [DarcsFlag] -> IO () actuallyShowRepo out r opts = do when (hasXmlOutput opts) (putStr "\n") when (verbose opts) (out "Show" $ show r) out "Format" $ showInOneLine $ repoFormat r let loc = repoLocation r out "Root" loc out "PristineType" $ show $ repoPristineType r out "Cache" $ showInOneLine $ repoCache r piExists <- doesPatchIndexExist loc piDisabled <- isPatchIndexDisabled loc out "PatchIndex" $ case (piExists, piDisabled) of (_, True) -> "disabled" (True, False) -> "enabled" (False, False) -> "enabled, but not yet created" showRepoPrefs out when (enumeratePatches opts) (do numPatches r >>= (out "Num Patches" . show) showXor out r) showRepoMOTD out r when (hasXmlOutput opts) (putStr "\n") showXor :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => PutInfo -> Repository rt p wR wU wR -> IO () showXor out repo = do theXor <- repoXor repo out "Weak Hash" (show theXor) -- Most of the actual elements being displayed are part of the Show -- class; that's fine for a Haskeller, but not for the common user, so -- the routines below work to provide more human-readable information -- regarding the repository elements. showInOneLine :: Show a => a -> String showInOneLine = intercalate ", " . lines . show showRepoPrefs :: PutInfo -> IO () showRepoPrefs out = do getPreflist "prefs" >>= mapM_ prefOut getPreflist "author" >>= out "Author" . unlines getPreflist "defaultrepo" >>= out "Default Remote" . unlines where prefOut = uncurry out . (\(p,v) -> (p++" Pref", dropWhile isSpace v)) . break isSpace showRepoMOTD :: RepoPatch p => PutInfo -> Repository rt p wR wU wR -> IO () showRepoMOTD out repo = getMotd (repoLocation repo) >>= out "MOTD" . BC.unpack -- Support routines to provide information used by the PutInfo operations above. numPatches :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wR -> IO Int numPatches r = (lengthRL . patchSet2RL) `liftM` readRepo r darcs-2.14.5/src/Darcs/UI/Commands/ShowTags.hs0000644000000000000000000000700007346545000017061 0ustar0000000000000000-- Copyright (C) 2007 Florian Weimer -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.ShowTags ( showTags ) where import Prelude () import Darcs.Prelude import Control.Monad ( unless, join ) import Data.Maybe ( fromMaybe ) import System.IO ( stderr, hPutStrLn ) import Darcs.Patch.Set ( PatchSet(..) ) import Darcs.Repository ( readRepo, withRepositoryLocation, RepoJob(..) ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, findRepository ) import Darcs.UI.Commands.Util ( repoTags ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags ( DarcsFlag, useCache, getRepourl ) import Darcs.UI.Options ( oid, odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Util.Text ( formatText ) import Darcs.Util.Path ( AbsolutePath ) showTagsDescription :: String showTagsDescription = "Show all tags in the repository." showTagsHelp :: String showTagsHelp = formatText 80 [ "The tags command writes a list of all tags in the repository to " ++ "standard output." , "Tab characters (ASCII character 9) in tag names are changed to spaces " ++ "for better interoperability with shell tools. A warning is printed " ++ "if this happens." ] showTags :: DarcsCommand [DarcsFlag] showTags = DarcsCommand { commandProgramName = "darcs" , commandName = "tags" , commandHelp = showTagsHelp , commandDescription = showTagsDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = tagsCmd , commandPrereq = findRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc showTagsBasicOpts , commandDefaults = defaultFlags showTagsOpts , commandCheckOptions = ocheck showTagsOpts , commandParseOptions = onormalise showTagsOpts } where showTagsBasicOpts = O.possiblyRemoteRepo showTagsOpts = showTagsBasicOpts `withStdOpts` oid tagsCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () tagsCmd _ opts _ = let repodir = fromMaybe "." (getRepourl opts) in withRepositoryLocation (useCache ? opts) repodir $ RepoJob $ \repo -> readRepo repo >>= printTags where printTags :: PatchSet rt p wW wZ -> IO () printTags = join . fmap (sequence_ . map process) . repoTags process :: String -> IO () process t = normalize t t False >>= putStrLn normalize :: String -> String -> Bool -> IO String normalize _ [] _ = return [] normalize t (x : xs) flag = if x == '\t' then do unless flag $ hPutStrLn stderr $ "warning: tag with TAB character: " ++ t rest <- normalize t xs True return $ ' ' : rest else do rest <- normalize t xs flag return $ x : rest darcs-2.14.5/src/Darcs/UI/Commands/Tag.hs0000644000000000000000000002102707346545000016042 0ustar0000000000000000-- Copyright (C) 2003-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Tag ( tag ) where import Prelude () import Darcs.Prelude import Control.Monad ( when ) import System.IO ( hPutStr, stderr ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.Info ( patchinfo ) import Darcs.Patch.Depends ( getUncovered ) import Darcs.Patch ( PrimPatch, PrimOf , IsRepoType, RepoPatch ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, n2pia, hopefully ) import Darcs.Patch.Named.Wrapped ( infopatch, adddeps, runInternalChecker, namedInternalChecker ) import Darcs.Patch.Set ( PatchSet(..), emptyPatchSet, appendPSFL, patchSet2FL ) import Darcs.Patch.Witnesses.Ordered ( FL(..), filterOutRLRL, (:>)(..) ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), mapSeal ) import Darcs.Repository ( withRepoLock, Repository, RepoJob(..), readRepo , tentativelyAddPatch, finalizeRepositoryChanges, ) import Darcs.Repository.Flags ( UpdateWorking(..), DryRun(NoDryRun) ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInHashedRepository ) import Darcs.UI.Commands.Util ( repoTags ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags ( DarcsFlag, getDate, compress, verbosity, useCache, umask, getAuthor, author ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.PatchHeader ( getLog ) import Darcs.UI.SelectChanges ( WhichChanges(..) , selectionContext , runSelection , PatchSelectionContext(allowSkipAll) ) import qualified Darcs.UI.SelectChanges as S import Darcs.Util.Path ( AbsolutePath ) import Darcs.Util.Tree( Tree ) tagDescription :: String tagDescription = "Name the current repository state for future reference." tagHelp :: String tagHelp = "The `darcs tag` command names the current repository state, so that it\n" ++ "can easily be referred to later. Every *important* state should be\n" ++ "tagged; in particular it is good practice to tag each stable release\n" ++ "with a number or codename. Advice on release numbering can be found\n" ++ "at .\n" ++ "\n" ++ "To reproduce the state of a repository `R` as at tag `t`, use the\n" ++ "command `darcs clone --tag t R`. The command `darcs show tags` lists\n" ++ "all tags in the current repository.\n" ++ "\n" ++ "Tagging also provides significant performance benefits: when Darcs\n" ++ "reaches a shared tag that depends on all antecedent patches, it can\n" ++ "simply stop processing.\n" ++ "\n" ++ "Like normal patches, a tag has a name, an author, a timestamp and an\n" ++ "optional long description, but it does not change the working tree.\n" ++ "A tag can have any name, but it is generally best to pick a naming\n" ++ "scheme and stick to it.\n" ++ "\n" ++ "By default a tag names the entire repository state at the time the tag\n" ++ "is created. If the --ask-deps option is used, the patches to include\n" ++ "as part of the tag can be explicitly selected.\n" ++ "\n" ++ "The `darcs tag` command accepts the `--pipe` option, which behaves as\n" ++ "described in `darcs record`.\n" tag :: DarcsCommand [DarcsFlag] tag = DarcsCommand { commandProgramName = "darcs" , commandName = "tag" , commandHelp = tagHelp , commandDescription = tagDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[TAGNAME]"] , commandCommand = tagCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc tagAdvancedOpts , commandBasicOptions = odesc tagBasicOpts , commandDefaults = defaultFlags tagOpts , commandCheckOptions = ocheck tagOpts , commandParseOptions = onormalise tagOpts } where tagBasicOpts = O.patchname ^ O.author ^ O.pipe ^ O.askLongComment ^ O.askDeps ^ O.repoDir tagAdvancedOpts = O.compress ^ O.umask tagOpts = tagBasicOpts `withStdOpts` tagAdvancedOpts filterNonInternal :: IsRepoType rt => PatchSet rt p wX wY -> PatchSet rt p wX wY filterNonInternal = case namedInternalChecker of Nothing -> id Just f -> \(PatchSet ts ps) -> PatchSet ts (filterOutRLRL (runInternalChecker f . hopefully) ps) tagCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () tagCmd _ opts args = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \(repository :: Repository rt p wR wU wR) -> do date <- getDate (hasPipe opts) the_author <- getAuthor (author ? opts) (hasPipe opts) patches <- readRepo repository tags <- repoTags patches let nonInternalPatches = filterNonInternal patches Sealed chosenPatches <- if O.askDeps ? opts then mapSeal (appendPSFL emptyPatchSet) <$> askAboutTagDepends opts (patchSet2FL nonInternalPatches) else return $ Sealed nonInternalPatches let deps = getUncovered chosenPatches (name, long_comment) <- get_name_log (NilFL :: FL (PrimOf p) wA wA) args tags myinfo <- patchinfo date name the_author long_comment let mypatch = infopatch myinfo NilFL _ <- tentativelyAddPatch repository (compress ? opts) (verbosity ? opts) YesUpdateWorking $ n2pia $ adddeps mypatch deps finalizeRepositoryChanges repository YesUpdateWorking (compress ? opts) putStrLn $ "Finished tagging patch '"++name++"'" where get_name_log ::(PrimPatch prim) => FL prim wA wA -> [String] -> [String] -> IO (String, [String]) get_name_log nilFL a tags = do (name, comment, _) <- getLog (case parseFlags O.patchname opts of Nothing -> Just (unwords a) Just s -> Just s) (hasPipe opts) (parseFlags O.logfile opts) (parseFlags O.askLongComment opts) Nothing nilFL when (length name < 2) $ hPutStr stderr $ "Do you really want to tag '" ++name++"'? If not type: darcs obliterate --last=1\n" when (name `elem` tags) $ putStrLn $ "WARNING: The tag " ++ "\"" ++ name ++ "\"" ++ " already exists." return ("TAG " ++ name, comment) -- This may be useful for developers, but users don't care about -- internals: -- -- A tagged version automatically depends on all patches in the -- repository. This allows you to later reproduce precisely that -- version. The tag does this by depending on all patches in the -- repository, except for those which are depended upon by other tags -- already in the repository. In the common case of a sequential -- series of tags, this means that the tag depends on all patches -- since the last tag, plus that tag itself. askAboutTagDepends :: forall rt p wX wY . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> FL (PatchInfoAnd rt p) wX wY -> IO (Sealed (FL (PatchInfoAnd rt p) wX)) askAboutTagDepends flags ps = do let opts = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = [] , S.interactive = True , S.selectDeps = O.PromptDeps , S.summary = O.NoSummary , S.withContext = O.NoContext } (deps:>_) <- runSelection ps $ ((selectionContext FirstReversed "depend on" opts Nothing Nothing) { allowSkipAll = False }) return $ Sealed deps hasPipe :: [DarcsFlag] -> Bool hasPipe = parseFlags O.pipe darcs-2.14.5/src/Darcs/UI/Commands/Test.hs0000644000000000000000000003146207346545000016252 0ustar0000000000000000-- Copyright (C) 2002-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Test ( test ) where import Prelude () import Darcs.Prelude hiding ( init ) import Control.Exception ( catch, IOException ) import Control.Monad( when ) import System.Process ( system ) import System.Exit ( ExitCode(..), exitWith ) import System.IO ( hFlush, stdout ) import Darcs.Util.Tree( Tree ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts , nodefaults , putInfo , amInHashedRepository ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags ( DarcsFlag, useCache, verbosity ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Patch.PatchInfoAnd ( hopefully ) import Darcs.Repository ( readRepo , withRepository , RepoJob(..) , withRecorded , setScriptsExecutablePatches , setScriptsExecutable ) import Darcs.Patch.Witnesses.Ordered ( RL(..) , (:>)(..) , (+<+) , reverseRL , splitAtRL , lengthRL , mapRL , mapFL , mapRL_RL ) import Darcs.Patch.ApplyMonad ( ApplyMonad ) import Darcs.Patch.Apply ( Apply, ApplyState ) import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Patch.Invert ( Invert ) import Darcs.Patch ( RepoPatch , apply , description , invert ) import Darcs.Patch.Named.Wrapped ( WrappedNamed ) import Darcs.Patch.Set ( patchSet2RL ) import Darcs.Util.Printer ( putDocLn , text ) import Darcs.Util.Path ( AbsolutePath ) import Darcs.Repository.ApplyPatches ( DefaultIO, runDefault ) import Darcs.Repository.Test ( getTest ) import Darcs.Util.Lock ( withTempDir , withPermDir ) testDescription :: String testDescription = "Run tests and search for the patch that introduced a bug." testHelp :: String testHelp = unlines [ "Run test on the current recorded state of the repository. Given no" ,"arguments, it uses the default repository test (see `darcs setpref`)." ,"Given one argument, it treats it as a test command." ,"Given two arguments, the first is an initialization command and the" ,"second is the test (meaning the exit code of the first command is not" ,"taken into account to determine success of the test)." ,"If given the `--linear` or `--bisect` flags, it tries to find the most" ,"recent version in the repository which passes a test." ,"" ,"`--linear` does linear search starting from head, and moving away" ,"from head. This strategy is best when the test runs very quickly" ,"or the patch you're seeking is near the head." ,"" ,"`--bisect` does binary search. This strategy is best when the test" ,"runs very slowly or the patch you're seeking is likely to be in" ,"the repository's distant past." ,"" ,"`--backoff` starts searching from head, skipping further and further" ,"into the past until the test succeeds. It then does a binary search" ,"on a subset of those skipped patches. This strategy works well unless" ,"the patch you're seeking is in the repository's distant past." ,"" ,"Under the assumption that failure is monotonous, `--linear` and" ,"`--bisect` produce the same result. (Monotonous means that when moving" ,"away from head, the test result changes only once from \"fail\" to" ,"\"ok\".) If failure is not monotonous, any one of the patches that" ,"break the test is found at random." ] test :: DarcsCommand [DarcsFlag] test = DarcsCommand { commandProgramName = "darcs" , commandName = "test" , commandHelp = testHelp , commandDescription = testDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[[INITIALIZATION]", "COMMAND]"] , commandCommand = testCommand , commandPrereq = amInHashedRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc testAdvancedOpts , commandBasicOptions = odesc testBasicOpts , commandDefaults = defaultFlags testOpts , commandCheckOptions = ocheck testOpts , commandParseOptions = onormalise testOpts } where testBasicOpts = O.testStrategy ^ O.leaveTestDir ^ O.repoDir testAdvancedOpts = O.setScriptsExecutable testOpts = testBasicOpts `withStdOpts` testAdvancedOpts -- | Functions defining a strategy for executing a test type Strategy = forall rt p wX wY . (RepoPatch p, ApplyMonad (ApplyState p) DefaultIO, ApplyState p ~ Tree) => [DarcsFlag] -> IO ExitCode -- ^ test command -> ExitCode -> RL (WrappedNamed rt p) wX wY -> IO () testCommand :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () testCommand _ opts args = withRepository (useCache ? opts) $ RepoJob $ \repository -> do patches <- readRepo repository (init,testCmd) <- case args of [] -> do t <- getTest (verbosity ? opts) return (return ExitSuccess, t) [cmd] -> do putStrLn $ "Using test command:\n"++cmd return (return ExitSuccess, system cmd) [init,cmd] -> do putStrLn $ "Using initialization command:\n"++init putStrLn $ "Using test command:\n"++cmd return (system init, system cmd) _ -> fail "Test expects zero to two arguments." let wd = case O.leaveTestDir ? opts of O.YesLeaveTestDir -> withPermDir O.NoLeaveTestDir -> withTempDir withRecorded repository (wd "testing") $ \_ -> do when (O.yes (O.setScriptsExecutable ? opts)) setScriptsExecutable _ <- init putInfo opts $ text "Running test...\n" testResult <- testCmd let track = chooseStrategy (O.testStrategy ? opts) track opts testCmd testResult (mapRL_RL hopefully . patchSet2RL $ patches) chooseStrategy :: O.TestStrategy -> Strategy chooseStrategy O.Bisect = trackBisect chooseStrategy O.Linear = trackLinear chooseStrategy O.Backoff = trackBackoff chooseStrategy O.Once = oneTest -- | test only the last recorded state oneTest :: Strategy oneTest opts _ ExitSuccess _ = putInfo opts $ text "Test ran successfully.\n" oneTest opts _ testResult _ = do putInfo opts $ text "Test failed!\n" exitWith testResult -- | linear search (with --linear) trackLinear :: Strategy trackLinear _ _ ExitSuccess _ = putStrLn "Success!" trackLinear opts testCmd (ExitFailure _) (ps:<:p) = do let ip = invert p safeApply ip when (O.yes (O.setScriptsExecutable ? opts)) $ setScriptsExecutablePatches ip putStrLn "Trying without the patch:" putDocLn $ description ip hFlush stdout testResult <- testCmd trackLinear opts testCmd testResult ps trackLinear _ _ (ExitFailure _) NilRL = putStrLn "Noone passed the test!" -- | exponential backoff search (with --backoff) trackBackoff :: Strategy trackBackoff _ _ ExitSuccess NilRL = putStrLn "Success!" trackBackoff _ _ (ExitFailure _) NilRL = putStrLn "Noone passed the test!" trackBackoff _ _ ExitSuccess _ = putStrLn "Test does not fail on head." trackBackoff opts testCmd (ExitFailure _) ps = trackNextBackoff opts testCmd 4 ps trackNextBackoff :: (RepoPatch p, ApplyMonad (ApplyState p) DefaultIO, ApplyState p ~ Tree) => [DarcsFlag] -> IO ExitCode -> Int -- ^ number of patches to skip -> RL (WrappedNamed rt p) wY wZ -- ^ patches not yet skipped -> IO () trackNextBackoff _ _ _ NilRL = putStrLn "Noone passed the test!" trackNextBackoff opts testCmd n ahead | n >= lengthRL ahead = initialBisect opts testCmd ahead trackNextBackoff opts testCmd n ahead = do putStrLn $ "Skipping " ++ show n ++ " patches..." hFlush stdout case splitAtRL n ahead of ( ahead' :> skipped' ) -> do unapplyRL skipped' when (O.yes (O.setScriptsExecutable ? opts)) $ setScriptsExecutablePatches skipped' testResult <- testCmd case testResult of ExitFailure _ -> trackNextBackoff opts testCmd (2*n) ahead' ExitSuccess -> do applyRL skipped' -- offending patch is one of these initialBisect opts testCmd skipped' -- bisect to find it -- | binary search (with --bisect) trackBisect :: Strategy trackBisect _ _ ExitSuccess NilRL = putStrLn "Success!" trackBisect _ _ (ExitFailure _) NilRL = putStrLn "Noone passed the test!" trackBisect _ _ ExitSuccess _ = putStrLn "Test does not fail on head." trackBisect opts testCmd (ExitFailure _) ps = initialBisect opts testCmd ps initialBisect :: (RepoPatch p, ApplyMonad (ApplyState p) DefaultIO, ApplyState p ~ Tree) => [DarcsFlag] -> IO ExitCode -> RL (WrappedNamed rt p) wX wY -> IO () initialBisect opts testCmd ps = trackNextBisect opts currProg testCmd BisectRight (patchTreeFromRL ps) where maxProg = 1 + round ((logBase 2 $ fromIntegral $ lengthRL ps) :: Double) currProg = (1, maxProg) :: BisectState -- | Bisect Patch Tree data PatchTree p wX wY where Leaf :: p wX wY -> PatchTree p wX wY Fork :: PatchTree p wY wZ -> PatchTree p wX wY -> PatchTree p wX wZ -- | Direction of Bisect trackdown data BisectDir = BisectLeft | BisectRight deriving Show -- | Progress of Bisect type BisectState = (Int, Int) -- | Create Bisect PatchTree from the RL patchTreeFromRL :: RL p wX wY -> PatchTree p wX wY patchTreeFromRL (NilRL :<: l) = Leaf l patchTreeFromRL xs = case splitAtRL (lengthRL xs `div` 2) xs of (r :> l) -> Fork (patchTreeFromRL l) (patchTreeFromRL r) -- | Convert PatchTree back to RL patchTree2RL :: PatchTree p wX wY -> RL p wX wY patchTree2RL (Leaf p) = NilRL :<: p patchTree2RL (Fork l r) = patchTree2RL r +<+ patchTree2RL l -- | Iterate the Patch Tree trackNextBisect :: (RepoPatch p, ApplyMonad (ApplyState p) DefaultIO, ApplyState p ~ Tree) => [DarcsFlag] -> BisectState -> IO ExitCode -- ^ test command -> BisectDir -> PatchTree (WrappedNamed rt p) wX wY -> IO () trackNextBisect opts (dnow, dtotal) testCmd dir (Fork l r) = do putStr $ "Trying " ++ show dnow ++ "/" ++ show dtotal ++ " sequences...\n" hFlush stdout case dir of BisectRight -> jumpHalfOnRight opts l -- move in temporary repo BisectLeft -> jumpHalfOnLeft opts r -- within given direction testResult <- testCmd -- execute test on repo case testResult of ExitSuccess -> trackNextBisect opts (dnow+1, dtotal) testCmd BisectLeft l -- continue left (to the present) _ -> trackNextBisect opts (dnow+1, dtotal) testCmd BisectRight r -- continue right (to the past) trackNextBisect _ _ _ _ (Leaf p) = do putStrLn "Last recent patch that fails the test (assuming monotony in the given range):" putDocLn (description p) jumpHalfOnRight :: (Invert p, Apply p, PatchInspect p, ApplyMonad (ApplyState p) DefaultIO) => [DarcsFlag] -> PatchTree p wX wY -> IO () jumpHalfOnRight opts l = do unapplyRL ps when (O.yes (O.setScriptsExecutable ? opts)) $ setScriptsExecutablePatches ps where ps = patchTree2RL l jumpHalfOnLeft :: (Apply p, PatchInspect p, ApplyMonad (ApplyState p) DefaultIO) => [DarcsFlag] -> PatchTree p wX wY -> IO () jumpHalfOnLeft opts r = do applyRL p when (O.yes (O.setScriptsExecutable ? opts)) $ setScriptsExecutablePatches p where p = patchTree2RL r applyRL :: (Apply p, ApplyMonad (ApplyState p) DefaultIO) => RL p wX wY -> IO () applyRL patches = sequence_ (mapFL safeApply (reverseRL patches)) unapplyRL :: (Invert p, Apply p, ApplyMonad (ApplyState p) DefaultIO) => RL p wX wY -> IO () unapplyRL patches = sequence_ (mapRL (safeApply . invert) patches) safeApply :: (Apply p, ApplyMonad (ApplyState p) DefaultIO) => p wX wY -> IO () safeApply p = runDefault (apply p) `catch` \(msg :: IOException) -> fail $ "Bad patch:\n" ++ show msg darcs-2.14.5/src/Darcs/UI/Commands/TransferMode.hs0000644000000000000000000000771707346545000017732 0ustar0000000000000000-- Copyright (C) 2008 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- The pragma above is only for pattern guards. module Darcs.UI.Commands.TransferMode ( transferMode ) where import Prelude () import Darcs.Prelude import Control.Exception ( catch ) import System.IO ( stdout, hFlush ) import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Exception ( prettyException ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInRepository ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags ( DarcsFlag ) import Darcs.UI.Options ( oid, odesc, ocheck, onormalise, defaultFlags ) import qualified Darcs.UI.Options.All as O import Darcs.Util.Progress ( setProgressMode ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Path ( AbsolutePath ) import Darcs.Util.Ssh ( transferModeHeader ) import qualified Data.ByteString as B (hPut, readFile, length, ByteString) transferModeDescription :: String transferModeDescription = "Internal command for efficient ssh transfers." transferModeHelp :: String transferModeHelp = "When pulling from or pushing to a remote repository over ssh, if both\n" ++ "the local and remote ends have Darcs 2, the `transfer-mode' command\n" ++ "will be invoked on the remote end. This allows Darcs to intelligently\n" ++ "transfer information over a single ssh connection.\n" ++ "\n" ++ "If either end runs Darcs 1, a separate ssh connection will be created\n" ++ "for each transfer. As well as being less efficient, this means users\n" ++ "who do not run ssh-agent will be prompted for the ssh password tens or\n" ++ "hundreds of times!\n" transferMode :: DarcsCommand [DarcsFlag] transferMode = DarcsCommand { commandProgramName = "darcs" , commandName = "transfer-mode" , commandHelp = transferModeHelp , commandDescription = transferModeDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCompleteArgs = noArgs , commandCommand = transferModeCmd , commandPrereq = amInRepository , commandArgdefaults = nodefaults , commandAdvancedOptions = [] , commandBasicOptions = odesc transferModeBasicOpts , commandDefaults = defaultFlags transferModeOpts , commandCheckOptions = ocheck transferModeOpts , commandParseOptions = onormalise transferModeOpts } where transferModeBasicOpts = O.repoDir transferModeOpts = transferModeBasicOpts `withStdOpts` oid transferModeCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () transferModeCmd _ _ _ = do setProgressMode False putStrLn transferModeHeader hFlush stdout withCurrentDirectory darcsdir transfer transfer :: IO () transfer = do 'g':'e':'t':' ':fn <- getLine x <- readfile fn case x of Right c -> do putStrLn $ "got " ++ fn print $ B.length c B.hPut stdout c hFlush stdout Left e -> do putStrLn $ "error " ++ fn print e hFlush stdout transfer readfile :: String -> IO (Either String B.ByteString) readfile fn = (Right `fmap` B.readFile fn) `catch` (return . Left . prettyException) darcs-2.14.5/src/Darcs/UI/Commands/Unrecord.hs0000644000000000000000000004030007346545000017103 0ustar0000000000000000-- Copyright (C) 2002-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE OverloadedStrings #-} module Darcs.UI.Commands.Unrecord ( unrecord , unpull , obliterate , getLastPatches , matchingHead ) where import Prelude () import Darcs.Prelude import Prelude hiding ( (^) ) import Control.Exception ( catch, IOException ) import Control.Monad ( when ) import Data.Maybe( isJust ) import Darcs.Util.Tree( Tree ) import System.Exit ( exitSuccess ) import Darcs.Patch ( IsRepoType, RepoPatch, invert, commute, effect ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Bundle ( makeBundleN, contextPatches, minContext ) import Darcs.Patch.Depends ( findCommonWithThem, patchSetUnion ) import Darcs.Patch.Match ( firstMatch, matchFirstPatchset, matchAPatch, MatchFlag ) import Darcs.Patch.PatchInfoAnd ( hopefully, patchDesc ) import Darcs.Patch.Set ( PatchSet(..), Tagged(..), appendPSFL, Origin, SealedPatchSet ) import Darcs.Patch.Witnesses.Sealed ( Sealed(..), seal ) import Darcs.Patch.Witnesses.Ordered ( RL(..), (:>)(..), (+<+), mapFL_FL, nullFL, reverseRL, mapRL, FL(..) ) import Darcs.Util.Path( useAbsoluteOrStd, AbsolutePath, toFilePath, doesPathExist ) import Darcs.Util.SignalHandler ( catchInterrupt ) import Darcs.Repository ( PatchInfoAnd, withRepoLock, RepoJob(..), Repository, tentativelyRemovePatches, finalizeRepositoryChanges, tentativelyAddToPending, applyToWorking, readRepo, invalidateIndex, unrecordedChanges, identifyRepositoryFor ) import Darcs.Repository.Flags( UseIndex(..), ScanKnown(..), UpdateWorking(..), DryRun(NoDryRun) ) import Darcs.Util.Lock( writeDocBinFile ) import Darcs.Repository.Prefs ( getDefaultRepoPath ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, commandAlias , putVerbose , setEnvDarcsPatches, amInHashedRepository , putInfo ) import Darcs.UI.Commands.Util ( getUniqueDPatchName, printDryRunMessageAndExit ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags ( DarcsFlag, changesReverse, compress, verbosity, getOutput , useCache, dryRun, umask, minimize , diffAlgorithm, xmlOutput, isInteractive, selectDeps ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import Darcs.UI.Options.All ( notInRemoteFlagName ) import qualified Darcs.UI.Options.All as O import Darcs.UI.SelectChanges ( WhichChanges(..), selectionContext, runSelection ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions (..) ) import Darcs.Util.English ( presentParticiple ) import Darcs.Util.Printer ( text, putDoc, vcat, (<+>), ($$) ) import Darcs.Util.Progress ( debugMessage ) unrecordDescription :: String unrecordDescription = "Remove recorded patches without changing the working tree." unrecordHelp :: String unrecordHelp = unlines [ "Unrecord does the opposite of record: it deletes patches from" , "the repository, without changing the working tree." , "Deleting patches from the repository makes active changes again" , "which you may record or revert later." , "Beware that you should not use this command if there is a" , "possibility that another user may have already pulled the patch." ] unrecord :: DarcsCommand [DarcsFlag] unrecord = DarcsCommand { commandProgramName = "darcs" , commandName = "unrecord" , commandHelp = unrecordHelp , commandDescription = unrecordDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = unrecordCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc unrecordAdvancedOpts , commandBasicOptions = odesc unrecordBasicOpts , commandDefaults = defaultFlags unrecordOpts , commandCheckOptions = ocheck unrecordOpts , commandParseOptions = onormalise unrecordOpts } where unrecordBasicOpts = O.notInRemote ^ O.matchSeveralOrLast ^ O.selectDeps ^ O.interactive -- True ^ O.repoDir unrecordAdvancedOpts = O.compress ^ O.umask ^ O.changesReverse unrecordOpts = unrecordBasicOpts `withStdOpts` unrecordAdvancedOpts unrecordCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () unrecordCmd _ opts _ = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do (_ :> removal_candidates) <- preselectPatches opts repository let direction = if changesReverse ? opts then Last else LastReversed context = selectionContext direction "unrecord" (patchSelOpts opts) Nothing Nothing (_ :> to_unrecord) <- runSelection removal_candidates context when (nullFL to_unrecord) $ do putInfo opts "No patches selected!" exitSuccess putVerbose opts $ text "About to write out (potentially) modified patches..." setEnvDarcsPatches to_unrecord invalidateIndex repository _ <- tentativelyRemovePatches repository (compress ? opts) YesUpdateWorking to_unrecord finalizeRepositoryChanges repository YesUpdateWorking (compress ? opts) putInfo opts "Finished unrecording." getLastPatches :: (IsRepoType rt, RepoPatch p) => [MatchFlag] -> PatchSet rt p Origin wR -> (PatchSet rt p :> FL (PatchInfoAnd rt p)) Origin wR getLastPatches matchFlags ps = case matchFirstPatchset matchFlags ps of Sealed p1s -> findCommonWithThem ps p1s unpullDescription :: String unpullDescription = "Opposite of pull; unsafe if patch is not in remote repository." unpullHelp :: String unpullHelp = unlines [ "Unpull completely removes recorded patches from your local repository." , "The changes will be undone in your working tree and the patches" , "will not be shown in your changes list anymore. Beware that if the" , "patches are not still present in another repository you will lose" , "precious code by unpulling!" , "" , "One way to save unpulled patches is to use the -O flag. A patch" , "bundle will be created locally, that you will be able to apply" , "later to your repository with `darcs apply`." ] unpull :: DarcsCommand [DarcsFlag] unpull = (commandAlias "unpull" Nothing obliterate) { commandHelp = unpullHelp , commandDescription = unpullDescription , commandCommand = unpullCmd } unpullCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () unpullCmd = genericObliterateCmd "unpull" obliterateDescription :: String obliterateDescription = "Delete selected patches from the repository." obliterateHelp :: String obliterateHelp = unlines [ "Obliterate completely removes recorded patches from your local" , "repository. The changes will be undone in your working tree and the" , "patches will not be shown in your changes list anymore. Beware that" , "you can lose precious code by obliterating!" , "" , "One way to save obliterated patches is to use the -O flag. A patch" , "bundle will be created locally, that you will be able to apply" , "later to your repository with `darcs apply`." ] obliterate :: DarcsCommand [DarcsFlag] obliterate = DarcsCommand { commandProgramName = "darcs" , commandName = "obliterate" , commandHelp = obliterateHelp , commandDescription = obliterateDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = obliterateCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc obliterateAdvancedOpts , commandBasicOptions = odesc obliterateBasicOpts , commandDefaults = defaultFlags obliterateOpts , commandCheckOptions = ocheck obliterateOpts , commandParseOptions = onormalise obliterateOpts } where obliterateBasicOpts = O.notInRemote ^ O.matchSeveralOrLast ^ O.selectDeps ^ O.interactive ^ O.repoDir ^ O.summary ^ O.output ^ O.minimize ^ O.diffAlgorithm ^ O.dryRunXml obliterateAdvancedOpts = O.compress ^ O.useIndex ^ O.umask ^ O.changesReverse obliterateOpts = obliterateBasicOpts `withStdOpts` obliterateAdvancedOpts obliterateCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () obliterateCmd = genericObliterateCmd "obliterate" -- | genericObliterateCmd is the function that executes the "obliterate" and -- "unpull" commands. The first argument is the name under which the command is -- invoked (@unpull@ or @obliterate@). genericObliterateCmd :: String -> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () genericObliterateCmd cmdname _ opts _ = let cacheOpt = useCache ? opts verbOpt = verbosity ? opts in withRepoLock (dryRun ? opts) cacheOpt YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do -- FIXME we may need to honour --ignore-times here, although this -- command does not take that option (yet) pend <- unrecordedChanges (UseIndex, ScanKnown, diffAlgorithm ? opts) O.NoLookForMoves O.NoLookForReplaces repository Nothing (auto_kept :> removal_candidates) <- preselectPatches opts repository let direction = if changesReverse ? opts then Last else LastReversed context = selectionContext direction cmdname (patchSelOpts opts) Nothing Nothing (kept :> removed) <- runSelection removal_candidates context when (nullFL removed) $ do putInfo opts "No patches selected!" exitSuccess case commute (effect removed :> pend) of Nothing -> fail $ "Can't " ++ cmdname ++ " patch without reverting some " ++ "unrecorded change." Just (_ :> p_after_pending) -> do printDryRunMessageAndExit "obliterate" verbOpt (O.summary ? opts) (dryRun ? opts) (xmlOutput ? opts) (isInteractive True opts) removed setEnvDarcsPatches removed when (isJust $ getOutput opts "") $ savetoBundle opts (auto_kept `appendPSFL` kept) removed invalidateIndex repository _ <- tentativelyRemovePatches repository (compress ? opts) YesUpdateWorking removed tentativelyAddToPending repository YesUpdateWorking $ invert $ effect removed finalizeRepositoryChanges repository YesUpdateWorking (compress ? opts) debugMessage "Applying patches to working directory..." _ <- applyToWorking repository verbOpt (invert p_after_pending) `catch` \(e :: IOException) -> fail $ "Couldn't undo patch in working dir.\n" ++ show e putInfo opts $ "Finished" <+> text (presentParticiple cmdname) <> "." -- | Get the union of the set of patches in each specified location remotePatches :: (IsRepoType rt, RepoPatch p) => [DarcsFlag] -> Repository rt p wX wU wT -> [O.NotInRemote] -> IO (SealedPatchSet rt p Origin) remotePatches opts repository nirs = do nirsPaths <- mapM getNotInRemotePath nirs putInfo opts $ "Determining patches not in" <+> pluralExtra nirsPaths $$ itemize nirsPaths patchSetUnion `fmap` mapM readNir nirsPaths where pluralExtra names = if length names > 1 then "any of" else mempty itemize = vcat . map (text . (" - " ++)) readNir n = do r <- identifyRepositoryFor repository (useCache ? opts) n rps <- readRepo r return $ seal rps getNotInRemotePath :: O.NotInRemote -> IO String getNotInRemotePath (O.NotInRemotePath p) = return p getNotInRemotePath O.NotInDefaultRepo = do defaultRepo <- getDefaultRepoPath let err = fail $ "No default push/pull repo configured, please pass a " ++ "repo name to --" ++ notInRemoteFlagName maybe err return defaultRepo -- | matchingHead returns the repository up to some tag. The tag t is the last -- tag such that there is a patch after t that is matched by the user's query. matchingHead :: forall rt p wR . (IsRepoType rt, RepoPatch p) => [MatchFlag] -> PatchSet rt p Origin wR -> (PatchSet rt p :> FL (PatchInfoAnd rt p)) Origin wR matchingHead matchFlags set = case mh set of (start :> patches) -> start :> reverseRL patches where mh :: forall wX . PatchSet rt p Origin wX -> (PatchSet rt p :> RL (PatchInfoAnd rt p)) Origin wX mh s@(PatchSet _ x) | or (mapRL (matchAPatch matchFlags) x) = contextPatches s mh (PatchSet (ts :<: Tagged t _ ps) x) = case mh (PatchSet ts (ps :<: t)) of (start :> patches) -> start :> patches +<+ x mh ps = ps :> NilRL savetoBundle :: (RepoPatch p, ApplyState p ~ Tree) => [DarcsFlag] -> PatchSet rt p Origin wZ -> FL (PatchInfoAnd rt p) wZ wT -> IO () savetoBundle opts kept removed@(x :>: _) = do let genFullBundle = makeBundleN Nothing kept (mapFL_FL hopefully removed) bundle <- if not (minimize ? opts) then genFullBundle else do putInfo opts "Minimizing context, to generate bundle with full context hit ctrl-C..." ( case minContext kept removed of Sealed (kept' :> removed') -> makeBundleN Nothing kept' (mapFL_FL hopefully removed') ) `catchInterrupt` genFullBundle filename <- getUniqueDPatchName (patchDesc x) let Just outname = getOutput opts filename exists <- useAbsoluteOrStd (doesPathExist . toFilePath) (return False) outname when exists $ fail $ "Directory or file named '" ++ (show outname) ++ "' already exists." useAbsoluteOrStd writeDocBinFile putDoc outname bundle savetoBundle _ _ NilFL = return () preselectPatches :: (IsRepoType rt, RepoPatch p) => [DarcsFlag] -> Repository rt p wR wU wT -> IO ((PatchSet rt p :> FL (PatchInfoAnd rt p)) Origin wR) preselectPatches opts repo = do allpatches <- readRepo repo let matchFlags = parseFlags O.matchSeveralOrLast opts case O.notInRemote ? opts of [] -> do return $ if firstMatch matchFlags then getLastPatches matchFlags allpatches else matchingHead matchFlags allpatches -- FIXME what about match options when we have --not-in-remote? -- It looks like they are simply ignored. nirs -> do (Sealed thems) <- remotePatches opts repo nirs return $ findCommonWithThem allpatches thems patchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions patchSelOpts flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = parseFlags O.matchSeveralOrLast flags , S.interactive = isInteractive True flags , S.selectDeps = selectDeps ? flags , S.summary = O.summary ? flags , S.withContext = O.NoContext } darcs-2.14.5/src/Darcs/UI/Commands/Unrevert.hs0000644000000000000000000001716207346545000017146 0ustar0000000000000000-- Copyright (C) 2003-2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Unrevert ( unrevert, writeUnrevert ) where import Prelude () import Darcs.Prelude import Control.Exception ( catch, IOException ) import System.Exit ( exitSuccess ) import Darcs.Util.Tree( Tree ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, amInHashedRepository ) import Darcs.UI.Completion ( noArgs ) import Darcs.UI.Flags ( diffingOpts, verbosity, useCache, umask, compress, diffAlgorithm , isInteractive, withContext ) import Darcs.Repository.Flags ( UseIndex(..), ScanKnown (..), Reorder(..), AllowConflicts(..), ExternalMerge(..) , WantGuiPause(..), UpdateWorking(..), DryRun(NoDryRun) ) import Darcs.UI.Flags ( DarcsFlag ) import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.Repository ( SealedPatchSet, Repository, withRepoLock, RepoJob(..), unrevertUrl, considerMergeToWorking, tentativelyAddToPending, finalizeRepositoryChanges, readRepo, readRecorded, applyToWorking, unrecordedChanges ) import Darcs.Patch ( IsRepoType, RepoPatch, PrimOf, commute, fromPrims ) import Darcs.Patch.Apply( ApplyState ) import Darcs.Patch.Named.Wrapped ( namepatch ) import Darcs.Patch.Rebase ( dropAnyRebase ) import Darcs.Patch.Set ( Origin ) import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed) ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (:>)(..), (+>+) ) import Darcs.UI.SelectChanges ( WhichChanges(First) , runSelection , selectionContextPrim ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions (..) ) import qualified Data.ByteString as B import Darcs.Util.Lock ( writeDocBinFile, removeFileMayNotExist ) import Darcs.Patch.Depends ( mergeThem ) import Darcs.UI.External ( catchall ) import Darcs.Util.Prompt ( askUser ) import Darcs.Patch.Bundle ( scanBundle, makeBundleN ) import Darcs.Util.IsoDate ( getIsoDateTime ) import Darcs.Util.SignalHandler ( withSignalsBlocked ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Path ( AbsolutePath ) unrevertDescription :: String unrevertDescription = "Undo the last revert." unrevertHelp :: String unrevertHelp = "Unrevert is a rescue command in case you accidentally reverted\n" ++ "something you wanted to keep (for example, typing `darcs rev -a`\n" ++ "instead of `darcs rec -a`).\n" ++ "\n" ++ "This command may fail if the repository has changed since the revert\n" ++ "took place. Darcs will ask for confirmation before executing an\n" ++ "interactive command that will DEFINITELY prevent unreversion.\n" patchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions patchSelOpts flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = [] , S.interactive = isInteractive True flags , S.selectDeps = O.PromptDeps -- option not supported, use default , S.summary = O.NoSummary -- option not supported, use default , S.withContext = withContext ? flags } unrevert :: DarcsCommand [DarcsFlag] unrevert = DarcsCommand { commandProgramName = "darcs" , commandName = "unrevert" , commandHelp = unrevertHelp , commandDescription = unrevertDescription , commandExtraArgs = 0 , commandExtraArgHelp = [] , commandCommand = unrevertCmd , commandPrereq = amInHashedRepository , commandCompleteArgs = noArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc unrevertAdvancedOpts , commandBasicOptions = odesc unrevertBasicOpts , commandDefaults = defaultFlags unrevertOpts , commandCheckOptions = ocheck unrevertOpts , commandParseOptions = onormalise unrevertOpts } where unrevertBasicOpts = O.useIndex ^ O.interactive -- True ^ O.repoDir ^ O.withContext ^ O.diffAlgorithm unrevertAdvancedOpts = O.umask unrevertOpts = unrevertBasicOpts `withStdOpts` unrevertAdvancedOpts unrevertCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () unrevertCmd _ opts [] = withRepoLock NoDryRun (useCache ? opts) YesUpdateWorking (umask ? opts) $ RepoJob $ \repository -> do us <- readRepo repository Sealed them <- unrevertPatchBundle repository recorded <- readRecorded repository unrecorded <- unrecordedChanges (diffingOpts opts {- always ScanKnown here -}) O.NoLookForMoves O.NoLookForReplaces repository Nothing Sealed h_them <- return $ mergeThem us them Sealed pw <- considerMergeToWorking repository "unrevert" YesAllowConflictsAndMark YesUpdateWorking NoExternalMerge NoWantGuiPause (compress ? opts) (verbosity ? opts) NoReorder ( UseIndex, ScanKnown, diffAlgorithm ? opts ) NilFL h_them let context = selectionContextPrim First "unrevert" (patchSelOpts opts) Nothing Nothing (Just recorded) (p :> skipped) <- runSelection pw context tentativelyAddToPending repository YesUpdateWorking p withSignalsBlocked $ do finalizeRepositoryChanges repository YesUpdateWorking (compress ? opts) _ <- applyToWorking repository (verbosity ? opts) p `catch` \(e :: IOException) -> fail ("Error applying unrevert to working directory...\n" ++ show e) debugMessage "I'm about to writeUnrevert." writeUnrevert repository skipped recorded (unrecorded+>+p) debugMessage "Finished unreverting." unrevertCmd _ _ _ = impossible writeUnrevert :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> FL (PrimOf p) wX wY -> Tree IO -> FL (PrimOf p) wR wX -> IO () writeUnrevert repository NilFL _ _ = removeFileMayNotExist $ unrevertUrl repository writeUnrevert repository ps recorded pend = case commute (pend :> ps) of Nothing -> do really <- askUser "You will not be able to unrevert this operation! Proceed? " case really of ('y':_) -> return () _ -> exitSuccess writeUnrevert repository NilFL recorded pend Just (p' :> _) -> do rep <- dropAnyRebase <$> readRepo repository date <- getIsoDateTime np <- namepatch date "unrevert" "anon" [] (fromRepoPrims repository p') bundle <- makeBundleN (Just recorded) rep (np :>: NilFL) writeDocBinFile (unrevertUrl repository) bundle where fromRepoPrims :: RepoPatch p => Repository rt p wR wU wT -> FL (PrimOf p) wR wY -> FL p wR wY fromRepoPrims _ = fromPrims unrevertPatchBundle :: RepoPatch p => Repository rt p wR wU wT -> IO (SealedPatchSet rt p Origin) unrevertPatchBundle repository = do pf <- B.readFile (unrevertUrl repository) `catchall` fail "There's nothing to unrevert!" case scanBundle pf of Right ps -> return ps Left err -> fail $ "Couldn't parse unrevert patch:\n" ++ err darcs-2.14.5/src/Darcs/UI/Commands/Util.hs0000644000000000000000000002347507346545000016255 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE OverloadedStrings #-} module Darcs.UI.Commands.Util ( announceFiles , filterExistingPaths , testTentativeAndMaybeExit , printDryRunMessageAndExit , getUniqueRepositoryName , getUniqueDPatchName , expandDirs , doesDirectoryReallyExist , checkUnrelatedRepos , repoTags ) where import Control.Monad ( when, unless ) import Data.Maybe ( catMaybes, fromJust ) import Prelude () import Darcs.Prelude import System.Exit ( ExitCode(..), exitWith, exitSuccess ) import System.FilePath.Posix ( () ) import System.Posix.Files ( isDirectory ) import Darcs.Patch ( RepoPatch, xmlSummary ) import Darcs.Patch.Depends ( areUnrelatedRepos ) import Darcs.Patch.Info ( toXml, piTag ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info, hopefullyM ) import Darcs.Patch.Set ( PatchSet(..), patchSetfMap ) import Darcs.Patch.Witnesses.Ordered ( FL, mapFL ) import Darcs.Repository ( Repository, readRecorded, testTentative ) import Darcs.Repository.State ( readUnrecordedFiltered, readWorking, restrictBoring , TreeFilter(..), applyTreeFilter ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.Bundle ( patchFilename ) import Darcs.UI.PrintPatch ( showFriendly ) import Darcs.UI.Options.All ( Verbosity(..), SetScriptsExecutable, TestChanges (..) , RunTest(..), LeaveTestDir(..), UseIndex, ScanKnown(..) , Summary(..), DryRun(..), XmlOutput(..), LookForMoves ) import Darcs.Util.Exception ( clarifyErrors ) import Darcs.Util.File ( getFileStatus, withCurrentDirectory ) import Darcs.Util.Path ( SubPath, toFilePath, getUniquePathName, floatPath , simpleSubPath, toPath, anchorPath ) import Darcs.Util.Printer ( text, (<+>), hsep, ($$), vcat, vsep , putDocLn, insertBeforeLastline, prefix ) import Darcs.Util.Prompt ( PromptConfig(..), promptChar, promptYorn ) import Darcs.Util.Text ( pathlist ) import Darcs.Util.Tree.Monad ( virtualTreeIO, exists ) import Darcs.Util.Tree ( Tree ) import qualified Darcs.Util.Tree as Tree announceFiles :: Verbosity -> Maybe [SubPath] -> String -> IO () announceFiles Quiet _ _ = return () announceFiles _ (Just subpaths) message = putDocLn $ text message <> text ":" <+> pathlist (map toFilePath subpaths) announceFiles _ _ _ = return () testTentativeAndMaybeExit :: Repository rt p wR wU wT -> Verbosity -> TestChanges -> SetScriptsExecutable -> Bool -> String -> String -> Maybe String -> IO () testTentativeAndMaybeExit repo verb test sse interactive failMessage confirmMsg withClarification = do let (rt,ltd) = case test of NoTestChanges -> (NoRunTest, YesLeaveTestDir) YesTestChanges x -> (YesRunTest, x) testResult <- testTentative repo rt ltd sse verb unless (testResult == ExitSuccess) $ do let doExit = maybe id (flip clarifyErrors) withClarification $ exitWith testResult unless interactive doExit putStrLn $ "Looks like " ++ failMessage let prompt = "Shall I " ++ confirmMsg ++ " anyway?" yn <- promptChar (PromptConfig prompt "yn" [] (Just 'n') []) unless (yn == 'y') doExit -- | @'printDryRunMessageAndExit' action flags patches@ prints a string -- representing the action that would be taken if the @--dry-run@ option had -- not been passed to darcs. Then darcs exits successfully. @action@ is the -- name of the action being taken, like @\"push\"@ @flags@ is the list of flags -- which were sent to darcs @patches@ is the sequence of patches which would be -- touched by @action@. printDryRunMessageAndExit :: (RepoPatch p, ApplyState p ~ Tree) => String -> Verbosity -> Summary -> DryRun -> XmlOutput -> Bool -- interactive -> FL (PatchInfoAnd rt p) wX wY -> IO () printDryRunMessageAndExit action v s d x interactive patches = do when (d == YesDryRun) $ do putInfoX $ hsep [ "Would", text action, "the following changes:" ] putDocLn put_mode putInfoX $ text "" putInfoX $ text "Making no changes: this is a dry run." exitSuccess when (not interactive && s == YesSummary) $ do putInfoX $ hsep [ "Will", text action, "the following changes:" ] putDocLn put_mode where put_mode = if x == YesXml then text "" $$ vcat (mapFL (indent . xml_info s) patches) $$ text "" else vsep $ mapFL (showFriendly v s) patches putInfoX = if x == YesXml then const (return ()) else putDocLn xml_info YesSummary = xml_with_summary xml_info NoSummary = toXml . info xml_with_summary hp | Just p <- hopefullyM hp = insertBeforeLastline (toXml $ info hp) (indent $ xmlSummary p) xml_with_summary hp = toXml (info hp) indent = prefix " " -- | Given a repository and two common command options, classify the given list -- of subpaths according to whether they exist in the pristine or working tree. -- Paths which are neither in working nor pristine are reported and dropped. -- The result is a pair of path lists: those that exist only in the working tree, -- and those that exist in pristine or working. filterExistingPaths :: (RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> Verbosity -> UseIndex -> ScanKnown -> LookForMoves -> [SubPath] -> IO ([SubPath],[SubPath]) filterExistingPaths repo verb useidx scan lfm paths = do pristine <- readRecorded repo working <- readUnrecordedFiltered repo useidx scan lfm (Just paths) let filepaths = map toFilePath paths check = virtualTreeIO $ mapM (exists . floatPath) filepaths (in_pristine, _) <- check pristine (in_working, _) <- check working let paths_with_info = zip3 paths in_pristine in_working paths_in_neither = [ p | (p,False,False) <- paths_with_info ] paths_only_in_working = [ p | (p,False,True) <- paths_with_info ] paths_in_either = [ p | (p,inp,inw) <- paths_with_info, inp || inw ] or_not_added = if scan == ScanKnown then " or not added " else " " unless (verb == Quiet || null paths_in_neither) $ putDocLn $ "Ignoring non-existing" <> or_not_added <> "paths:" <+> pathlist (map toFilePath paths_in_neither) return (paths_only_in_working, paths_in_either) getUniqueRepositoryName :: Bool -> FilePath -> IO FilePath getUniqueRepositoryName talkative name = getUniquePathName talkative buildMsg buildName where buildName i = if i == -1 then name else name++"_"++show i buildMsg n = "Directory or file '"++ name ++ "' already exists, creating repository as '"++ n ++"'" getUniqueDPatchName :: FilePath -> IO FilePath getUniqueDPatchName name = getUniquePathName True buildMsg buildName where buildName i = if i == -1 then patchFilename name else patchFilename $ name++"_"++show i buildMsg n = "Directory or file '"++ name ++ "' already exists, creating dpatch as '"++ n ++"'" -- | For each directory in the list of 'SubPath's, add all paths -- under that directory to the list. If the first argument is 'True', then -- include even boring files. -- -- This is used by the add and remove commands to handle the --recursive option. expandDirs :: Bool -> [SubPath] -> IO [SubPath] expandDirs includeBoring subpaths = do boringFilter <- if includeBoring then return (TreeFilter id) else restrictBoring Tree.emptyTree fmap (map (fromJust . simpleSubPath)) $ concat `fmap` mapM (expandOne boringFilter . toPath) subpaths where expandOne boringFilter "" = listFiles boringFilter expandOne boringFilter f = do isdir <- doesDirectoryReallyExist f if not isdir then return [f] else do fs <- withCurrentDirectory f (listFiles boringFilter) return $ f: map (f ) fs listFiles boringFilter = do working <- applyTreeFilter boringFilter <$> readWorking return $ map (anchorPath "" . fst) $ Tree.list working doesDirectoryReallyExist :: FilePath -> IO Bool doesDirectoryReallyExist f = maybe False isDirectory `fmap` getFileStatus f checkUnrelatedRepos :: RepoPatch p => Bool -> PatchSet rt p wStart wX -> PatchSet rt p wStart wY -> IO () checkUnrelatedRepos allowUnrelatedRepos us them = when ( not allowUnrelatedRepos && areUnrelatedRepos us them ) $ do confirmed <- promptYorn "Repositories seem to be unrelated. Proceed?" unless confirmed $ putStrLn "Cancelled." >> exitSuccess repoTags :: PatchSet rt p wX wY -> IO [String] repoTags ps = catMaybes `fmap` patchSetfMap (return . piTag . info) ps darcs-2.14.5/src/Darcs/UI/Commands/Util/0000755000000000000000000000000007346545000015706 5ustar0000000000000000darcs-2.14.5/src/Darcs/UI/Commands/Util/Tree.hs0000644000000000000000000000513007346545000017140 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.Util.Tree ( -- * Tree lookup. treeHas , treeHasDir , treeHasFile , treeHasAnycase ) where import Prelude () import Darcs.Prelude import Control.Monad ( forM ) import Control.Monad.State.Strict( gets ) import Data.Maybe ( fromMaybe ) import qualified Darcs.Util.Tree.Monad as TM ( TreeMonad, withDirectory, fileExists, directoryExists , virtualTreeMonad, currentDirectory, exists, tree ) import Darcs.Util.Tree ( Tree, listImmediate, findTree ) import Darcs.Util.Path ( AnchoredPath(..), floatPath, eqAnycase ) treeHasAnycase :: Monad m => Tree m -> FilePath -> m Bool treeHasAnycase tree path = fst `fmap` TM.virtualTreeMonad (existsAnycase $ floatPath path) tree existsAnycase :: Monad m => AnchoredPath -> TM.TreeMonad m Bool existsAnycase (AnchoredPath []) = return True existsAnycase (AnchoredPath (x:xs)) = do wd <- TM.currentDirectory tree <- fromMaybe (bug "invalid path passed to existsAnycase") <$> gets (flip findTree wd . TM.tree) let subs = [ AnchoredPath [n] | (n, _) <- listImmediate tree, eqAnycase n x ] or `fmap` forM subs (\path -> do file <- TM.fileExists path if file then return True else TM.withDirectory path (existsAnycase $ AnchoredPath xs)) treeHas :: Monad m => Tree m -> FilePath -> m Bool treeHas tree path = fst `fmap` TM.virtualTreeMonad (TM.exists $ floatPath path) tree treeHasDir :: Monad m => Tree m -> FilePath -> m Bool treeHasDir tree path = fst `fmap` TM.virtualTreeMonad (TM.directoryExists $ floatPath path) tree treeHasFile :: Monad m => Tree m -> FilePath -> m Bool treeHasFile tree path = fst `fmap` TM.virtualTreeMonad (TM.fileExists $ floatPath path) tree darcs-2.14.5/src/Darcs/UI/Commands/WhatsNew.hs0000644000000000000000000004317407346545000017076 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.Commands.WhatsNew ( whatsnew , status ) where import Prelude () import Darcs.Prelude import Control.Monad ( void, when ) import Control.Monad.Reader ( runReaderT ) import Control.Monad.State ( evalStateT, liftIO ) import Darcs.Util.Tree ( Tree ) import System.Exit ( ExitCode (..), exitSuccess, exitWith ) import Data.List.Ordered ( nubSort ) import Darcs.Patch ( PrimOf, PrimPatch, RepoPatch , applyToTree, plainSummaryPrims, primIsHunk ) import Darcs.Patch.Apply ( Apply, ApplyState ) import Darcs.Patch.Choices ( mkPatchChoices, labelPatches, unLabel ) import Darcs.Patch.Commute ( Commute ) import Darcs.Patch.FileHunk ( IsHunk (..) ) import Darcs.Patch.Format ( PatchListFormat ) import Darcs.Patch.Inspect ( PatchInspect (..) ) import Darcs.Patch.Permutations ( partitionRL ) import Darcs.Patch.Prim.Class ( PrimDetails (..) ) import Darcs.Patch.Show ( ShowPatch, ShowContextPatch ) import Darcs.Patch.Split ( primSplitter ) import Darcs.Patch.TouchesFiles ( choosePreTouching ) import Darcs.Patch.Witnesses.Ordered ( (:>) (..), FL (..), RL (..) , lengthFL, reverseFL, reverseRL ) import Darcs.Patch.Witnesses.Sealed ( Sealed (..), Sealed2 (..) , unFreeLeft ) import Darcs.Patch.Witnesses.WZipper ( FZipper (..) ) import Darcs.Repository ( RepoJob (..), Repository , readRecorded , unrecordedChanges, withRepository ) import Darcs.Repository.Diff ( treeDiff ) import Darcs.Repository.Prefs ( filetypeFunction ) import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, amInRepository , commandAlias, nodefaults ) import Darcs.UI.Completion ( modifiedFileArgs ) import Darcs.UI.Commands.Util ( announceFiles, filterExistingPaths ) import Darcs.UI.Flags ( DarcsFlag, diffAlgorithm , withContext, useCache, fixSubPaths , verbosity, isInteractive , lookForAdds, lookForMoves, lookForReplaces , scanKnown, useIndex, diffingOpts ) import Darcs.UI.Options ( DarcsOption, (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) ) import qualified Darcs.UI.Options.All as O import Darcs.UI.PrintPatch ( contextualPrintPatch, printPatch , printPatchPager ) import Darcs.UI.SelectChanges ( InteractiveSelectionContext (..) , InteractiveSelectionM, KeyPress (..) , WhichChanges (..), backAll , backOne, currentFile , currentPatch, decide , decideWholeFile, helpFor , keysFor, prompt , selectionContextPrim, skipMundane , skipOne, printSummary ) import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions (..) ) import Darcs.Util.Path ( AbsolutePath, SubPath, toFilePath ) import Darcs.Util.Printer ( putDocLn, renderString , text, vcat ) import Darcs.Util.Prompt ( PromptConfig (..), promptChar ) commonAdvancedOpts :: DarcsOption a (O.UseIndex -> O.IncludeBoring -> a) commonAdvancedOpts = O.useIndex ^ O.includeBoring patchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions patchSelOpts flags = S.PatchSelectionOptions { S.verbosity = verbosity ? flags , S.matchFlags = [] , S.interactive = isInteractive True flags , S.selectDeps = O.PromptDeps -- option not supported, use default , S.summary = getSummary flags , S.withContext = withContext ? flags } -- lookForAdds and machineReadable set YesSummary -- unless NoSummary was given expressly -- (or by default e.g. status) getSummary :: [DarcsFlag] -> O.Summary getSummary flags = case O.maybeSummary Nothing ? flags of Just O.NoSummary -> O.NoSummary Just O.YesSummary -> O.YesSummary Nothing | O.yes (lookForAdds flags) -> O.YesSummary | O.machineReadable ? flags -> O.YesSummary | otherwise -> O.NoSummary whatsnew :: DarcsCommand [DarcsFlag] whatsnew = DarcsCommand { commandProgramName = "darcs" , commandName = "whatsnew" , commandHelp = whatsnewHelp , commandDescription = whatsnewDescription , commandExtraArgs = -1 , commandExtraArgHelp = ["[FILE or DIRECTORY]..."] , commandCommand = whatsnewCmd , commandPrereq = amInRepository , commandCompleteArgs = modifiedFileArgs , commandArgdefaults = nodefaults , commandAdvancedOptions = odesc commonAdvancedOpts , commandBasicOptions = odesc whatsnewBasicOpts , commandDefaults = defaultFlags whatsnewOpts , commandCheckOptions = ocheck whatsnewOpts , commandParseOptions = onormalise whatsnewOpts } where whatsnewBasicOpts = O.maybeSummary Nothing ^ O.withContext ^ O.machineReadable ^ O.lookfor ^ O.diffAlgorithm ^ O.repoDir ^ O.interactive -- False whatsnewOpts = whatsnewBasicOpts `withStdOpts` commonAdvancedOpts whatsnewDescription :: String whatsnewDescription = "List unrecorded changes in the working tree." whatsnewHelp :: String whatsnewHelp = "The `darcs whatsnew` command lists unrecorded changes to the working\n" ++ "tree. If you specify a set of files and directories, only unrecorded\n" ++ "changes to those files and directories are listed.\n" ++ "\n" ++ "With the `--summary` option, the changes are condensed to one line per\n" ++ "file, with mnemonics to indicate the nature and extent of the change.\n" ++ "The `--look-for-adds` option causes candidates for `darcs add` to be\n" ++ "included in the summary output. Summary mnemonics are as follows:\n" ++ "\n" ++ "* `A f` and `A d/` respectively mean an added file or directory.\n" ++ "* `R f` and `R d/` respectively mean a removed file or directory.\n" ++ "* `M f -N +M rP` means a modified file, with `N` lines deleted, `M`\n" ++ " lines added, and `P` lexical replacements.\n" ++ "* `f -> g` means a moved file or directory.\n" ++ "* `a f` and `a d/` respectively mean a new, but unadded, file or\n" ++ " directory, when using `--look-for-adds`.\n" ++ "\n" ++ " An exclamation mark (!) as in `R! foo.c`, means the change is known to\n" ++ " conflict with a change in another patch. The phrase `duplicated`\n" ++ " means the change is known to be identical to a change in another patch.\n" ++ "\n" ++ "The `--machine-readable` option implies `--summary` while making it more\n" ++ "parsable. Modified files are only shown as `M f`, and moves are shown in\n" ++ "two lines: `F f` and `T g` (as in 'From f To g').\n" ++ "\n" ++ "By default, `darcs whatsnew` uses Darcs' internal format for changes.\n" ++ "To see some context (unchanged lines) around each change, use the\n" ++ "`--unified` option. To view changes in conventional `diff` format, use\n" ++ "the `darcs diff` command; but note that `darcs whatsnew` is faster.\n" ++ "\n" ++ "This command exits unsuccessfully (returns a non-zero exit status) if\n" ++ "there are no unrecorded changes.\n" whatsnewCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () whatsnewCmd fps opts args = withRepository (useCache ? opts) $ RepoJob $ \(repo :: Repository rt p wR wU wR) -> do let scan = scanKnown (lookForAdds opts) (O.includeBoring ? opts) existing_files <- do files <- if null args then return Nothing else Just . nubSort <$> fixSubPaths fps args when (files == Just []) $ fail "No valid arguments were given." files' <- traverse (filterExistingPaths repo (verbosity ? opts) (useIndex ? opts) scan (lookForMoves opts)) files let files'' = fmap snd files' when (files'' == Just []) $ fail "None of the files you specified exist." return files'' -- get all unrecorded changes, possibly including unadded or even boring -- files if the appropriate options were supplied Sealed allInterestingChanges <- filteredUnrecordedChanges (diffingOpts opts) (lookForMoves opts) (lookForReplaces opts) repo existing_files -- get the recorded state pristine <- readRecorded repo -- the case --look-for-adds and --summary must be handled specially -- in order to distinguish added and unadded files -- TODO: it would be nice if we could return the pair -- (noLookChanges,unaddedNewPathsPs) in one go and also -- with proper witnesses (e.g. as noLookChanges +>+ unaddedNewPathsPs) -- This would also obviate the need for samePatchType. Sealed noLookChanges <- if haveLookForAddsAndSummary then -- do *not* look for adds here: filteredUnrecordedChanges (O.useIndex ? opts, O.ScanKnown, O.diffAlgorithm ? opts) (lookForMoves opts) (lookForReplaces opts) repo existing_files else return (Sealed NilFL) Sealed unaddedNewPathsPs <- if haveLookForAddsAndSummary then do noLookAddsTree <- applyAddPatchesToPristine noLookChanges pristine lookAddsTree <- applyAddPatchesToPristine allInterestingChanges pristine ftf <- filetypeFunction -- Return the patches that create files/dirs that aren't yet added. unFreeLeft <$> treeDiff (diffAlgorithm ? opts) ftf noLookAddsTree lookAddsTree else return (Sealed NilFL) -- avoid ambiguous typing for unaddedNewPathsPs: samePatchType noLookChanges unaddedNewPathsPs exitOnNoChanges allInterestingChanges announceFiles (verbosity ? opts) existing_files "What's new in" if maybeIsInteractive opts then runInteractive (interactiveHunks pristine) (patchSelOpts opts) (diffAlgorithm ? opts) pristine allInterestingChanges else if haveLookForAddsAndSummary then do printChanges pristine noLookChanges printUnaddedPaths unaddedNewPathsPs else do printChanges pristine allInterestingChanges where haveSummary = O.yes (getSummary opts) haveLookForAddsAndSummary = haveSummary && O.yes (lookForAdds opts) -- Filter out hunk patches (leaving add patches) and return the tree -- resulting from applying the filtered patches to the pristine tree. applyAddPatchesToPristine ps pristine = do adds :> _ <- return $ partitionRL primIsHunk $ reverseFL ps applyToTree (reverseRL adds) pristine exitOnNoChanges :: FL p wX wY -> IO () exitOnNoChanges NilFL = do putStrLn "No changes!" exitWith $ ExitFailure 1 exitOnNoChanges _ = return () -- This function does nothing. Its purpose is to enforce the -- same patch type for the two passed FLs. This is necessary -- in order to avoid ambiguous typing for unaddedNewPathsPs. samePatchType :: FL p wX wY -> FL p wU wV -> IO () samePatchType _ _ = return () printUnaddedPaths :: PrimPatch p => FL p wX wY -> IO () printUnaddedPaths NilFL = return () printUnaddedPaths ps = putDocLn . lowercaseAs . renderString . (plainSummaryPrims False) $ ps -- Make any add markers lowercase, to distinguish new-but-unadded files -- from those that are unrecorded, but added. lowercaseAs x = vcat $ map (text . lowercaseA) $ lines x lowercaseA ('A' : x) = 'a' : x lowercaseA x = x -- Appropriately print changes, according to the passed flags. -- Note this cannot make distinction between unadded and added files. printChanges :: ( IsHunk p, ShowPatch p, ShowContextPatch p , PatchListFormat p, Apply p , PrimDetails p, ApplyState p ~ Tree) => Tree IO -> FL p wX wY -> IO () printChanges pristine changes | haveSummary = putDocLn $ plainSummaryPrims machineReadable changes | O.yes (withContext ? opts) = contextualPrintPatch pristine changes | otherwise = printPatch changes where machineReadable = parseFlags O.machineReadable opts -- return the unrecorded changes that affect an optional list of paths. filteredUnrecordedChanges :: forall rt p wR wU wT. (RepoPatch p, ApplyState p ~ Tree) => (O.UseIndex, O.ScanKnown, O.DiffAlgorithm) -> O.LookForMoves -> O.LookForReplaces -> Repository rt p wR wU wT -> Maybe [SubPath] -> IO (Sealed (FL (PrimOf p) wT)) filteredUnrecordedChanges diffing lfm lfr repo files = let filePaths = map toFilePath <$> files in choosePreTouching filePaths <$> unrecordedChanges diffing lfm lfr repo files -- | Runs the 'InteractiveSelectionM' code runInteractive :: PrimPatch p => InteractiveSelectionM p wX wY () -- Selection to run -> S.PatchSelectionOptions -> O.DiffAlgorithm -> Tree IO -- Pristine -> FL p wX wY -- A list of patches -> IO () runInteractive i patchsel diffalg pristine ps' = do let lps' = labelPatches Nothing ps' choices' = mkPatchChoices lps' ps = evalStateT i $ ISC { total = lengthFL lps' , current = 0 , lps = FZipper NilRL lps' , choices = choices' } void $ runReaderT ps $ selectionContextPrim First "view" patchsel (Just (primSplitter diffalg)) Nothing (Just pristine) -- | The interactive part of @darcs whatsnew@ interactiveHunks :: (IsHunk p, ShowPatch p, ShowContextPatch p, Commute p, PatchInspect p, PrimDetails p, ApplyState p ~ Tree) => Tree IO -> InteractiveSelectionM p wX wY () interactiveHunks pristine = do c <- currentPatch case c of Nothing -> liftIO $ putStrLn "No more changes!" Just (Sealed2 lp) -> do liftIO $ printPatch (unLabel lp) repeatThis lp where repeatThis lp = do thePrompt <- prompt -- "Shall I view this change? (n/m)" yorn <- liftIO $ promptChar (PromptConfig thePrompt (keysFor basic_options) (keysFor adv_options) (Just 'n') "?h") case yorn of -- View change in context 'v' -> liftIO (contextualPrintPatch pristine (unLabel lp)) >> repeatThis lp -- View summary of the change 'x' -> liftIO (printSummary (unLabel lp)) >> repeatThis lp -- View change and move on 'y' -> liftIO (contextualPrintPatch pristine (unLabel lp)) >> decide True lp >> next_hunk -- Go to the next patch 'n' -> decide False lp >> next_hunk -- Skip the whole file 's' -> do currentFile >>= maybe (return ()) (\f -> decideWholeFile f False) next_hunk -- View change in a pager 'p' -> liftIO (printPatchPager $ unLabel lp) >> repeatThis lp -- Next change 'j' -> next_hunk -- Previous change 'k' -> prev_hunk -- Start from the first change 'g' -> start_over -- Quit whatsnew 'q' -> liftIO $ exitSuccess _ -> do liftIO . putStrLn $ helpFor "whatsnew" basic_options adv_options repeatThis lp start_over = backAll >> interactiveHunks pristine next_hunk = skipOne >> skipMundane >> interactiveHunks pristine prev_hunk = backOne >> interactiveHunks pristine options_yn = [ KeyPress 'v' "view this change in a context" , KeyPress 'y' "view this change in a context and go to the next one" , KeyPress 'n' "skip this change and its dependencies" ] optionsView = [ KeyPress 'p' "view this change in context wih pager " , KeyPress 'x' "view a summary of this change" ] optionsNav = [ KeyPress 'q' "quit whatsnew" , KeyPress 's' "skip the rest of the changes to this file" , KeyPress 'j' "go to the next change" , KeyPress 'k' "back up to previous change" , KeyPress 'g' "start over from the first change" ] basic_options = [ options_yn ] adv_options = [ optionsView, optionsNav ] -- | status is an alias for whatsnew, with implicit Summary and LookForAdds -- flags. We override the default description, to include the implicit flags. status :: DarcsCommand [DarcsFlag] status = statusAlias { commandDescription = statusDesc , commandAdvancedOptions = odesc commonAdvancedOpts , commandBasicOptions = odesc statusBasicOpts , commandDefaults = defaultFlags statusOpts , commandCheckOptions = ocheck statusOpts , commandParseOptions = onormalise statusOpts } where statusAlias = commandAlias "status" Nothing whatsnew statusDesc = "Alias for `darcs " ++ commandName whatsnew ++ " -ls '." statusBasicOpts = O.maybeSummary (Just O.YesSummary) ^ O.withContext ^ O.machineReadable ^ O.lookforadds O.YesLookForAdds ^ O.lookforreplaces ^ O.lookformoves ^ O.diffAlgorithm ^ O.repoDir ^ O.interactive statusOpts = statusBasicOpts `withStdOpts` commonAdvancedOpts maybeIsInteractive :: [DarcsFlag] -> Bool maybeIsInteractive = maybe False id . parseFlags O.interactive darcs-2.14.5/src/Darcs/UI/CommandsAux.hs0000644000000000000000000000616507346545000016013 0ustar0000000000000000-- Copyright (C) 2006 Tommy Pettersson -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.CommandsAux ( checkPaths , maliciousPatches , hasMaliciousPath ) where import Prelude () import Darcs.Prelude import Control.Monad ( when ) import Darcs.UI.Flags ( DarcsFlag ) import Darcs.UI.Options ( parseFlags ) import Darcs.UI.Options.All ( restrictPaths ) import Darcs.Patch.Inspect ( PatchInspect, listTouchedFiles ) import Darcs.Patch.Witnesses.Ordered ( FL, mapFL ) import Darcs.Patch.Witnesses.Sealed ( Sealed2(..), unseal2 ) import Darcs.Util.Path ( isMaliciousPath ) -- * File paths {- Darcs will operate on files and directories with the invoking user's privileges. The paths for these files and directories are stored in patches, which darcs receives in various ways. Even though darcs will not create patches with "unexpected" file paths, there are no such guarantees for received patches. A spoofed patch could inflict changes on any file or directory which the invoking user is privileged to modify. There is no one single "apply" function that can check paths, so each command is responsible for not applying patches without first checking them with one of these function when appropriate. -} {- | A convenience function to call from all darcs command functions before applying any patches. It checks for malicious paths in patches, and prints an error message and fails if it finds one. -} checkPaths :: PatchInspect p => [DarcsFlag] -> FL p wX wY -> IO () checkPaths opts patches = when (parseFlags restrictPaths opts && or (mapFL hasMaliciousPath patches)) $ fail $ unlines $ ["Malicious path in patch:"] ++ map (" " ++) (concat $ mapFL maliciousPaths patches) ++ ["", "If you are sure this is ok then you can run again with the --dont-restrict-paths option."] -- TODO: print patch(es) -- NOTE: should use safe Doc printer, this can be evil chars -- | Filter out patches that contains some malicious file path maliciousPatches :: PatchInspect p => [Sealed2 p] -> [Sealed2 p] maliciousPatches = filter (unseal2 hasMaliciousPath) hasMaliciousPath :: PatchInspect p => p wX wY -> Bool hasMaliciousPath patch = case maliciousPaths patch of [] -> False _ -> True maliciousPaths :: PatchInspect p => p wX wY -> [String] maliciousPaths patch = let paths = listTouchedFiles patch in filter isMaliciousPath paths darcs-2.14.5/src/Darcs/UI/Completion.hs0000644000000000000000000001420207346545000015674 0ustar0000000000000000-- | How to complete arguments {-# LANGUAGE RecordWildCards, NamedFieldPuns #-} module Darcs.UI.Completion ( fileArgs, knownFileArgs, unknownFileArgs, modifiedFileArgs , noArgs, prefArgs ) where import Prelude () import Darcs.Prelude import Data.List ( (\\), stripPrefix ) import Data.List.Ordered ( nubSort, minus ) import Data.Maybe ( mapMaybe ) import Darcs.Patch ( listTouchedFiles ) import Darcs.Repository.Flags ( UseCache(..) ) import Darcs.Repository.Prefs ( getPreflist ) import Darcs.Repository.Job ( RepoJob(..) , withRepository ) import Darcs.Repository.State ( readRecordedAndPending , readUnrecordedFiltered , unrecordedChanges , restrictDarcsdir , applyTreeFilter , TreeFilter(..) ) import Darcs.UI.Flags ( DarcsFlag ) import qualified Darcs.UI.Flags as Flags import qualified Darcs.UI.Options.All as O import Darcs.Util.File ( doesDirectoryReallyExist ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Path ( AnchoredPath, anchorPath , AbsolutePath, toPath, floatSubPath, makeSubPathOf ) import Darcs.Util.Tree as Tree ( Tree, ItemType(..) , expand, expandPath, list, findTree, itemType, emptyTree ) import Darcs.Util.Tree.Plain ( readPlainTree ) -- | Return all files available under the original working -- directory regardless of their repo state. -- Subdirectories get a separator (slash) appended. fileArgs :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO [FilePath] fileArgs (_, orig) _flags args = notYetListed args $ fmap (map anchoredToFilePath . listItems) $ Tree.expand . applyTreeFilter restrictDarcsdir =<< readPlainTree (toPath orig) -- | Return all files available under the original working directory that -- are unknown to darcs but could be added. -- Subdirectories get a separator (slash) appended. unknownFileArgs :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO [FilePath] unknownFileArgs fps flags args = notYetListed args $ do let sk = if Flags.includeBoring flags then O.ScanBoring else O.ScanAll lfm = Flags.lookForMoves flags lfr = Flags.lookForReplaces flags RepoTrees {have, known} <- repoTrees O.UseIndex sk lfm lfr known_paths <- listHere known fps have_paths <- listHere have fps return $ map anchoredToFilePath $ nubSort have_paths `minus` nubSort known_paths -- | Return all files available under the original working directory that -- are known to darcs (either recorded or pending). -- Subdirectories get a separator (slash) appended. knownFileArgs :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO [FilePath] knownFileArgs fps flags args = notYetListed args $ do let (ui, sk, _) = Flags.diffingOpts flags lfm = Flags.lookForMoves flags lfr = Flags.lookForReplaces flags RepoTrees {known} <- repoTrees ui sk lfm lfr map anchoredToFilePath <$> listHere known fps -- | Return all files available under the original working directory that -- are modified (relative to the recorded state). -- Subdirectories get a separator (slash) appended. modifiedFileArgs :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO [FilePath] modifiedFileArgs fps flags args = notYetListed args $ do let (ui, sk, _) = Flags.diffingOpts flags lfm = Flags.lookForMoves flags lfr = Flags.lookForReplaces flags RepoTrees {new} <- repoTrees ui sk lfm lfr case uncurry makeSubPathOf fps of Nothing -> return [] Just here -> return $ mapMaybe (stripPathPrefix (toPath here) . drop 2) new -- | Return the available prefs of the given kind. prefArgs :: String -> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO [String] prefArgs name _ _ _ = getPreflist name -- | Return an empty list. noArgs :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO [String] noArgs _ _ _ = return [] -- * unexported helper functions data RepoTrees m = RepoTrees { have :: Tree m -- ^ working tree , known :: Tree m -- ^ recorded and pending , new :: [FilePath] -- ^ unrecorded paths } repoTrees :: O.UseIndex -> O.ScanKnown -> O.LookForMoves -> O.LookForReplaces -> IO (RepoTrees IO) repoTrees ui sk lfm lfr = do inDarcsRepo <- doesDirectoryReallyExist darcsdir if inDarcsRepo then withRepository NoUseCache $ RepoJob $ \r -> do known <- readRecordedAndPending r have <- readUnrecordedFiltered r ui sk lfm Nothing -- we are only interested in the affected paths so the diff -- algorithm is irrelevant new <- listTouchedFiles <$> unrecordedChanges (ui, sk, O.MyersDiff) lfm lfr r Nothing return $ RepoTrees {..} else return RepoTrees {have = emptyTree, known = emptyTree, new = []} -- this is for completion which should give us everything under the original wd subtreeHere :: Tree IO -> (AbsolutePath, AbsolutePath) -> IO (Maybe (Tree IO)) subtreeHere tree fps = case floatSubPath <$> uncurry makeSubPathOf fps of Nothing -> do return Nothing -- here is no subtree of the repo Just here -> do flip findTree here <$> expandPath tree here listHere :: Tree IO -> (AbsolutePath, AbsolutePath) -> IO [(AnchoredPath, ItemType)] listHere tree fps = do msubtree <- subtreeHere tree fps case msubtree of Nothing -> return [] Just subtree -> listItems <$> expand subtree listItems :: Tree m -> [(AnchoredPath, ItemType)] listItems = map (\(p, i) -> (p, itemType i)) . Tree.list anchoredToFilePath :: (AnchoredPath, ItemType) -> [Char] anchoredToFilePath (path, TreeType) = anchorPath "" path -- ++ "/" anchoredToFilePath (path, BlobType) = anchorPath "" path stripPathPrefix :: FilePath -> FilePath -> Maybe FilePath stripPathPrefix = stripPrefix . addSlash where addSlash [] = [] addSlash xs = xs ++ "/" -- | Turn an action that creates all possible completions into one -- that removes already given arguments. notYetListed :: [String] -> IO [String] -> IO [String] notYetListed already complete = do possible <- complete return $ possible \\ already darcs-2.14.5/src/Darcs/UI/Defaults.hs0000644000000000000000000002260307346545000015336 0ustar0000000000000000module Darcs.UI.Defaults ( applyDefaults ) where import Prelude () import Darcs.Prelude import Control.Monad.Writer import Data.Char ( isSpace ) import Data.Functor.Compose ( Compose(..) ) import Data.List ( nub ) import Data.Maybe ( catMaybes ) import qualified Data.Map as M import System.Console.GetOpt import Text.Regex.Applicative ( (<|>) , match, many, some , psym, anySym, string ) import Darcs.UI.Flags ( DarcsFlag ) import Darcs.UI.Options ( DarcsOptDescr ) import Darcs.UI.Commands ( DarcsCommand(..), commandAlloptions, extractAllCommands , WrappedCommand(..) ) import Darcs.UI.TheCommands ( commandControlList ) import Darcs.Util.Path ( AbsolutePath ) -- | Apply defaults from all sources to a list of 'DarcsFlag's (e.g. from the -- command line), given the command (and possibly super command) name, and a -- list of all options for the command. -- -- Sources for defaults are -- -- * the builtin (hard-coded) defaults, -- -- * the defaults file in the user's configuration, and -- -- * the defaults file in the current repository. -- -- Note that the pseudo command @ALL@ is allowed in defaults files to specify -- that an option should be the default for all commands to which it applies. -- -- The order of precedence for conflicting options (i.e. those belonging to -- same group of mutually exclusive options) is from less specific to more -- specific. In other words, options from the command line override all -- defaults, per-repo defaults override per-user defaults, which in turn -- override the built-in defaults. Inside the options from a defaults file, -- options for the given command override options for the @ALL@ pseudo command. -- -- Conflicting options at the same level of precedence are not allowed. -- -- Errors encountered during processing of command line or defaults flags -- are formatted and added as (separate) strings to the list of error messages -- that are returned together with the resulting flag list. applyDefaults :: Maybe String -> DarcsCommand pf -> AbsolutePath -> [String] -> [String] -> [DarcsFlag] -> ([DarcsFlag], [String]) applyDefaults msuper cmd cwd user repo flags = runWriter $ do cl_flags <- runChecks "Command line" check_opts flags user_defs <- get_flags "User defaults" user repo_defs <- get_flags "Repo defaults" repo return $ cl_flags ++ repo_defs ++ user_defs ++ builtin_defs where cmd_name = mkCmdName msuper (commandName cmd) builtin_defs = commandDefaults cmd check_opts = commandCheckOptions cmd opts = uncurry (++) $ commandAlloptions cmd get_flags source = parseDefaults source cwd cmd_name opts check_opts -- | Name of a normal command, or name of super and sub command. data CmdName = NormalCmd String | SuperCmd String String -- | Make a 'CmdName' from a possible super command name and a sub command name. mkCmdName :: Maybe String -> String -> CmdName mkCmdName Nothing cmd = NormalCmd cmd mkCmdName (Just super) sub = SuperCmd super sub -- | Turn a 'CmdName' into a 'String'. For a 'SuperCmd' concatenate with a space in between. showCmdName :: CmdName -> String showCmdName (SuperCmd super sub) = unwords [super,sub] showCmdName (NormalCmd name) = name runChecks :: String -> ([DarcsFlag] -> [String]) -> [DarcsFlag] -> Writer [String] [DarcsFlag] runChecks source check fs = do tell $ map ((source++": ")++) $ check fs return fs -- | Parse a list of lines from a defaults file, returning a list of 'DarcsFlag', -- given the current working directory, the command name, and a list of 'DarcsOption' -- for the command. -- -- In the result, defaults for the given command come first, then come defaults -- for @ALL@ commands. -- -- We check that matching options actually exist. -- -- * lines matching the command name: the option must exist in the command's -- option map. -- -- * lines matching @ALL@: there must be at least *some* darcs command with -- that option. -- -- It is debatable whether these checks are useful. On the one hand they can help -- detect typos in defaults files. On the other hand they make it difficult to -- use different versions of darcs in parallel: a default for an option that is -- only available in a later version will make the earlier version produce an -- error. Maybe reduce this to a warning? parseDefaults :: String -> AbsolutePath -> CmdName -> [DarcsOptDescr DarcsFlag] -> ([DarcsFlag] -> [String]) -> [String] -> Writer [String] [DarcsFlag] parseDefaults source cwd cmd opts check_opts def_lines = do cmd_flags <- flags_for (M.keys opt_map) cmd_defs >>= runChecks (source++" for command '"++showCmdName cmd++"'") check_opts all_flags <- flags_for allOptionSwitches all_defs >>= runChecks (source++" for ALL commands") check_opts return $ cmd_flags ++ all_flags where opt_map = optionMap opts cmd_defs = parseDefaultsLines cmd def_lines all_defs = parseDefaultsLines (NormalCmd "ALL") def_lines to_flag all_switches (switch,arg) = if switch `notElem` all_switches then do tell [source++": command '"++showCmdName cmd ++"' has no option '"++switch++"'."] return Nothing else mapErrors ((source++" for command '"++showCmdName cmd++"':"):) $ defaultToFlag cwd opt_map (switch,arg) -- the catMaybes filters out options that are not defined -- for this command flags_for all_switches = fmap catMaybes . mapM (to_flag all_switches) mapErrors f = mapWriter (\(r, es) -> (r, if null es then [] else f es)) -- | Result of parsing a defaults line: switch and argument(s). type Default = (String, String) -- | Extract 'Default's from lines of a defaults file that match the given 'CmdName'. -- -- The syntax is -- -- @ -- supercmd subcmd [--]switch [args...] -- @ -- -- for (super) commands with a sub command, and -- -- @ -- cmd default [--]default [args...] -- @ -- -- for normal commands (including the @ALL@ pseudo command). parseDefaultsLines :: CmdName -> [String] -> [Default] parseDefaultsLines cmd = catMaybes . map matchLine where matchLine = match $ (,) <$> (match_cmd cmd *> spaces *> opt_dashes *> word) <*> rest match_cmd (NormalCmd name) = string name match_cmd (SuperCmd super sub) = string super *> spaces *> string sub opt_dashes = string "--" <|> pure "" word = some $ psym (not.isSpace) spaces = some $ psym isSpace rest = spaces *> many anySym <|> pure "" {- $note This definition is a bit simpler, and doesn't need Text.Regex.Applicative, but it has two disadvantages over the one above: * Flag arguments are split and joined again with words/unwords, which means that whitespace inside an argument is not preserved literally. * It is less easily extendable with new syntax. > parseDefaultsLines :: CmdName -> [String] -> [(String, String)] > parseDefaultsLines name entries = case name of > SuperCmd super sub -> [ mk_def d as | (s:c:d:as) <- map words entries, s == super, c == sub ] > NormalCmd cmd -> [ mk_def d as | (c:d:as) <- map words entries, c == cmd ] > where > mk_def d as = (drop_dashes d, unwords as) > drop_dashes ('-':'-':switch) = switch > drop_dashes switch = switch -} -- | Search an option list for a switch. If found, apply the flag constructor -- from the option to the arg, if any. The first parameter is the current working -- directory, which, depending on the option type, may be needed to create a flag -- from an argument. -- -- Fails if (default has argument /= corresponding option has argument). defaultToFlag :: AbsolutePath -> OptionMap -> Default -> Writer [String] (Maybe DarcsFlag) defaultToFlag cwd opts (switch, arg) = case M.lookup switch opts of -- This case is not impossible! A default flag defined for ALL commands -- is not necessarily defined for the concrete command in question. Nothing -> return Nothing Just opt -> flag_from $ getArgDescr $ getCompose opt where getArgDescr (Option _ _ a _) = a flag_from (NoArg mkFlag) = do if not (null arg) then do tell ["'"++switch++"' takes no argument, but '"++arg++"' argument given."] return Nothing else return $ Just $ mkFlag cwd flag_from (OptArg mkFlag _) = return $ Just $ mkFlag (if null arg then Nothing else Just arg) cwd flag_from (ReqArg mkFlag _) = do if null arg then do tell ["'"++switch++"' requires an argument, but no "++"argument given."] return Nothing else return $ Just $ mkFlag arg cwd -- | Get all the longSwitches from a list of options. optionSwitches :: [DarcsOptDescr DarcsFlag] -> [String] optionSwitches = concatMap sel where sel (Compose (Option _ switches _ _)) = switches -- | A finite map from long switches to 'DarcsOptDescr's. type OptionMap = M.Map String (DarcsOptDescr DarcsFlag) -- | Build an 'OptionMap' from a list of 'DarcsOption's. optionMap :: [DarcsOptDescr DarcsFlag] -> OptionMap optionMap = M.fromList . concatMap sel where add_option opt switch = (switch, opt) sel o@(Compose (Option _ switches _ _)) = map (add_option o) switches -- | List of option switches of all commands (except help but that has no options). allOptionSwitches :: [String] allOptionSwitches = nub $ optionSwitches $ concatMap (\(WrappedCommand c) -> uncurry (++) . commandAlloptions $ c) $ extractAllCommands commandControlList darcs-2.14.5/src/Darcs/UI/Email.hs0000644000000000000000000002611307346545000014616 0ustar0000000000000000module Darcs.UI.Email ( makeEmail , readEmail , formatHeader -- just for testing , prop_qp_roundtrip ) where import Prelude () import Darcs.Prelude import Data.Char ( digitToInt, isHexDigit, ord, intToDigit, isPrint, toUpper ) import Data.List ( isInfixOf ) import Darcs.Util.Printer ( Doc, ($$), (<+>), text, empty, packedString, renderPS ) import Darcs.Util.ByteString ( packStringToUTF8, dropSpace, linesPS, betweenLinesPS ) import qualified Data.ByteString as B (ByteString, length, null, tail ,drop, head, concat, singleton ,pack, append, empty, unpack, snoc ) import qualified Data.ByteString.Char8 as BC (index, head, pack) import Data.ByteString.Internal as B (c2w, createAndTrim) import System.IO.Unsafe ( unsafePerformIO ) import Foreign.Ptr ( Ptr, plusPtr ) import Foreign.Storable ( poke ) import Data.Word ( Word8 ) import Data.Maybe ( fromMaybe ) -- lineMax is maximum number of characters in an e-mail line excluding the CRLF -- at the end. qlineMax is the number of characters in a q-encoded or -- quoted-printable-encoded line. lineMax, qlineMax :: Int lineMax = 78 qlineMax = 75 -- | Formats an e-mail header by encoding any non-ascii characters using UTF-8 -- and Q-encoding, and folding lines at appropriate points. It doesn't do -- more than that, so the header name and header value should be -- well-formatted give or take line length and encoding. So no non-ASCII -- characters within quoted-string, quoted-pair, or atom; no semantically -- meaningful signs in names; no non-ASCII characters in the header name; -- etcetera. formatHeader :: String -> String -> B.ByteString formatHeader headerName headerValue = B.append nameColon encodedValue where nameColon = B.pack (map B.c2w (headerName ++ ":")) -- space for folding encodedValue = foldAndEncode (' ':headerValue) (B.length nameColon) False False -- run through a string and encode non-ascii words and fold where appropriate. -- the integer argument is the current position in the current line. -- the string in the first argument must begin with whitespace, or be empty. foldAndEncode :: String -> Int -> Bool -> Bool -> B.ByteString foldAndEncode [] _ _ _ = B.empty foldAndEncode s p lastWordEncoded inMidWord = let newline = B.singleton 10 space = B.singleton 32 s2bs = B.pack . map B.c2w -- the twelve there is the max number of ASCII chars to encode a single -- character: 4 * 3, 4 UTF-8 bytes times 3 ASCII chars per byte safeEncChunkLength = (qlineMax - B.length encodedWordStart - B.length encodedWordEnd) `div` 12 (curSpace, afterCurSpace) = span (== ' ') s (curWord, afterCurWord) = break (== ' ') afterCurSpace qEncWord | lastWordEncoded = qEncode (curSpace ++ curWord) | otherwise = qEncode curWord mustEncode = inMidWord || any (\c -> not (isPrint c) || ord c > 127) curWord || length curWord > lineMax - 1 || isInfixOf "=?" curWord mustFold | mustEncode && lastWordEncoded = p + 1 + B.length qEncWord > lineMax | mustEncode = p + length curSpace + B.length qEncWord > lineMax | otherwise = p + length curSpace + length curWord > lineMax mustSplit = (B.length qEncWord > qlineMax && mustEncode) || length curWord > lineMax - 1 spaceToInsert | mustEncode && lastWordEncoded = space | otherwise = s2bs curSpace wordToInsert | mustEncode && mustSplit = qEncode (take safeEncChunkLength curWord) | mustEncode = qEncWord | otherwise = s2bs curWord doneChunk | mustFold = B.concat [newline, spaceToInsert, wordToInsert] | otherwise = B.concat [spaceToInsert, wordToInsert] (rest, nextP) | mustSplit = (drop safeEncChunkLength curWord ++ afterCurWord, qlineMax + 1) | mustEncode && mustFold = (afterCurWord, B.length spaceToInsert + B.length wordToInsert) | otherwise = (afterCurWord, p + B.length doneChunk) in B.append doneChunk (foldAndEncode rest nextP mustEncode mustSplit) -- | Turns a piece of string into a q-encoded block -- Applies q-encoding, for use in e-mail header values, as defined in RFC 2047. -- It just takes a string and builds an encoded-word from it, it does not check -- length or necessity. qEncode :: String -> B.ByteString qEncode s = B.concat [encodedWordStart, encodedString, encodedWordEnd] where encodedString = B.concat (map qEncodeChar s) encodedWordStart, encodedWordEnd :: B.ByteString encodedWordStart = B.pack (map B.c2w "=?UTF-8?Q?") encodedWordEnd = B.pack (map B.c2w "?=") -- turns a character into its q-encoded bytestring value. For most printable -- ASCII characters, that's just the singleton bytestring with that char. qEncodeChar :: Char -> B.ByteString qEncodeChar c | c == ' ' = c2bs '_' | isPrint c && c `notElem` "?=_" && ord c < 128 = c2bs c | otherwise = B.concat (map qbyte (B.unpack (packStringToUTF8 [c]))) where c2bs = B.singleton . B.c2w -- qbyte turns a byte into its q-encoded "=hh" representation qbyte b = B.pack (map B.c2w ['=' ,word8ToUDigit (b `div` 16) ,word8ToUDigit (b `mod` 16) ]) word8ToUDigit :: Word8 -> Char word8ToUDigit = toUpper . intToDigit . fromIntegral -- Encode a ByteString according to "Quoted Printable" defined by MIME -- (https://tools.ietf.org/html/rfc2045#section-6.7) qpencode :: B.ByteString -> B.ByteString qpencode s = unsafePerformIO -- Really only (3 + 2/75) * length or something in the worst case $ B.createAndTrim (4 * B.length s) (\buf -> encode s qlineMax buf 0) encode :: B.ByteString -> Int -> Ptr Word8 -> Int -> IO Int encode ps _ _ bufi | B.null ps = return bufi encode ps n buf bufi = case B.head ps of c | c == newline -> do poke (buf `plusPtr` bufi) newline encode ps' qlineMax buf (bufi+1) | n == 0 && B.length ps >= 1 -> do poke (buf `plusPtr` bufi) equals poke (buf `plusPtr` (bufi+1)) newline encode ps qlineMax buf (bufi + 2) | c == tab || c == space -> if B.null ps' || B.head ps' == newline then do poke (buf `plusPtr` bufi) c poke (buf `plusPtr` (bufi+1)) equals poke (buf `plusPtr` (bufi+2)) newline encode ps' qlineMax buf (bufi + 3) else do poke (buf `plusPtr` bufi) c encode ps' (n - 1) buf (bufi + 1) | c >= bang && c /= equals && c /= period && c <= tilde -> do poke (buf `plusPtr` bufi) c encode ps' (n - 1) buf (bufi + 1) | n < 3 -> encode ps 0 buf bufi | otherwise -> do let (x, y) = c `divMod` 16 h1 = intToUDigit x h2 = intToUDigit y poke (buf `plusPtr` bufi) equals poke (buf `plusPtr` (bufi+1)) h1 poke (buf `plusPtr` (bufi+2)) h2 encode ps' (n - 3) buf (bufi + 3) where ps' = B.tail ps newline = B.c2w '\n' tab = B.c2w '\t' space = B.c2w ' ' bang = B.c2w '!' tilde = B.c2w '~' equals = B.c2w '=' period = B.c2w '.' intToUDigit i | i >= 0 && i <= 9 = B.c2w '0' + i | i >= 10 && i <= 15 = B.c2w 'A' + i - 10 | otherwise = error $ "intToUDigit: '"++show i++"'not a digit" qpdecode :: B.ByteString -> B.ByteString qpdecode s = unsafePerformIO -- Add 1 as linesPS "\n" -> ["", ""] -> "\n\n" $ B.createAndTrim (B.length s + 1) (\buf -> decode (linesPS s) buf 0) decode :: [B.ByteString] -> Ptr Word8 -> Int -> IO Int decode [] _ bufi = return bufi decode (ps:pss) buf bufi | B.null (dropSpace ps) = do poke (buf `plusPtr` bufi) newline decode pss buf (bufi+1) | is_equals && B.length ps >= 3 && isHexDigit c1 && isHexDigit c2 = do poke (buf `plusPtr` bufi) (toWord8 $ digitToInt c1 * 16 + digitToInt c2) decode (B.drop 3 ps:pss) buf (bufi+1) | is_equals && B.null (dropSpace (B.tail ps)) = decode pss buf bufi | otherwise = do poke (buf `plusPtr` bufi) (B.head ps) decode (B.tail ps:pss) buf (bufi+1) where is_equals = BC.head ps == '=' c1 = BC.index ps 1 c2 = BC.index ps 2 newline = B.c2w '\n' toWord8 :: Int -> Word8 toWord8 = fromIntegral makeEmail :: String -> [(String, String)] -> Maybe Doc -> Maybe String -> Doc -> Maybe String -> Doc makeEmail repodir headers mcontents mcharset bundle mfilename = text "DarcsURL:" <+> text repodir $$ foldl (\m (h,v) -> m $$ (text (h ++ ":") <+> text v)) empty headers $$ text "MIME-Version: 1.0" $$ text "Content-Type: multipart/mixed; boundary=\"=_\"" $$ text "" $$ text "--=_" $$ (case mcontents of Just contents -> text ("Content-Type: text/plain; charset=\"" ++ fromMaybe "x-unknown" mcharset ++ "\"") $$ text "Content-Transfer-Encoding: quoted-printable" $$ text "" $$ packedString (qpencode (renderPS contents)) $$ text "" $$ text "--=_" Nothing -> empty) $$ text "Content-Type: text/x-darcs-patch; name=\"patch-preview.txt\"" $$ text "Content-Disposition: inline" $$ text "Content-Transfer-Encoding: quoted-printable" $$ text "Content-Description: Patch preview" $$ text "" $$ (case betweenLinesPS (BC.pack "New patches:") (BC.pack "Context:") (renderPS bundle) of Just s -> packedString $ qpencode s -- this should not happen, but in case it does, keep everything Nothing -> packedString $ qpencode $ renderPS bundle) $$ text "--=_" $$ text "Content-Type: application/x-darcs-patch" <> (case mfilename of Just filename -> text "; name=\"" <> text filename <> text "\"" Nothing -> empty) $$ text "Content-Transfer-Encoding: quoted-printable" $$ text "Content-Disposition: attachment" $$ text "Content-Description: A darcs patch for your repository!" $$ text "" $$ packedString (qpencode (renderPS bundle)) $$ text "--=_--" $$ text "" $$ text "." $$ text "" $$ text "" readEmail :: B.ByteString -> B.ByteString readEmail s = case betweenLinesPS (BC.pack "Content-Description: A darcs patch for your repository!") (BC.pack "--=_--") s of Nothing -> s -- if it wasn't an email in the first place, just pass along. Just s' -> qpdecode s' -- note: qpdecode appends an extra '\n' prop_qp_roundtrip :: B.ByteString -> Bool prop_qp_roundtrip s = B.snoc s 10 == (qpdecode . qpencode) s darcs-2.14.5/src/Darcs/UI/External.hs0000644000000000000000000005447007346545000015360 0ustar0000000000000000{-# LANGUAGE CPP, ForeignFunctionInterface #-} module Darcs.UI.External ( sendEmail , generateEmail , sendEmailDoc , resendEmail , signString , verifyPS , execDocPipe , execPipeIgnoreError , pipeDoc , pipeDocSSH , viewDoc , viewDocWith , haveSendmail , sendmailPath , diffProgram , darcsProgram , editText , editFile , catchall -- * Locales , setDarcsEncodings , getSystemEncoding , isUTF8Locale ) where import Prelude () import Darcs.Prelude import Darcs.Util.Text ( showCommandLine ) import Data.Maybe ( isJust, isNothing, maybeToList ) import Control.Monad ( unless, when, filterM, liftM2, void ) import GHC.MVar ( MVar ) import System.Exit ( ExitCode(..) ) import System.Environment ( getEnv , getExecutablePath ) import System.IO ( hPutStr, hPutStrLn, hClose, hIsTerminalDevice, stdout, stderr, Handle ) import System.Directory ( doesFileExist, findExecutable ) import System.FilePath.Posix ( () ) import System.Process ( createProcess, proc, CreateProcess(..), runInteractiveProcess, waitForProcess, StdStream(..) ) import System.Process.Internals ( ProcessHandle ) import GHC.IO.Encoding ( getFileSystemEncoding , setForeignEncoding , setLocaleEncoding ) import Foreign.C.String ( CString, peekCString ) import Control.Concurrent ( forkIO, newEmptyMVar, putMVar, takeMVar ) import Control.Exception ( try, finally, catch, IOException ) import System.IO.Error ( ioeGetErrorType ) import GHC.IO.Exception ( IOErrorType(ResourceVanished) ) import Data.Char ( toLower ) import Text.Regex #if defined (HAVE_MAPI) import Foreign.C ( withCString ) #endif #ifdef HAVE_MAPI import Foreign.Ptr ( nullPtr ) import Darcs.Util.Lock ( canonFilename, writeDocBinFile ) #endif import Darcs.Util.SignalHandler ( catchNonSignal ) import Darcs.UI.Options.All ( Sign(..), Verify(..), Compression(..) ) import Darcs.Util.Path ( AbsolutePath , toFilePath , FilePathLike ) import Darcs.Util.Progress ( withoutProgress, debugMessage ) import Darcs.Util.ByteString (linesPS, unlinesPS) import qualified Data.ByteString as B (ByteString, empty, null, readFile ,hGetContents, writeFile, hPut, length ,take, concat, drop, isPrefixOf, singleton, append) import qualified Data.ByteString.Char8 as BC (unpack, pack) import Darcs.Util.Lock ( withTemp , withNamedTemp , withOpenTemp ) import Darcs.Util.Ssh ( getSSH, SSHCmd(..) ) import Darcs.Util.CommandLine ( parseCmd, addUrlencoded ) import Darcs.Util.Exec ( execInteractive, exec, Redirect(..), withoutNonBlock ) import Darcs.Util.URL ( SshFilePath, sshUhost ) import Darcs.Util.Printer ( Doc, Printers, hPutDocLnWith, hPutDoc, hPutDocLn, hPutDocWith, ($$), renderPS, simplePrinters, hPutDocCompr, text, empty, packedString, vcat, renderString ) import qualified Darcs.Util.Ratified as Ratified import Darcs.UI.Email ( formatHeader ) sendmailPath :: IO String sendmailPath = do l <- filterM doesFileExist $ liftM2 () [ "/usr/sbin", "/sbin", "/usr/lib" ] [ "sendmail" ] ex <- findExecutable "sendmail" when (isNothing ex && null l) $ fail "Cannot find the \"sendmail\" program." return $ head $ maybeToList ex ++ l diffProgram :: IO String diffProgram = do l <- filterM (fmap isJust . findExecutable) [ "gdiff", "gnudiff", "diff" ] when (null l) $ fail "Cannot find the \"diff\" program." return $ head l -- |Get the name of the darcs executable (as supplied by @getExecutablePath@) darcsProgram :: IO String darcsProgram = getExecutablePath pipeDoc :: String -> [String] -> Doc -> IO ExitCode pipeDoc = pipeDocInternal (PipeToOther simplePrinters) data WhereToPipe = PipeToSsh Compression -- ^ if pipe to ssh, can choose to compress or not | PipeToOther Printers -- ^ otherwise, can specify printers pipeDocInternal :: WhereToPipe -> String -> [String] -> Doc -> IO ExitCode pipeDocInternal whereToPipe c args inp = withoutNonBlock $ withoutProgress $ do debugMessage $ "Exec: " ++ showCommandLine (c:args) (Just i,_,_,pid) <- createProcess (proc c args){ std_in = CreatePipe , delegate_ctlc = True} debugMessage "Start transferring data" case whereToPipe of PipeToSsh GzipCompression -> hPutDocCompr i inp PipeToSsh NoCompression -> hPutDoc i inp PipeToOther printers -> hPutDocWith printers i inp hClose i rval <- waitForProcess pid debugMessage "Finished transferring data" when (rval == ExitFailure 127) $ putStrLn $ "Command not found:\n "++ show (c:args) return rval pipeDocSSH :: Compression -> SshFilePath -> [String] -> Doc -> IO ExitCode pipeDocSSH compress remoteAddr args input = do (ssh, ssh_args) <- getSSH SSH pipeDocInternal (PipeToSsh compress) ssh (ssh_args ++ ("--":sshUhost remoteAddr:args)) input sendEmail :: String -> String -> String -> String -> String -> String -> IO () sendEmail f t s cc scmd body = sendEmailDoc f t s cc scmd Nothing (text body) generateEmail :: Handle -- ^ handle to write email to -> String -- ^ From -> String -- ^ To -> String -- ^ Subject -> String -- ^ CC -> Doc -- ^ body -> IO () generateEmail h f t s cc body = do putHeader "To" t putHeader "From" f putHeader "Subject" s unless (null cc) $ putHeader "Cc" cc putHeader "X-Mail-Originator" "Darcs Version Control System" hPutDocLn h body where putHeader field value = B.hPut h (B.append (formatHeader field value) newline) newline = B.singleton 10 haveSendmail :: IO Bool haveSendmail = (sendmailPath >> return True) `catch` (\(_ :: IOException) -> return False) -- | Send an email, optionally containing a patch bundle -- (more precisely, its description and the bundle itself) sendEmailDoc :: String -- ^ from -> String -- ^ to -> String -- ^ subject -> String -- ^ cc -> String -- ^ send command -> Maybe (Doc, Doc) -- ^ (content,bundle) -> Doc -- ^ body -> IO () sendEmailDoc _ "" _ "" _ _ _ = return () sendEmailDoc f "" s cc scmd mbundle body = sendEmailDoc f cc s "" scmd mbundle body sendEmailDoc f t s cc scmd mbundle body = do use_sendmail <- haveSendmail if use_sendmail || scmd /= "" then withOpenTemp $ \(h,fn) -> do generateEmail h f t s cc body hClose h withOpenTemp $ \(hat,at) -> do ftable' <- case mbundle of Just (content,bundle) -> do hPutDocLn hat bundle return [ ('b', renderString content) , ('a', at) ] Nothing -> return [ ('b', renderString body) ] hClose hat let ftable = [ ('t',addressOnly t),('c',cc),('f',f),('s',s) ] ++ ftable' r <- execSendmail ftable scmd fn when (r /= ExitSuccess) $ fail ("failed to send mail to: " ++ t ++ cc_list cc ++ "\nPerhaps sendmail is not configured.") #ifdef HAVE_MAPI else do r <- withCString t $ \tp -> withCString f $ \fp -> withCString cc $ \ccp -> withCString s $ \sp -> withOpenTemp $ \(h,fn) -> do hPutDoc h body hClose h writeDocBinFile "mailed_patch" body cfn <- canonFilename fn withCString cfn $ \pcfn -> c_send_email fp tp ccp sp nullPtr pcfn when (r /= 0) $ fail ("failed to send mail to: " ++ t) #else else fail "no mail facility (sendmail or mapi) located at configure time!" #endif where addressOnly a = case dropWhile (/= '<') a of ('<':a2) -> takeWhile (/= '>') a2 _ -> a cc_list [] = [] cc_list c = " and cc'ed " ++ c resendEmail :: String -> String -> B.ByteString -> IO () resendEmail "" _ _ = return () resendEmail t scmd body = do use_sendmail <- haveSendmail if use_sendmail || scmd /= "" then withOpenTemp $ \(h,fn) -> do hPutStrLn h $ "To: "++ t hPutStrLn h $ find_from (linesPS body) hPutStrLn h $ find_subject (linesPS body) hPutDocLn h $ fixit $ linesPS body hClose h let ftable = [('t',t)] r <- execSendmail ftable scmd fn when (r /= ExitSuccess) $ fail ("failed to send mail to: " ++ t) else #ifdef HAVE_MAPI fail "Don't know how to resend email with MAPI" #else fail "no mail facility (sendmail or mapi) located at configure time (use the sendmail-command option)!" #endif where br = BC.pack "\r" darcsurl = BC.pack "DarcsURL:" content = BC.pack "Content-" from_start = BC.pack "From:" subject_start = BC.pack "Subject:" fixit (l:ls) | B.null l = packedString B.empty $$ vcat (map packedString ls) | l == br = packedString B.empty $$ vcat (map packedString ls) | B.take 9 l == darcsurl || B.take 8 l == content = packedString l $$ fixit ls | otherwise = fixit ls fixit [] = empty find_from (l:ls) | B.take 5 l == from_start = BC.unpack l | otherwise = find_from ls find_from [] = "From: unknown" find_subject (l:ls) | B.take 8 l == subject_start = BC.unpack l | otherwise = find_subject ls find_subject [] = "Subject: (no subject)" execSendmail :: [(Char,String)] -> String -> String -> IO ExitCode execSendmail ftable scmd fn = if scmd == "" then do cmd <- sendmailPath exec cmd ["-i", "-t"] (File fn, Null, AsIs) else case parseCmd (addUrlencoded ftable) scmd of Right (arg0:opts, wantstdin) -> do let stdin = if wantstdin then File fn else Null exec arg0 opts (stdin, Null, AsIs) Left e -> fail $ "failed to send mail, invalid sendmail-command: "++show e _ -> fail "failed to send mail, invalid sendmail-command" #ifdef HAVE_MAPI foreign import ccall "win32/send_email.h send_email" c_send_email :: CString -> {- sender -} CString -> {- recipient -} CString -> {- cc -} CString -> {- subject -} CString -> {- body -} CString -> {- path -} IO Int #endif execPSPipe :: String -> [String] -> B.ByteString -> IO B.ByteString execPSPipe c args ps = fmap renderPS $ execDocPipe c args $ packedString ps execAndGetOutput :: FilePath -> [String] -> Doc -> IO (ProcessHandle, MVar (), B.ByteString) execAndGetOutput c args instr = do (i,o,e,pid) <- runInteractiveProcess c args Nothing Nothing _ <- forkIO $ hPutDoc i instr >> hClose i mvare <- newEmptyMVar _ <- forkIO ((Ratified.hGetContents e >>= -- ratify: immediately consumed hPutStr stderr) `finally` putMVar mvare ()) out <- B.hGetContents o return (pid, mvare, out) execDocPipe :: String -> [String] -> Doc -> IO Doc execDocPipe c args instr = withoutProgress $ do (pid, mvare, out) <- execAndGetOutput c args instr rval <- waitForProcess pid takeMVar mvare case rval of ExitFailure ec ->fail $ "External program '"++c++ "' failed with exit code "++ show ec ExitSuccess -> return $ packedString out -- The following is needed for diff, which returns non-zero whenever -- the files differ. execPipeIgnoreError :: String -> [String] -> Doc -> IO Doc execPipeIgnoreError c args instr = withoutProgress $ do (pid, mvare, out) <- execAndGetOutput c args instr _ <- waitForProcess pid takeMVar mvare return $ if B.null out then empty else packedString out signString :: Sign -> Doc -> IO Doc signString NoSign d = return d signString Sign d = signPGP [] d signString (SignAs keyid) d = signPGP ["--local-user", keyid] d signString (SignSSL idf) d = signSSL idf d signPGP :: [String] -> Doc -> IO Doc signPGP args = execDocPipe "gpg" ("--clearsign":args) signSSL :: String -> Doc -> IO Doc signSSL idfile t = withTemp $ \cert -> do opensslPS ["req", "-new", "-key", idfile, "-outform", "PEM", "-days", "365"] (BC.pack "\n\n\n\n\n\n\n\n\n\n\n") >>= opensslPS ["x509", "-req", "-extensions", "v3_ca", "-signkey", idfile, "-outform", "PEM", "-days", "365"] >>= opensslPS ["x509", "-outform", "PEM"] >>= B.writeFile cert opensslDoc ["smime", "-sign", "-signer", cert, "-inkey", idfile, "-noattr", "-text"] t where opensslDoc = execDocPipe "openssl" opensslPS = execPSPipe "openssl" verifyPS :: Verify -> B.ByteString -> IO (Maybe B.ByteString) verifyPS NoVerify ps = return $ Just ps verifyPS (VerifyKeyring pks) ps = verifyGPG pks ps verifyPS (VerifySSL auks) ps = verifySSL auks ps verifyGPG :: AbsolutePath -> B.ByteString -> IO (Maybe B.ByteString) verifyGPG goodkeys s = withOpenTemp $ \(th,tn) -> do B.hPut th s hClose th rval <- exec "gpg" ["--batch","--no-default-keyring", "--keyring",fix_path $ toFilePath goodkeys, "--verify"] (File tn, Null, Null) case rval of ExitSuccess -> return $ Just gpg_fixed_s _ -> return Nothing where gpg_fixed_s = let not_begin_signature x = x /= BC.pack "-----BEGIN PGP SIGNED MESSAGE-----" && x /= BC.pack "-----BEGIN PGP SIGNED MESSAGE-----\r" in unlinesPS $ map fix_line $ tail $ dropWhile not_begin_signature $ linesPS s fix_line x | B.length x < 3 = x | BC.pack "- -" `B.isPrefixOf` x = B.drop 2 x | otherwise = x #if defined(WIN32) fix_sep c | c=='/' = '\\' | otherwise = c fix_path p = map fix_sep p #else fix_path p = p #endif verifySSL :: AbsolutePath -> B.ByteString -> IO (Maybe B.ByteString) verifySSL goodkeys s = do certdata <- opensslPS ["smime", "-pk7out"] s >>= opensslPS ["pkcs7", "-print_certs"] cruddy_pk <- opensslPS ["x509", "-pubkey"] certdata let key_used = B.concat $ tail $ takeWhile (/= BC.pack"-----END PUBLIC KEY-----") $ linesPS cruddy_pk in do allowed_keys <- linesPS `fmap` B.readFile (toFilePath goodkeys) if key_used `notElem` allowed_keys then return Nothing -- Not an allowed key! else withTemp $ \cert -> withTemp $ \on -> withOpenTemp $ \(th,tn) -> do B.hPut th s hClose th B.writeFile cert certdata rval <- exec "openssl" ["smime", "-verify", "-CAfile", cert, "-certfile", cert] (File tn, File on, Null) case rval of ExitSuccess -> Just `fmap` B.readFile on _ -> return Nothing where opensslPS = execPSPipe "openssl" viewDoc :: Doc -> IO () viewDoc = viewDocWith simplePrinters viewDocWith :: Printers -> Doc -> IO () viewDocWith pr msg = do isTerminal <- hIsTerminalDevice stdout void $ if isTerminal && lengthGreaterThan (20 :: Int) (lines $ renderString msg) then do mbViewerPlusArgs <- getViewer case mbViewerPlusArgs of Just viewerPlusArgs -> do let (viewer : args) = words viewerPlusArgs pipeDocToPager viewer args pr msg Nothing -> return $ ExitFailure 127 -- No such command -- TEMPORARY passing the -K option should be removed as soon as -- we can use the delegate_ctrl_c feature in process `ortryrunning` pipeDocToPager "less" ["-RK"] pr msg `ortryrunning` pipeDocToPager "more" [] pr msg #ifdef WIN32 `ortryrunning` pipeDocToPager "more.com" [] pr msg #endif `ortryrunning` pipeDocToPager "" [] pr msg else pipeDocToPager "" [] pr msg where lengthGreaterThan n _ | n <= 0 = True lengthGreaterThan _ [] = False lengthGreaterThan n (_:xs) = lengthGreaterThan (n-1) xs getViewer :: IO (Maybe String) getViewer = Just `fmap` (getEnv "DARCS_PAGER" `catchall` getEnv "PAGER") `catchall` return Nothing pipeDocToPager :: String -> [String] -> Printers -> Doc -> IO ExitCode pipeDocToPager "" _ pr inp = do hPutDocLnWith pr stdout inp return ExitSuccess pipeDocToPager c args pr inp = pipeDocInternal (PipeToOther pr) c args inp -- | Given two shell commands as arguments, execute the former. The -- latter is then executed if the former failed because the executable -- wasn't found (code 127), wasn't executable (code 126) or some other -- exception occurred (save from a resource vanished/broken pipe error). -- Other failures (such as the user holding ^C) -- do not cause the second command to be tried. ortryrunning :: IO ExitCode -> IO ExitCode -> IO ExitCode a `ortryrunning` b = do ret <- try a case ret of (Right (ExitFailure 126)) -> b -- command not executable (Right (ExitFailure 127)) -> b -- command not found #ifdef WIN32 (Right (ExitFailure 9009)) -> b -- command not found by cmd.exe on Windows #endif (Right x) -> return x -- legitimate success/failure (Left (e :: IOException)) -> case ioeGetErrorType e of -- case where pager is quit before darcs has fed it entirely: ResourceVanished -> return ExitSuccess -- other exception: _ -> b editText :: String -> B.ByteString -> IO B.ByteString editText desc txt = withNamedTemp desc $ \f -> do B.writeFile f txt _ <- runEditor f B.readFile f -- | @editFile f@ lets the user edit a file which could but does not need to -- already exist. This function returns the exit code from the text editor and a -- flag indicating if the user made any changes. editFile :: FilePathLike p => p -> IO (ExitCode, Bool) editFile ff = do old_content <- file_content ec <- runEditor f new_content <- file_content return (ec, new_content /= old_content) where f = toFilePath ff file_content = do exists <- doesFileExist f if exists then do content <- B.readFile f return $ Just content else return Nothing runEditor :: FilePath -> IO ExitCode runEditor f = do ed <- getEditor execInteractive ed f `ortryrunning` execInteractive "vi" f `ortryrunning` execInteractive "emacs" f `ortryrunning` execInteractive "emacs -nw" f #ifdef WIN32 `ortryrunning` execInteractive "edit" f #endif getEditor :: IO String getEditor = getEnv "DARCS_EDITOR" `catchall` getEnv "VISUAL" `catchall` getEnv "EDITOR" `catchall` return "nano" catchall :: IO a -> IO a -> IO a a `catchall` b = a `catchNonSignal` (\_ -> b) -- | On Posix systems, GHC by default uses the user's locale encoding to -- determine how to decode/encode the raw byte sequences in the Posix API -- to/from 'String'. It also uses certain special variants of this -- encoding to determine how to handle encoding errors. -- -- See "GHC.IO.Encoding" for details. -- -- In particular, the default variant used for command line arguments and -- environment variables is //ROUNDTRIP, which means that /any/ byte sequence -- can be decoded and re-encoded w/o failure or loss of information. To -- enable this, GHC uses code points that are outside the range of the regular -- unicode set. This is what you get with 'getFileSystemEncoding'. -- -- We need to preserve the raw bytes e.g. for file names passed in by the -- user and also when reading file names from disk; also when re-generating -- files from patches, and when we display them to the user. -- -- So we want to use this encoding variant for *all* IO and for (almost) all -- conversions between raw bytes and 'String's. The encoding used for IO from -- and to handles is controlled by 'setLocaleEncoding' which we use here to -- make it equal to the //ROUNDTRIP variant. -- -- @setDarcsEncoding@ should be called before the -- first time any darcs operation is run, and again if anything else might have -- set those encodings to different values. -- -- Note that it isn't thread-safe and has a global effect on your program. -- -- On Windows, this function does (and should) not do anything. setDarcsEncodings :: IO () #ifdef WIN32 setDarcsEncodings = return () #else setDarcsEncodings = do e <- getFileSystemEncoding -- TODO check if we have to set this, too. setForeignEncoding e setLocaleEncoding e #endif -- The following functions are copied from the encoding package (BSD3 -- licence, by Henning Günther). -- | @getSystemEncoding@ fetches the current encoding from locale foreign import ccall "system_encoding.h get_system_encoding" get_system_encoding :: IO CString getSystemEncoding :: IO String getSystemEncoding = do enc <- get_system_encoding peekCString enc -- | @isUTF8@ checks if an encoding is UTF-8 (or ascii, since it is a -- subset of UTF-8). isUTF8Locale :: String -> Bool isUTF8Locale codeName = case normalizeEncoding codeName of -- ASCII "ascii" -> True "646" -> True "ansi_x3_4_1968" -> True "ansi_x3.4_1986" -> True "cp367" -> True "csascii" -> True "ibm367" -> True "iso646_us" -> True "iso_646.irv_1991" -> True "iso_ir_6" -> True "us" -> True "us_ascii" -> True -- UTF-8 "utf_8" -> True "u8" -> True "utf" -> True "utf8" -> True "utf8_ucs2" -> True "utf8_ucs4" -> True -- Everything else _ -> False where normalizeEncoding s = map toLower $ subRegex sep s "_" sep = mkRegex "[^0-9A-Za-z]+" darcs-2.14.5/src/Darcs/UI/Flags.hs0000644000000000000000000004355307346545000014632 0ustar0000000000000000-- Copyright (C) 2002-2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE OverloadedStrings #-} module Darcs.UI.Flags ( F.DarcsFlag -- FIXME these are temporary exceptions ( WorkRepoDir -- init , NewRepo -- convert, clone , UpToPattern -- clone --to-xxx -> -xxx hack , UpToPatch -- same , UpToHash -- same , OnePattern -- same , OnePatch -- same , OneHash -- same ) , remoteDarcs , diffingOpts , diffOpts , scanKnown , wantGuiPause , isInteractive , willRemoveLogFile , includeBoring , lookForAdds , lookForMoves , lookForReplaces , setDefault , allowConflicts , hasXmlOutput , hasLogfile , quiet , verbose , enumeratePatches , fixRemoteRepos , fixUrl , fixSubPaths , maybeFixSubPaths , getRepourl , getAuthor , promptAuthor , getEasyAuthor , getSendmailCmd , fileHelpAuthor , environmentHelpEmail , getSubject , getInReplyTo , getCc , environmentHelpSendmail , getOutput , getDate -- * Re-exports , O.compress , O.diffAlgorithm , O.reorder , O.minimize , O.editDescription , O.externalMerge , O.maxCount , O.matchAny , O.withContext , O.happyForwarding , O.allowCaseDifferingFilenames , O.allowWindowsReservedFilenames , O.changesReverse , O.usePacks , O.onlyToFiles , O.amendUnrecord , O.verbosity , O.useCache , O.useIndex , O.umask , O.dryRun , O.runTest , O.testChanges , O.setScriptsExecutable , O.withWorkingDir , O.leaveTestDir , O.remoteRepos , O.cloneKind , O.workRepo , O.patchIndexNo , O.patchIndexYes , O.xmlOutput , O.selectDeps , O.author , O.reply , O.patchFormat , O.charset , O.siblings , O.applyAs , O.enumPatches ) where import Prelude () import Darcs.Prelude import Data.List ( nub, intercalate ) import Data.Maybe ( isJust , maybeToList , isNothing , catMaybes ) import Control.Monad ( unless ) import System.Directory ( doesDirectoryExist, createDirectory ) import System.FilePath.Posix ( () ) import System.Environment ( lookupEnv ) import Darcs.UI.External ( catchall ) import qualified Darcs.UI.Options.Flags as F ( DarcsFlag( .. ) ) import Darcs.UI.Options.Core import qualified Darcs.UI.Options.All as O import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.Prompt ( askUser , askUserListItem ) import Darcs.Util.Lock ( writeTextFile ) import Darcs.Repository.Prefs ( getPreflist , getGlobal , globalPrefsDirDoc , globalPrefsDir ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.IsoDate ( getIsoDateTime, cleanLocalDate ) import Darcs.Util.Path ( AbsolutePath , AbsolutePathOrStd , SubPath , toFilePath , makeSubPathOf , ioAbsolute , makeAbsoluteOrStd ) import Darcs.Util.Printer ( putDocLn, ePutDocLn, text, ($$), (<+>) ) import Darcs.Util.URL ( isValidLocalPath ) import Darcs.Util.Text ( pathlist ) type Config = [F.DarcsFlag] verbose :: Config -> Bool verbose = (== O.Verbose) . parseFlags O.verbosity quiet :: Config -> Bool quiet = (== O.Quiet) . parseFlags O.verbosity remoteDarcs :: Config -> O.RemoteDarcs remoteDarcs = O.remoteDarcs . parseFlags O.network enumeratePatches :: Config -> Bool enumeratePatches = (== O.YesEnumPatches) . parseFlags O.enumPatches diffOpts :: O.UseIndex -> O.LookForAdds -> O.IncludeBoring -> O.DiffAlgorithm -> (O.UseIndex, O.ScanKnown, O.DiffAlgorithm) diffOpts use_index look_for_adds include_boring diff_alg = (use_index, scanKnown look_for_adds include_boring, diff_alg) -- | Non-trivial interaction between options. scanKnown :: O.LookForAdds -> O.IncludeBoring -> O.ScanKnown scanKnown O.NoLookForAdds _ = O.ScanKnown scanKnown O.YesLookForAdds O.NoIncludeBoring = O.ScanAll scanKnown O.YesLookForAdds O.YesIncludeBoring = O.ScanBoring diffingOpts :: Config -> (O.UseIndex, O.ScanKnown, O.DiffAlgorithm) diffingOpts flags = diffOpts (O.useIndex ? flags) (lookForAdds flags) (parseFlags O.includeBoring flags) (O.diffAlgorithm ? flags) -- | This will become dis-entangled as soon as we inline these functions. wantGuiPause :: Config -> O.WantGuiPause wantGuiPause fs = if (hasDiffCmd fs || hasExternalMerge fs) && hasPause fs then O.YesWantGuiPause else O.NoWantGuiPause where hasDiffCmd = isJust . O.diffCmd . parseFlags O.extDiff hasExternalMerge = (/= O.NoExternalMerge) . parseFlags O.externalMerge hasPause = (== O.YesWantGuiPause) . parseFlags O.pauseForGui -- | Non-trivial interaction between options. Explicit @-i@ or @-a@ dominates, -- else @--count@, @--xml@, or @--dry-run@ imply @-a@, else use the def argument. isInteractive :: Bool -> Config -> Bool isInteractive def = oparse (O.dryRunXml ^ O.changesFormat ^ O.interactive) decide where decide :: O.DryRun -> O.XmlOutput -> Maybe O.ChangesFormat -> Maybe Bool -> Bool decide _ _ _ (Just True) = True decide _ _ _ (Just False) = False decide _ _ (Just O.CountPatches) Nothing = False decide _ O.YesXml _ Nothing = False decide O.YesDryRun _ _ Nothing = False decide _ _ _ Nothing = def willRemoveLogFile :: Config -> Bool willRemoveLogFile = O._rmlogfile . parseFlags O.logfile includeBoring :: Config -> Bool includeBoring cfg = case parseFlags O.includeBoring cfg of O.NoIncludeBoring -> False O.YesIncludeBoring -> True lookForAdds :: Config -> O.LookForAdds lookForAdds = O.adds . parseFlags O.lookfor lookForReplaces :: Config -> O.LookForReplaces lookForReplaces = O.replaces . parseFlags O.lookfor lookForMoves :: Config -> O.LookForMoves lookForMoves = O.moves . parseFlags O.lookfor setDefault :: Bool -> Config -> O.SetDefault setDefault defYes = maybe def noDef . parseFlags O.setDefault where def = if defYes then O.YesSetDefault False else O.NoSetDefault False noDef yes = if yes then O.YesSetDefault True else O.NoSetDefault True allowConflicts :: Config -> O.AllowConflicts allowConflicts = maybe O.NoAllowConflicts id . parseFlags O.conflictsNo -- | Ugly. The alternative is to put the remoteRepos accessor into the IO monad, -- which is hardly better. fixRemoteRepos :: AbsolutePath -> Config -> IO Config fixRemoteRepos d = mapM fixRemoteRepo where fixRemoteRepo (F.RemoteRepo p) = F.RemoteRepo `fmap` fixUrl d p fixRemoteRepo f = return f -- | 'fixUrl' takes a String that may be a file path or a URL. -- It returns either the URL, or an absolute version of the path. fixUrl :: AbsolutePath -> String -> IO String fixUrl d f = if isValidLocalPath f then toFilePath `fmap` withCurrentDirectory d (ioAbsolute f) else return f -- | @maybeFixSubPaths (repo_path, orig_path) file_paths@ tries to turn -- @file_paths@ into 'SubPath's, taking into account the repository path and -- the original path from which darcs was invoked. -- -- A 'SubPath' is a path /under/ (or inside) the repo path. This does /not/ -- mean it must exist as a file or directory, nor that the path has been added -- to the repository; it merely means that it /could/ be added. -- -- When converting a relative path to an absolute one, this function first tries -- to interpret the relative path with respect to the current working directory. -- If that fails, it tries to interpret it with respect to the repository -- directory. Only when that fails does it put a @Nothing@ in the result at the -- position of the path that cannot be converted. -- -- It is intended for validating file arguments to darcs commands. maybeFixSubPaths :: (AbsolutePath, AbsolutePath) -> [FilePath] -> IO [Maybe SubPath] maybeFixSubPaths (r, o) fs = do fixedFs <- mapM fixit fs let bads = snd . unzip . filter (isNothing . fst) $ zip fixedFs fs unless (null bads) $ ePutDocLn $ text "Ignoring non-repository paths:" <+> pathlist bads return fixedFs where fixit p = do ap <- withCurrentDirectory o $ ioAbsolute p case makeSubPathOf r ap of Just sp -> return $ Just sp Nothing -> do absolutePathByRepodir <- withCurrentDirectory r $ ioAbsolute p return $ makeSubPathOf r absolutePathByRepodir -- | 'fixSubPaths' is a variant of 'maybeFixSubPaths' that throws out -- non-repository paths and duplicates from the result. See there for details. -- TODO: why filter out null paths from the input? why here and not in -- 'maybeFixSubPaths'? fixSubPaths :: (AbsolutePath, AbsolutePath) -> [FilePath] -> IO [SubPath] fixSubPaths fps fs = nub . catMaybes <$> maybeFixSubPaths fps (filter (not . null) fs) -- | 'getRepourl' takes a list of flags and returns the url of the -- repository specified by @Repodir \"directory\"@ in that list of flags, if any. -- This flag is present if darcs was invoked with @--repodir=DIRECTORY@ getRepourl :: Config -> Maybe String getRepourl fs = case parseFlags O.possiblyRemoteRepo fs of Nothing -> Nothing Just d -> if not (isValidLocalPath d) then Just d else Nothing fileHelpAuthor :: [String] fileHelpAuthor = [ "Each patch is attributed to its author, usually by email address (for", "example, `Fred Bloggs `). Darcs looks in several", "places for this author string: the `--author` option, the files", "`_darcs/prefs/author` (in the repository) and `" ++ globalPrefsDirDoc ++ "author` (in your", "home directory), and the environment variables `$DARCS_EMAIL` and", "`$EMAIL`. If none of those exist, Darcs will prompt you for an author", "string and write it to `" ++ globalPrefsDirDoc ++ "author`. Note that if you have more", "than one email address, you can put them all in `" ++ globalPrefsDirDoc ++ "author`,", "one author per line. Darcs will still prompt you for an author, but it", "allows you to select from the list, or to type in an alternative." ] environmentHelpEmail :: ([String], [String]) environmentHelpEmail = (["DARCS_EMAIL","EMAIL"], fileHelpAuthor) -- | 'getAuthor' takes a list of flags and returns the author of the -- change specified by @Author \"Leo Tolstoy\"@ in that list of flags, if any. -- Otherwise, if @Pipe@ is present, asks the user who is the author and -- returns the answer. If neither are present, try to guess the author, -- from repository or global preference files or environment variables, -- and if it's not possible, ask the user. getAuthor :: Maybe String -> Bool -> IO String getAuthor (Just author) _ = return author getAuthor Nothing pipe = if pipe then askUser "Who is the author? " else promptAuthor True False -- | 'promptAuthor' try to guess the author, from repository or -- global preference files or environment variables, and -- if it's not possible or alwaysAsk parameter is true, ask the user. -- If store parameter is true, the new author is added into -- @_darcs/prefs@. promptAuthor :: Bool -- Store the new author -> Bool -- Author selection even if already stored -> IO String promptAuthor store alwaysAsk = do as <- getEasyAuthor case as of [a] -> if alwaysAsk then askForAuthor False (fancyPrompt as) (fancyPrompt as) else return a [] -> askForAuthor True shortPrompt longPrompt _ -> askForAuthor False (fancyPrompt as) (fancyPrompt as) where shortPrompt = askUser "What is your email address? " longPrompt = askUser "What is your email address (e.g. Fred Bloggs )? " fancyPrompt xs = do putDocLn $ text "" $$ text "You have saved the following email addresses to your global settings:" str <- askUserListItem "Please select an email address for this repository: " (xs ++ ["Other"]) if str == "Other" then longPrompt else return str askForAuthor storeGlobal askfn1 askfn2 = do aminrepo <- doesDirectoryExist (darcsdir "prefs") if aminrepo && store then do prefsdir <- if storeGlobal then tryGlobalPrefsDir else return $ darcsdir "prefs" putDocLn $ text "Each patch is attributed to its author, usually by email address (for" $$ text "example, `Fred Bloggs '). Darcs could not determine" $$ text "your email address, so you will be prompted for it." $$ text "" $$ text ("Your address will be stored in " ++ prefsdir) if prefsdir /= darcsdir "prefs" then putDocLn $ text "It will be used for all patches you record in ALL repositories." $$ text ("If you move that file to " ++ darcsdir "prefs" "author" ++ ", it will") $$ text "be used for patches recorded in this repository only." else putDocLn $ text "It will be used for all patches you record in this repository only." $$ text ("If you move that file to " ++ globalPrefsDirDoc ++ "author, it will") $$ text "be used for all patches recorded in ALL repositories." add <- askfn1 writeTextFile (prefsdir "author") $ unlines ["# " ++ line | line <- fileHelpAuthor] ++ "\n" ++ add return add else askfn2 tryGlobalPrefsDir = do maybeprefsdir <- globalPrefsDir case maybeprefsdir of Nothing -> do putStrLn "WARNING: Global preference directory could not be found." return $ darcsdir "prefs" Just dir -> do exists <- doesDirectoryExist dir unless exists $ createDirectory dir return dir -- | 'getEasyAuthor' tries to get the author name first from the repository preferences, -- then from global preferences, then from environment variables. Returns @[]@ -- if it could not get it. Note that it may only return multiple possibilities when -- reading from global preferences getEasyAuthor :: IO [String] getEasyAuthor = firstNotNullIO [ (take 1 . nonblank) `fmap` getPreflist "author" , nonblank `fmap` getGlobal "author" , maybeToList `fmap` lookupEnv "DARCS_EMAIL" , maybeToList `fmap` lookupEnv "EMAIL" ] where nonblank = filter (not . null) -- this could perhaps be simplified with Control.Monad -- but note that we do NOT want to concatenate the results firstNotNullIO [] = return [] firstNotNullIO (e:es) = do v <- e `catchall` return [] if null v then firstNotNullIO es else return v getDate :: Bool -> IO String getDate hasPipe = if hasPipe then cleanLocalDate =<< askUser "What is the date? " else getIsoDateTime environmentHelpSendmail :: ([String], [String]) environmentHelpSendmail = (["SENDMAIL"], [ "On Unix, the `darcs send` command relies on sendmail(8). The", "`--sendmail-command` or $SENDMAIL environment variable can be used to", "provide an explicit path to this program; otherwise the standard", "locations /usr/sbin/sendmail and /usr/lib/sendmail will be tried."]) -- FIXME: mention the following also: -- * sendmail(8) is not sendmail-specific; -- * nowadays, desktops often have no MTA or an unconfigured MTA -- -- which is awful, because it accepts mail but doesn't relay it; -- * in this case, can be a sendmail(8)-emulating wrapper on top of an -- MUA that sends mail directly to a smarthost; and -- * on a multi-user system without an MTA and on which you haven't -- got root, can be msmtp. -- |'getSendmailCmd' takes a list of flags and returns the sendmail command -- to be used by @darcs send@. Looks for a command specified by -- @SendmailCmd \"command\"@ in that list of flags, if any. -- This flag is present if darcs was invoked with @--sendmail-command=COMMAND@ -- Alternatively the user can set @$S@@ENDMAIL@ which will be used as a fallback if present. getSendmailCmd :: Config -> IO String getSendmailCmd fs = case parseFlags O.sendmailCmd fs of Just cmd -> return cmd Nothing -> fmap (maybe "" id) $ lookupEnv "SENDMAIL" -- | Accessor for output option getOutput :: Config -> FilePath -> Maybe AbsolutePathOrStd getOutput fs fp = fmap go (parseFlags O.output fs) where go (O.Output ap) = ap go (O.OutputAutoName ap) = makeAbsoluteOrStd ap fp -- |'getSubject' takes a list of flags and returns the subject of the mail -- to be sent by @darcs send@. Looks for a subject specified by -- @Subject \"subject\"@ in that list of flags, if any. -- This flag is present if darcs was invoked with @--subject=SUBJECT@ getSubject :: Config -> Maybe String getSubject = O._subject . parseFlags O.headerFields -- |'getCc' takes a list of flags and returns the addresses to send a copy of -- the patch bundle to when using @darcs send@. -- looks for a cc address specified by @Cc \"address\"@ in that list of flags. -- Returns the addresses as a comma separated string. getCc :: Config -> String getCc = intercalate " , " . O._cc . parseFlags O.headerFields getInReplyTo :: Config -> Maybe String getInReplyTo = O._inReplyTo . parseFlags O.headerFields hasXmlOutput :: Config -> Bool hasXmlOutput = (== O.YesXml) . parseFlags O.xmlOutput hasLogfile :: Config -> Maybe AbsolutePath hasLogfile = O._logfile . parseFlags O.logfile darcs-2.14.5/src/Darcs/UI/Options.hs0000644000000000000000000000114207346545000015215 0ustar0000000000000000module Darcs.UI.Options ( module Darcs.UI.Options.Core , DarcsOption , PrimDarcsOption , DarcsOptDescr , optDescr ) where import Prelude () import Darcs.Prelude import Data.Functor.Compose ( getCompose ) import System.Console.GetOpt ( OptDescr ) import Darcs.UI.Options.All ( DarcsOption ) import Darcs.UI.Options.Core import Darcs.UI.Options.Util ( DarcsOptDescr, PrimDarcsOption ) import Darcs.Util.Path ( AbsolutePath ) -- | Instantiate a 'DarcsOptDescr' with an 'AbsolutePath' optDescr :: AbsolutePath -> DarcsOptDescr f -> OptDescr f optDescr path = fmap ($ path) . getCompose darcs-2.14.5/src/Darcs/UI/Options/0000755000000000000000000000000007346545000014663 5ustar0000000000000000darcs-2.14.5/src/Darcs/UI/Options/All.hs0000644000000000000000000013317407346545000015740 0ustar0000000000000000{-# LANGUAGE RecordWildCards #-} {- | All the concrete options. Notes: * The term \"option\" refers to a flag or combination of flags that together form a part of a command's configuration. Ideally, options should be orthogonal to each other, so we can freely combine them. * A primitive (indivisible) option has an associate value type. * An option named \"xyzActions\" represents a set of flags that act as mutually exclusive sub-commands. They typically have a dedicated value type named \"XyzAction\". * This module is probably best imported qualified. This is in contrast to the current practice of using subtly differing names to avoid name clashes for closely related items. For instance, the data constructors for an option's value type and the corresponding data constructors in 'F.DarcsFlag' may coincide. This is also why we import "Darcs.UI.Flags" qualified here. * When the new options system is finally in place, no code other than the one for constructing options should directly refer to 'F.DarcsFlag' constructors. -} module Darcs.UI.Options.All ( DarcsOption -- conversion to 'Bool' , YesNo (..) -- root , RootAction (..) , rootActions -- all commands , StdCmdAction (..) , stdCmdActions , debug , Verbosity (..) -- re-export , verbosity , timings , anyVerbosity , HooksConfig (..) -- re-export , HookConfig (..) -- re-export , preHook , postHook , hooks , UseCache (..) -- re-export , useCache -- interactivity , XmlOutput (..) , xmlOutput , DryRun (..) -- re-export , dryRun , dryRunXml , interactive , pipe , WantGuiPause (..) -- re-export , pauseForGui , askDeps -- patch selection , module Darcs.UI.Options.Matching -- re-export , SelectDeps (..) , selectDeps , changesReverse , maxCount -- local or remote repo(s) , WorkRepo (..) -- re-export , workRepo , repoDir , RemoteRepos (..) -- re-export , remoteRepos , possiblyRemoteRepo , reponame , NotInRemote (..) , notInRemote , notInRemoteFlagName , RepoCombinator (..) , repoCombinator , allowUnrelatedRepos , justThisRepo , WithWorkingDir (..) -- re-export , withWorkingDir , SetDefault (..) -- re-export , setDefault -- patch meta-data , patchname , author , AskLongComment (..) , askLongComment , keepDate , Logfile (..) , logfile -- looking for changes , LookFor (..) , LookForAdds (..) -- re-export , LookForMoves (..) -- re-export , LookForReplaces (..) -- re-export , lookfor , lookforadds , lookforreplaces , lookformoves -- files to consider , UseIndex (..) -- re-export , ScanKnown (..) -- re-export , IncludeBoring (..) , includeBoring , allowProblematicFilenames , allowCaseDifferingFilenames , allowWindowsReservedFilenames , onlyToFiles , useIndex , recursive -- differences , DiffAlgorithm (..) -- re-export , diffAlgorithm , WithContext (..) , withContext , ExternalDiff (..) , extDiff -- tests , TestChanges (..) , testChanges , RunTest (..) -- re-export , runTest , LeaveTestDir (..) -- re-export , leaveTestDir -- mail related , HeaderFields (..) , headerFields , sendToContext , sendmail , sendmailCmd , charset , editDescription , ccApply , reply , happyForwarding -- patch bundles , applyAs , Sign (..) , sign , Verify (..) , verify -- merging patches , AllowConflicts (..) -- re-export , conflictsNo , conflictsYes , ExternalMerge (..) -- re-export , externalMerge -- optimizations , Compression (..) -- re-export , compress , usePacks , WithPatchIndex (..) -- re-export , patchIndexNo , patchIndexYes , Reorder (..) -- re-export , reorder , minimize , storeInMemory -- miscellaneous , Output (..) , output , Summary (..) , summary , maybeSummary , RemoteDarcs (..) -- re-export , NetworkOptions (..) , network , UMask (..) -- re-export , umask , SetScriptsExecutable (..) -- re-export , setScriptsExecutable , restrictPaths -- command specific -- amend , amendUnrecord , selectAuthor -- annotate , machineReadable -- clone , CloneKind (..) , cloneKind -- dist , distname , distzip -- convert import/export, init , marks , readMarks , writeMarks , PatchFormat (..) , patchFormat , hashed -- log , ChangesFormat (..) , changesFormat -- replace , tokens , forceReplace -- test , TestStrategy (..) , testStrategy -- show files/index , files , directories , pending , nullFlag -- show repo , EnumPatches (..) , enumPatches -- gzcrcs , GzcrcsAction (..) , gzcrcsActions -- optimize , siblings , optimizePatchIndex ) where import Prelude () import Darcs.Prelude import Prelude hiding ( (^) ) import Data.Char ( isDigit ) import Data.List ( intercalate ) import Darcs.Repository.Flags ( Compression (..) , RemoteDarcs (..) , Reorder (..) , Verbosity (..) , UseCache (..) , UMask (..) , DryRun (..) , LookForAdds (..) , LookForMoves (..) , LookForReplaces (..) , DiffAlgorithm (..) , RunTest (..) , SetScriptsExecutable (..) , LeaveTestDir (..) , RemoteRepos (..) , SetDefault (..) , UseIndex (..) , ScanKnown (..) , CloneKind (..) , ExternalMerge (..) , WorkRepo (..) , AllowConflicts (..) , WantGuiPause (..) , WithPatchIndex (..) , WithWorkingDir (..) , PatchFormat (..) , IncludeBoring (..) , HooksConfig (..) , HookConfig (..) ) import qualified Darcs.UI.Options.Flags as F ( DarcsFlag(..) ) import Darcs.UI.Options.Core import Darcs.UI.Options.Iso import Darcs.UI.Options.Util import Darcs.UI.Options.Matching -- * Type instantiations -- | 'DarcsOption' instantiates the first two type parameters of 'OptSpec' to -- what we need in darcs. The first parameter is instantiated to -- The flag type is instantiate to 'Flag'. type DarcsOption = OptSpec DarcsOptDescr Flag type RawDarcsOption = forall v. v -> RawOptSpec Flag v -- * Conversion to 'Bool' class YesNo a where yes :: a -> Bool no :: a -> Bool no = not . yes instance YesNo Compression where yes NoCompression = False yes GzipCompression = True instance YesNo WithPatchIndex where yes NoPatchIndex = False yes YesPatchIndex = True instance YesNo Reorder where yes NoReorder = False yes Reorder = True instance YesNo UseCache where yes NoUseCache = False yes YesUseCache = True instance YesNo DryRun where yes NoDryRun = False yes YesDryRun = True instance YesNo LookForAdds where yes NoLookForAdds = False yes YesLookForAdds = True instance YesNo LookForReplaces where yes NoLookForReplaces = False yes YesLookForReplaces = True instance YesNo LookForMoves where yes NoLookForMoves = False yes YesLookForMoves = True instance YesNo IncludeBoring where yes NoIncludeBoring = False yes YesIncludeBoring = True instance YesNo RunTest where yes NoRunTest = False yes YesRunTest = True instance YesNo SetScriptsExecutable where yes NoSetScriptsExecutable = False yes YesSetScriptsExecutable = True instance YesNo LeaveTestDir where yes NoLeaveTestDir = False yes YesLeaveTestDir = True instance YesNo UseIndex where yes IgnoreIndex = False yes UseIndex = True instance YesNo WantGuiPause where yes NoWantGuiPause = False yes YesWantGuiPause = True instance YesNo WithWorkingDir where yes NoWorkingDir = False yes WithWorkingDir = True data EnumPatches = NoEnumPatches | YesEnumPatches deriving (Eq, Show) instance YesNo EnumPatches where yes NoEnumPatches = False yes YesEnumPatches = True -- * Root command -- | Options for darcs iself that act like sub-commands. data RootAction = RootHelp | Version | ExactVersion | ListCommands deriving (Eq, Show) rootActions :: PrimDarcsOption (Maybe RootAction) rootActions = withDefault Nothing [ RawNoArg ['h'] ["help"] F.Help (Just RootHelp) "show a brief description of all darcs commands and top-level options" , RawNoArg ['v','V'] ["version"] F.Version (Just Version) "show the darcs version" , RawNoArg [] ["exact-version"] F.ExactVersion (Just ExactVersion) "show the exact darcs version" -- the switch --commands is here for compatibility only , RawNoArg [] ["commands"] F.ListCommands (Just ListCommands) "show plain list of available options and commands, for auto-completion" ] -- * Common to all commands -- ** Standard command actions data StdCmdAction = Help | ListOptions | Disable deriving (Eq, Show) stdCmdActions :: PrimDarcsOption (Maybe StdCmdAction) stdCmdActions = withDefault Nothing [ RawNoArg [] ["help"] F.Help (Just Help) "show a brief description of the command and its options" , RawNoArg [] ["list-options"] F.ListOptions (Just ListOptions) "show plain list of available options and commands, for auto-completion" , RawNoArg [] ["disable"] F.Disable (Just Disable) "disable this command" ] -- ** Verbosity related debug :: PrimDarcsOption Bool debug = singleNoArg [] ["debug"] F.Debug "give only debug output" debugHttp :: PrimDarcsOption Bool debugHttp = singleNoArg [] ["debug-http"] F.DebugHTTP "debug output from libcurl" verbosity :: PrimDarcsOption Verbosity verbosity = withDefault NormalVerbosity [ RawNoArg ['q'] ["quiet"] F.Quiet Quiet "suppress informational output" , RawNoArg [] ["standard-verbosity"] F.NormalVerbosity NormalVerbosity "neither verbose nor quiet output" , RawNoArg ['v'] ["verbose"] F.Verbose Verbose "give verbose output" ] timings :: PrimDarcsOption Bool timings = singleNoArg [] ["timings"] F.Timings "provide debugging timings information" anyVerbosity :: DarcsOption a (Bool -> Bool -> Verbosity -> Bool -> a) anyVerbosity = debug ^ debugHttp ^ verbosity ^ timings where -- ** Hooks hooks :: DarcsOption a (HooksConfig -> a) hooks = imap (Iso fw bw) $ preHook ^ postHook where fw k (HooksConfig pr po) = k pr po bw k pr po = k (HooksConfig pr po) hookIso :: Iso (Maybe String -> Bool -> a) (HookConfig -> a) hookIso = (Iso fw bw) where fw k (HookConfig c p) = k c p bw k c p = k (HookConfig c p) preHook :: DarcsOption a (HookConfig -> a) preHook = imap hookIso $ prehookCmd ^ hookPrompt "prehook" F.AskPrehook F.RunPrehook postHook :: DarcsOption a (HookConfig -> a) postHook = imap hookIso $ posthookCmd ^ hookPrompt "posthook" F.AskPosthook F.RunPosthook prehookCmd :: PrimDarcsOption (Maybe String) prehookCmd = withDefault Nothing [ RawStrArg [] ["prehook"] F.PrehookCmd unF Just unV "COMMAND" "specify command to run before this darcs command" , RawNoArg [] ["no-prehook"] F.NoPrehook Nothing "don't run prehook command" ] where unF f = [ s | F.PrehookCmd s <- [f] ] unV v = [ s | Just s <- [v] ] posthookCmd :: PrimDarcsOption (Maybe String) posthookCmd = withDefault Nothing [ RawStrArg [] ["posthook"] F.PosthookCmd unF Just unV "COMMAND" "specify command to run after this darcs command" , RawNoArg [] ["no-posthook"] F.NoPosthook Nothing "don't run posthook command" ] where unF f = [ s | F.PosthookCmd s <- [f] ] unV v = [ s | Just s <- [v] ] hookPrompt :: String -> Flag -> Flag -> PrimDarcsOption Bool hookPrompt name fask frun = withDefault False [ RawNoArg [] ["prompt-"++name] fask True ("prompt before running "++name) , RawNoArg [] ["run-"++name] frun False ("run "++name++" command without prompting") ] -- ** Misc useCache :: PrimDarcsOption UseCache useCache = (imap . cps) (Iso fw bw) $ singleNoArg [] ["no-cache"] F.NoCache "don't use patch caches" where fw True = NoUseCache fw False = YesUseCache bw NoUseCache = True bw YesUseCache = False -- * Interactivity related {- TODO: these options interact (no pun intended) in complex ways that are very hard to figure out for users as well as maintainers. I think the only solution here is a more radical (and probably incompatible) re-design involving all interactivity related options. That is beyond the goals of this sub-project (which is already large enough). -} data XmlOutput = NoXml | YesXml deriving (Eq, Show) instance YesNo XmlOutput where yes NoXml = False yes YesXml = True xmlOutput :: PrimDarcsOption XmlOutput xmlOutput = withDefault NoXml [__xmloutput YesXml] __xmloutput :: RawDarcsOption __xmloutput val = RawNoArg [] ["xml-output"] F.XMLOutput val "generate XML formatted output" -- | TODO someone wrote here long ago that any time --dry-run is a possibility -- automated users should be able to examine the results more -- easily with --xml. See also issue2397. -- dryRun w/o xml is currently used in add, pull, and repair. dryRun :: PrimDarcsOption DryRun dryRun = withDefault NoDryRun [ RawNoArg [] ["dry-run"] F.DryRun YesDryRun "don't actually take the action" ] dryRunXml :: DarcsOption a (DryRun -> XmlOutput -> a) dryRunXml = dryRun ^ xmlOutput pipe :: PrimDarcsOption Bool pipe = singleNoArg [] ["pipe"] F.Pipe "ask user interactively for the patch metadata" interactive :: PrimDarcsOption (Maybe Bool) interactive = withDefault Nothing [ RawNoArg ['a'] ["all","no-interactive"] F.All (Just False) "answer yes to all patches" , RawNoArg ['i'] ["interactive"] F.Interactive (Just True) "prompt user interactively" ] pauseForGui :: PrimDarcsOption WantGuiPause pauseForGui = withDefault YesWantGuiPause [ RawNoArg [] ["pause-for-gui"] F.PauseForGui YesWantGuiPause "pause for an external diff or merge command to finish" , RawNoArg [] ["no-pause-for-gui"] F.NoPauseForGui NoWantGuiPause "return immediately after external diff or merge command finishes" ] askDeps :: PrimDarcsOption Bool askDeps = withDefault False [ RawNoArg [] ["ask-deps"] F.AskDeps True "manually select dependencies" , RawNoArg [] ["no-ask-deps"] F.NoAskDeps False "automatically select dependencies" ] -- * Patch selection related data SelectDeps = NoDeps | AutoDeps | PromptDeps deriving (Eq, Show) selectDeps :: PrimDarcsOption SelectDeps selectDeps = withDefault PromptDeps [ RawNoArg [] ["no-deps"] F.DontGrabDeps NoDeps "don't automatically fulfill dependencies" , RawNoArg [] ["auto-deps","dont-prompt-for-dependencies"] F.DontPromptForDependencies AutoDeps "don't ask about patches that are depended on by matched patches (with --match or --patch)" , RawNoArg [] ["prompt-deps","prompt-for-dependencies"] F.PromptForDependencies PromptDeps "prompt about patches that are depended on by matched patches" ] changesReverse :: PrimDarcsOption Bool changesReverse = withDefault False [ RawNoArg [] ["reverse"] F.Reverse True "show/consider changes in reverse order" , RawNoArg [] ["no-reverse"] F.Forward False "show/consider changes in the usual order" ] -- | TODO: Returning @-1@ if the argument cannot be parsed as an integer is -- not something I expected to find in a Haskell program. Instead, the flag -- should take either a plain 'String' argument (leaving it to a later stage -- to parse the 'String' to an 'Int'), or else a @'Maybe' 'Int'@, taking -- the possibility of a failed parse into account. maxCount :: PrimDarcsOption (Maybe Int) maxCount = (withDefault Nothing [ RawStrArg [] ["max-count"] F.MaxCount unF toV unV "NUMBER" "return only NUMBER results" ]) {ocheck=check} where unF f = [ s | F.MaxCount s <- [f] ] unV x = [ show s | Just s <- [x] ] toV s = if good s then Just (read s) else Nothing check fs = [ "invalid argument to --max-count: '"++s++"'" | s <- args, not (good s) ] ++ if length args > 1 then ["conflicting flags: " ++ intercalate ", " (map ("--max-count="++) args)] else [] where args = [ s | F.MaxCount s <- fs ] good s = not (null s) && all isDigit s -- * Local or remote repo workRepo :: PrimDarcsOption WorkRepo workRepo = imap (Iso fw bw) $ repoDir ^ possiblyRemoteRepo where fw k (WorkRepoDir s) = k (Just s) Nothing fw k (WorkRepoPossibleURL s) = k Nothing (Just s) fw k WorkRepoCurrentDir = k Nothing Nothing bw k (Just s) _ = k (WorkRepoDir s) bw k Nothing (Just s) = k (WorkRepoPossibleURL s) bw k Nothing Nothing = k WorkRepoCurrentDir repoDir :: PrimDarcsOption (Maybe String) repoDir = singleStrArg [] ["repodir"] F.WorkRepoDir arg "DIRECTORY" "specify the repository directory in which to run" where arg (F.WorkRepoDir s) = Just s arg _ = Nothing -- | @--repodir@ is there for compatibility, should be removed eventually -- -- IMHO the whole option can disappear; it overlaps with using an extra (non-option) -- argument, which is how e.g. @darcs get@ is usually invoked. reponame :: PrimDarcsOption (Maybe String) reponame = singleStrArg [] ["repo-name","repodir"] F.NewRepo arg "DIRECTORY" "path of output directory" where arg (F.NewRepo s) = Just s; arg _ = Nothing possiblyRemoteRepo :: PrimDarcsOption (Maybe String) possiblyRemoteRepo = singleStrArg [] ["repo"] F.WorkRepoUrl arg "URL" "specify the repository URL" where arg (F.WorkRepoUrl s) = Just s arg _ = Nothing remoteRepos :: PrimDarcsOption RemoteRepos remoteRepos = (imap . cps) (Iso fw bw) $ multiStrArg [] ["remote-repo"] F.RemoteRepo mkV "URL" "specify the remote repository URL to work with" where mkV fs = [ s | F.RemoteRepo s <- fs ] fw ss = RemoteRepos ss bw (RemoteRepos ss) = ss notInRemoteFlagName :: String notInRemoteFlagName = "not-in-remote" data NotInRemote = NotInDefaultRepo | NotInRemotePath String notInRemote :: PrimDarcsOption [NotInRemote] notInRemote = (imap . cps) (Iso (map fw) (map bw)) $ multiOptStrArg [] [notInRemoteFlagName] F.NotInRemote args "URL/PATH" $ "select all patches not in the default push/pull repository or at " ++ "location URL/PATH" where args fs = [s | F.NotInRemote s <- fs] fw (Just s) = NotInRemotePath s fw Nothing = NotInDefaultRepo bw (NotInRemotePath s) = Just s bw NotInDefaultRepo = Nothing data RepoCombinator = Intersection | Union | Complement deriving (Eq, Show) repoCombinator :: PrimDarcsOption RepoCombinator repoCombinator = withDefault Union [ RawNoArg [] ["intersection"] F.Intersection Intersection "take intersection of all repositories" , RawNoArg [] ["union"] F.Union Union "take union of all repositories" , RawNoArg [] ["complement"] F.Complement Complement "take complement of repositories (in order listed)" ] allowUnrelatedRepos :: PrimDarcsOption Bool allowUnrelatedRepos = singleNoArg [] ["ignore-unrelated-repos"] F.AllowUnrelatedRepos "do not check if repositories are unrelated" justThisRepo :: PrimDarcsOption Bool justThisRepo = singleNoArg [] ["just-this-repo"] F.JustThisRepo "Limit the check or repair to the current repo" -- | convert, clone, init withWorkingDir :: PrimDarcsOption WithWorkingDir withWorkingDir = withDefault WithWorkingDir [ RawNoArg [] ["with-working-dir"] F.UseWorkingDir WithWorkingDir "Create a working directory (normal repository)" , RawNoArg [] ["no-working-dir"] F.UseNoWorkingDir NoWorkingDir "Do not create a working directory (bare repository)" ] setDefault :: PrimDarcsOption (Maybe Bool) setDefault = withDefault Nothing [ RawNoArg [] ["set-default"] F.SetDefault (Just True) "set default repository" , RawNoArg [] ["no-set-default"] F.NoSetDefault (Just False) "don't set default repository" ] -- * Specifying patch meta-data patchname :: PrimDarcsOption (Maybe String) patchname = singleStrArg ['m'] ["name"] F.PatchName arg "PATCHNAME" "name of patch" where arg (F.PatchName s) = Just s arg _ = Nothing author :: PrimDarcsOption (Maybe String) author = singleStrArg ['A'] ["author"] F.Author arg "EMAIL" "specify author id" where arg (F.Author s) = Just s arg _ = Nothing data AskLongComment = NoEditLongComment | YesEditLongComment | PromptLongComment deriving (Eq, Show) -- TODO: fix non-default behavior askLongComment :: PrimDarcsOption (Maybe AskLongComment) askLongComment = withDefault Nothing [ RawNoArg [] ["edit-long-comment"] F.EditLongComment (Just YesEditLongComment) "edit the long comment by default" , RawNoArg [] ["skip-long-comment"] F.NoEditLongComment (Just NoEditLongComment) "don't give a long comment" , RawNoArg [] ["prompt-long-comment"] F.PromptLongComment (Just PromptLongComment) "prompt for whether to edit the long comment" ] keepDate :: PrimDarcsOption Bool keepDate = withDefault False [ RawNoArg [] ["keep-date"] F.KeepDate True "keep the date of the original patch" , RawNoArg [] ["no-keep-date"] F.NoKeepDate False "use the current date for the amended patch" ] -- record, send data Logfile = Logfile { _logfile :: Maybe AbsolutePath , _rmlogfile :: Bool } logfile :: PrimDarcsOption Logfile logfile = imap (Iso fw bw) (__logfile ^ __rmlogfile) where fw k (Logfile x y) = k x y bw k x y = k (Logfile x y) __logfile :: PrimDarcsOption (Maybe AbsolutePath) __logfile = singleAbsPathArg [] ["logfile"] F.LogFile arg "FILE" "give patch name and comment in file" where arg (F.LogFile s) = Just s arg _ = Nothing __rmlogfile :: PrimDarcsOption Bool __rmlogfile = withDefault False [ RawNoArg [] ["delete-logfile"] F.RmLogFile True "delete the logfile when done" , RawNoArg [] ["no-delete-logfile"] F.DontRmLogFile False "keep the logfile when done" ] -- * Looking for changes data LookFor = LookFor { adds :: LookForAdds , replaces :: LookForReplaces , moves :: LookForMoves } lookfor :: PrimDarcsOption LookFor lookfor = imap (Iso fw bw) (lookforadds NoLookForAdds ^ lookforreplaces ^ lookformoves) where fw k (LookFor a r m) = k a r m bw k a r m = k (LookFor a r m) lookforadds :: LookForAdds -> PrimDarcsOption LookForAdds lookforadds def = withDefault def [ RawNoArg ['l'] ["look-for-adds"] F.LookForAdds YesLookForAdds "look for (non-boring) files that could be added" , RawNoArg [] ["dont-look-for-adds","no-look-for-adds"] F.NoLookForAdds NoLookForAdds "don't look for any files that could be added" ] lookforreplaces :: PrimDarcsOption LookForReplaces lookforreplaces = withDefault NoLookForReplaces [ RawNoArg [] ["look-for-replaces"] F.LookForReplaces YesLookForReplaces "look for replaces that could be marked" , RawNoArg [] ["dont-look-for-replaces","no-look-for-replaces"] F.NoLookForReplaces NoLookForReplaces "don't look for any replaces" ] lookformoves :: PrimDarcsOption LookForMoves lookformoves = withDefault NoLookForMoves [ RawNoArg [] ["look-for-moves"] F.LookForMoves YesLookForMoves "look for files that may be moved/renamed" , RawNoArg [] ["dont-look-for-moves","no-look-for-moves"] F.NoLookForMoves NoLookForMoves "don't look for any files that could be moved/renamed" ] -- * Files to consider useIndex :: PrimDarcsOption UseIndex useIndex = (imap . cps) (Iso fw bw) ignoreTimes where fw False = UseIndex fw True = IgnoreIndex bw UseIndex = False bw IgnoreIndex = True includeBoring :: PrimDarcsOption IncludeBoring includeBoring = withDefault NoIncludeBoring [ RawNoArg [] ["boring"] F.Boring YesIncludeBoring "don't skip boring files" , RawNoArg [] ["no-boring"] F.SkipBoring NoIncludeBoring "skip boring files" ] allowProblematicFilenames :: DarcsOption a (Bool -> Bool -> a) allowProblematicFilenames = allowCaseDifferingFilenames ^ allowWindowsReservedFilenames allowCaseDifferingFilenames :: PrimDarcsOption Bool allowCaseDifferingFilenames = withDefault False [ RawNoArg [] ["case-ok"] F.AllowCaseOnly True "don't refuse to add files differing only in case" , RawNoArg [] ["no-case-ok"] F.DontAllowCaseOnly False "refuse to add files whose name differ only in case" ] allowWindowsReservedFilenames :: PrimDarcsOption Bool allowWindowsReservedFilenames = withDefault False [ RawNoArg [] ["reserved-ok"] F.AllowWindowsReserved True "don't refuse to add files with Windows-reserved names" , RawNoArg [] ["no-reserved-ok"] F.DontAllowWindowsReserved False "refuse to add files with Windows-reserved names" ] -- | TODO: see issue2395 onlyToFiles :: PrimDarcsOption Bool onlyToFiles = withDefault False [ RawNoArg [] ["only-to-files"] F.OnlyChangesToFiles True "show only changes to specified files" , RawNoArg [] ["no-only-to-files"] F.ChangesToAllFiles False "show changes to all files" ] ignoreTimes :: PrimDarcsOption Bool ignoreTimes = withDefault False [ RawNoArg [] ["ignore-times"] F.IgnoreTimes True "don't trust the file modification times" , RawNoArg [] ["no-ignore-times"] F.DontIgnoreTimes False "trust modification times to find modified files" ] recursive :: PrimDarcsOption Bool recursive = withDefault False [ RawNoArg ['r'] ["recursive"] F.Recursive True "recurse into subdirectories" , RawNoArg [] ["not-recursive","no-recursive"] F.NoRecursive False ("don't recurse into subdirectories") ] -- * Differences diffAlgorithm :: PrimDarcsOption DiffAlgorithm diffAlgorithm = withDefault PatienceDiff [ RawNoArg [] ["myers"] F.UseMyersDiff MyersDiff "use myers diff algorithm" , RawNoArg [] ["patience"] F.UsePatienceDiff PatienceDiff "use patience diff algorithm" ] data WithContext = NoContext | YesContext deriving (Eq, Show) instance YesNo WithContext where yes NoContext = False yes YesContext = True withContext :: PrimDarcsOption WithContext withContext = (imap . cps) (Iso fw bw) $ withDefault False [ RawNoArg ['u'] ["unified"] F.Unified True "output changes in a darcs-specific format similar to diff -u" , RawNoArg [] ["no-unified"] F.NonUnified False "output changes in darcs' usual format" ] where fw False = NoContext fw True = YesContext bw NoContext = False bw YesContext = True data ExternalDiff = ExternalDiff { diffCmd :: Maybe String , diffOpts :: [String] , diffUnified :: Bool } deriving (Eq, Show) extDiff :: PrimDarcsOption ExternalDiff extDiff = imap (Iso fw bw) $ __extDiffCmd ^ __extDiffOpts ^ __unidiff where fw k (ExternalDiff cmd opts uni) = k cmd opts uni bw k cmd opts uni = k (ExternalDiff cmd opts uni) __extDiffCmd :: PrimDarcsOption (Maybe String) __extDiffCmd = singleStrArg [] ["diff-command"] F.DiffCmd arg "COMMAND" "specify diff command (ignores --diff-opts)" where arg (F.DiffCmd s) = Just s arg _ = Nothing __extDiffOpts :: PrimDarcsOption [String] __extDiffOpts = multiStrArg [] ["diff-opts"] F.DiffFlags mkV "OPTIONS" "options to pass to diff" where mkV fs = [ s | F.DiffFlags s <- fs ] __unidiff :: PrimDarcsOption Bool __unidiff = withDefault True [ RawNoArg ['u'] ["unified"] F.Unified True "pass -u option to diff" , RawNoArg [] ["no-unified"] F.NonUnified False "output patch in diff's dumb format" ] -- * Runnign tests data TestChanges = NoTestChanges | YesTestChanges LeaveTestDir deriving (Eq) testChanges :: PrimDarcsOption TestChanges testChanges = imap (Iso fw bw) $ runTest ^ leaveTestDir where fw k NoTestChanges = k NoRunTest {- undefined -} YesLeaveTestDir fw k (YesTestChanges ltd) = k YesRunTest ltd bw k NoRunTest _ = k NoTestChanges bw k YesRunTest ltd = k (YesTestChanges ltd) runTest :: PrimDarcsOption RunTest runTest = withDefault NoRunTest [ RawNoArg [] ["test"] F.Test YesRunTest "run the test script" , RawNoArg [] ["no-test"] F.NoTest NoRunTest "don't run the test script" ] leaveTestDir :: PrimDarcsOption LeaveTestDir leaveTestDir = withDefault YesLeaveTestDir [ RawNoArg [] ["leave-test-directory"] F.LeaveTestDir YesLeaveTestDir "don't remove the test directory" , RawNoArg [] ["remove-test-directory"] F.NoLeaveTestDir NoLeaveTestDir "remove the test directory" ] -- * Mail related data HeaderFields = HeaderFields { _to, _cc :: [String] , _from, _subject, _inReplyTo :: Maybe String } headerFields :: PrimDarcsOption HeaderFields headerFields = imap (Iso fw bw) $ to ^ cc ^ from ^ subject ^ inReplyTo where fw k (HeaderFields t f c s i) = k t f c s i bw k t f c s i = k (HeaderFields t f c s i) from :: PrimDarcsOption (Maybe String) from = singleStrArg [] ["from"] F.Author arg "EMAIL" "specify email address" where arg (F.Author s) = Just s arg _ = Nothing to :: PrimDarcsOption [String] to = multiStrArg [] ["to"] F.To mkV "EMAIL" "specify destination email" where mkV fs = [ s | F.To s <- fs ] cc :: PrimDarcsOption [String] cc = multiStrArg [] ["cc"] F.Cc mkV "EMAIL" "mail results to additional EMAIL(s)" where mkV fs = [ s | F.Cc s <- fs ] subject :: PrimDarcsOption (Maybe String) subject = singleStrArg [] ["subject"] F.Subject arg "SUBJECT" "specify mail subject" where arg (F.Subject s) = Just s arg _ = Nothing inReplyTo :: PrimDarcsOption (Maybe String) inReplyTo = singleStrArg [] ["in-reply-to"] F.InReplyTo arg "EMAIL" "specify in-reply-to header" where arg (F.InReplyTo s) = Just s arg _ = Nothing sendToContext :: PrimDarcsOption (Maybe AbsolutePath) sendToContext = singleAbsPathArg [] ["context"] F.Context arg "FILENAME" "send to context stored in FILENAME" where arg (F.Context s) = Just s arg _ = Nothing -- TODO: do something about the nonsensical case (False, Just s) -- -- Some of the tests actually do this (pass --sendmail-command without -- passing --mail) and it's unclear if it's deliberate or just a historical -- accident after the issue2204 changes. We should untangle that and -- perhaps turn this into a single option with an optional argument. -- The other question to resolve is the interaction with the 'output' -- options to darcs send. sendmailIso :: Iso (Bool -> Maybe String -> a) ((Bool, Maybe String) -> a) sendmailIso = Iso uncurry curry sendmail :: PrimDarcsOption (Bool, Maybe String) sendmail = imap sendmailIso $ mail ^ sendmailCmd mail :: PrimDarcsOption Bool mail = singleNoArg [] ["mail"] F.Mail "send patch using sendmail" sendmailCmd :: PrimDarcsOption (Maybe String) sendmailCmd = singleStrArg [] ["sendmail-command"] F.SendmailCmd arg "COMMAND" "specify sendmail command" where arg (F.SendmailCmd s) = Just s arg _ = Nothing minimize :: PrimDarcsOption Bool minimize = withDefault True [ RawNoArg [] ["minimize"] F.Minimize True "minimize context of patch bundle" , RawNoArg [] ["no-minimize"] F.NoMinimize False ("don't minimize context of patch bundle") ] charset :: PrimDarcsOption (Maybe String) charset = singleStrArg [] ["charset"] F.Charset arg "CHARSET" "specify mail charset" where arg (F.Charset s) = Just s arg _ = Nothing editDescription :: PrimDarcsOption Bool editDescription = withDefault True [ RawNoArg [] ["edit-description"] F.EditDescription True "edit the patch bundle description" , RawNoArg [] ["dont-edit-description","no-edit-description"] F.NoEditDescription False "don't edit the patch bundle description" ] -- TODO: turn these two into a combined option ccApply :: PrimDarcsOption (Maybe String) ccApply = singleStrArg [] ["cc"] F.Cc arg "EMAIL" "mail results to additional EMAIL(s). Requires --reply" where arg (F.Cc s) = Just s arg _ = Nothing reply :: PrimDarcsOption (Maybe String) reply = singleStrArg [] ["reply"] F.Reply arg "FROM" "reply to email-based patch using FROM address" where arg (F.Reply s) = Just s arg _ = Nothing happyForwarding :: PrimDarcsOption Bool happyForwarding = withDefault False [ RawNoArg [] ["happy-forwarding"] F.HappyForwarding True "forward unsigned messages without extra header" , RawNoArg [] ["no-happy-forwarding"] F.NoHappyForwarding False "don't forward unsigned messages without extra header" ] -- * Patch bundle related applyAs :: PrimDarcsOption (Maybe String) applyAs = withDefault Nothing [ RawStrArg [] ["apply-as"] F.ApplyAs unF Just unV "USERNAME" "apply patch as another user using sudo" , RawNoArg [] ["no-apply-as"] F.NonApply Nothing "don't use sudo to apply as another user" ] where unF f = [ s | F.ApplyAs s <- [f] ] unV x = [ s | Just s <- [x] ] data Sign = NoSign | Sign | SignAs String | SignSSL String deriving (Eq, Show) sign :: PrimDarcsOption Sign sign = withDefault NoSign [ RawNoArg [] ["sign"] F.Sign Sign "sign the patch with your gpg key" , RawStrArg [] ["sign-as"] F.SignAs unFSignAs SignAs unSignAs "KEYID" "sign the patch with a given keyid" , RawStrArg [] ["sign-ssl"] F.SignSSL unFSignSSL SignSSL unSignSSL "IDFILE" "sign the patch using openssl with a given private key" , RawNoArg [] ["dont-sign","no-sign"] F.NoSign NoSign "don't sign the patch" ] where unFSignAs f = [ s | F.SignAs s <- [f] ] unSignAs v = [ s | SignAs s <- [v] ] unFSignSSL f = [ s | F.SignSSL s <- [f] ] unSignSSL v = [ s | SignSSL s <- [v] ] data Verify = NoVerify | VerifyKeyring AbsolutePath | VerifySSL AbsolutePath deriving (Eq, Show) verify :: PrimDarcsOption Verify verify = withDefault NoVerify [ RawAbsPathArg [] ["verify"] F.Verify unFKeyring VerifyKeyring unVKeyring "PUBRING" "verify that the patch was signed by a key in PUBRING" , RawAbsPathArg [] ["verify-ssl"] F.VerifySSL unFSSL VerifySSL unVSSL "KEYS" "verify using openSSL with authorized keys from file KEYS" , RawNoArg [] ["no-verify"] F.NonVerify NoVerify "don't verify patch signature" ] where unFKeyring f = [ s | F.Verify s <- [f] ] unVKeyring x = [ s | VerifyKeyring s <- [x] ] unFSSL f = [ s | F.VerifySSL s <- [f] ] unVSSL x = [ s | VerifySSL s <- [x] ] -- * Merging patches -- | push, apply, rebase apply: default to 'NoAllowConflicts' conflictsNo :: PrimDarcsOption (Maybe AllowConflicts) conflictsNo = conflicts NoAllowConflicts -- | pull, rebase pull: default to 'YesAllowConflictsAndMark' conflictsYes :: PrimDarcsOption (Maybe AllowConflicts) conflictsYes = conflicts YesAllowConflictsAndMark conflicts :: AllowConflicts -> PrimDarcsOption (Maybe AllowConflicts) conflicts def = withDefault (Just def) [ RawNoArg [] ["mark-conflicts"] F.MarkConflicts (Just YesAllowConflictsAndMark) "mark conflicts" , RawNoArg [] ["allow-conflicts"] F.AllowConflicts (Just YesAllowConflicts) "allow conflicts, but don't mark them" , RawNoArg [] ["dont-allow-conflicts","no-allow-conflicts","no-resolve-conflicts"] F.NoAllowConflicts (Just NoAllowConflicts) "fail if there are patches that would create conflicts" , RawNoArg [] ["skip-conflicts"] F.SkipConflicts Nothing "filter out any patches that would create conflicts" ] -- Technically not an isomorphism, see 'sendmailIso'. externalMerge :: PrimDarcsOption ExternalMerge externalMerge = imap (Iso fw bw) $ singleStrArg [] ["external-merge"] F.ExternalMerge arg "COMMAND" "use external tool to merge conflicts" where arg (F.ExternalMerge s) = Just s arg _ = Nothing bw k (Just s) = k (YesExternalMerge s) bw k Nothing = k NoExternalMerge fw k (YesExternalMerge s) = k (Just s) fw k NoExternalMerge = k Nothing -- * Optimizations compress :: PrimDarcsOption Compression compress = withDefault GzipCompression [ RawNoArg [] ["compress"] F.Compress GzipCompression "compress patch data" , RawNoArg [] ["dont-compress","no-compress"] F.NoCompress NoCompression "don't compress patch data" ] usePacks :: PrimDarcsOption Bool usePacks = withDefault True [ RawNoArg [] ["packs"] F.Packs True "use repository packs" , RawNoArg [] ["no-packs"] F.NoPacks False "don't use repository packs" ] -- for init, clone and convert: patch index disabled by default patchIndexNo :: PrimDarcsOption WithPatchIndex patchIndexNo = withDefault NoPatchIndex [__patchIndex YesPatchIndex, __noPatchIndex NoPatchIndex] -- for log and annotate: patch index enabled by default patchIndexYes :: PrimDarcsOption WithPatchIndex patchIndexYes = withDefault YesPatchIndex [__patchIndex YesPatchIndex, __noPatchIndex NoPatchIndex] __patchIndex, __noPatchIndex :: RawDarcsOption __patchIndex val = RawNoArg [] ["with-patch-index"] F.PatchIndexFlag val "build patch index" __noPatchIndex val = RawNoArg [] ["no-patch-index"] F.NoPatchIndexFlag val "don't build patch index" -- diff, dist storeInMemory :: PrimDarcsOption Bool storeInMemory = withDefault False [ RawNoArg [] ["store-in-memory"] F.StoreInMemory True "do patch application in memory rather than on disk" , RawNoArg [] ["no-store-in-memory"] F.ApplyOnDisk False "do patch application on disk" ] -- * Output data Output = Output AbsolutePathOrStd | OutputAutoName AbsolutePath deriving (Eq, Show) output :: PrimDarcsOption (Maybe Output) output = withDefault Nothing [ RawAbsPathOrStdArg ['o'] ["output"] F.Output unOutputF (Just . Output) unOutput "FILE" "specify output filename" , RawOptAbsPathArg ['O'] ["output-auto-name"] F.OutputAutoName unOutputAutoNameF (Just . OutputAutoName) unOutputAutoName "." "DIRECTORY" "output to automatically named file in DIRECTORY, default: current directory" ] where unOutputF f = [ p | F.Output p <- [f] ] unOutput (Just (Output p)) = [p] unOutput _ = [] unOutputAutoNameF f = [ p | F.OutputAutoName p <- [f] ] unOutputAutoName (Just (OutputAutoName p)) = [p] unOutputAutoName _ = [] -- * Miscellaneous data Summary = NoSummary | YesSummary deriving (Eq, Show) instance YesNo Summary where yes NoSummary = False yes YesSummary = True -- all commands except whatsnew summary :: PrimDarcsOption Summary summary = (imap . cps) (Iso fw bw) $ maybeSummary Nothing where fw Nothing = NoSummary fw (Just NoSummary) = NoSummary fw (Just YesSummary) = YesSummary bw NoSummary = Nothing bw YesSummary = Just YesSummary -- needed for whatsnew maybeSummary :: Maybe Summary -> PrimDarcsOption (Maybe Summary) maybeSummary def = withDefault def [ RawNoArg ['s'] ["summary"] F.Summary (Just YesSummary) "summarize changes" , RawNoArg [] ["no-summary"] F.NoSummary (Just NoSummary) "don't summarize changes" ] -- | TODO: reconsider this grouping of options data NetworkOptions = NetworkOptions { noHttpPipelining :: Bool , remoteDarcs :: RemoteDarcs } networkIso :: Iso (Bool -> Maybe String -> a) (NetworkOptions -> a) networkIso = Iso fw bw where fw k (NetworkOptions x (RemoteDarcs y)) = k x (Just y) fw k (NetworkOptions x DefaultRemoteDarcs) = k x Nothing bw k x (Just y) = k (NetworkOptions x (RemoteDarcs y)) bw k x Nothing = k (NetworkOptions x DefaultRemoteDarcs) network :: PrimDarcsOption NetworkOptions network = imap networkIso $ singleNoArg [] ["no-http-pipelining"] F.NoHTTPPipelining "disable HTTP pipelining" ^ singleStrArg [] ["remote-darcs"] F.RemoteDarcsOpt arg "COMMAND" "name of the darcs executable on the remote server" where arg (F.RemoteDarcsOpt s) = Just s arg _ = Nothing umask :: PrimDarcsOption UMask umask = (imap . cps) (Iso fw bw) $ singleStrArg [] ["umask"] F.UMask arg "UMASK" "specify umask to use when writing" where arg (F.UMask s) = Just s arg _ = Nothing fw (Just s) = YesUMask s fw Nothing = NoUMask bw (YesUMask s) = Just s bw NoUMask = Nothing setScriptsExecutable :: PrimDarcsOption SetScriptsExecutable setScriptsExecutable = withDefault NoSetScriptsExecutable [ RawNoArg [] ["set-scripts-executable"] F.SetScriptsExecutable YesSetScriptsExecutable "make scripts executable" , RawNoArg [] ["dont-set-scripts-executable","no-set-scripts-executable"] F.DontSetScriptsExecutable NoSetScriptsExecutable "don't make scripts executable" ] restrictPaths :: PrimDarcsOption Bool restrictPaths = withDefault True [ RawNoArg [] ["restrict-paths"] F.RestrictPaths True "don't allow darcs to touch external files or repo metadata" , RawNoArg [] ["dont-restrict-paths","no-restrict-paths"] F.DontRestrictPaths False "allow darcs to modify any file or directory (unsafe)" ] -- * Specific to a single command -- ** amend amendUnrecord :: PrimDarcsOption Bool amendUnrecord = withDefault False [ RawNoArg [] ["unrecord"] F.AmendUnrecord True "remove changes from the patch" , RawNoArg [] ["record"] F.NoAmendUnrecord False "add more changes to the patch" ] selectAuthor :: PrimDarcsOption Bool selectAuthor = singleNoArg [] ["select-author"] F.SelectAuthor "select author id from a menu" -- ** annotate machineReadable :: PrimDarcsOption Bool machineReadable = withDefault False [ __humanReadable False , __machineReadable True ] __humanReadable :: RawDarcsOption __humanReadable val = RawNoArg [] ["human-readable"] F.HumanReadable val "give human-readable output" __machineReadable :: RawDarcsOption __machineReadable val = RawNoArg [] ["machine-readable"] F.MachineReadable val "give machine-readable output" -- ** clone cloneKind :: PrimDarcsOption CloneKind cloneKind = withDefault NormalClone [ RawNoArg [] ["lazy"] F.Lazy LazyClone "get patch files only as needed" , RawNoArg [] ["complete"] F.Complete CompleteClone "get a complete copy of the repository" ] -- ** convert import/export marks :: DarcsOption a (Maybe String -> Maybe String -> a) marks = readMarks ^ writeMarks readMarks :: PrimDarcsOption (Maybe String) readMarks = singleStrArg [] ["read-marks"] F.ReadMarks arg "FILE" "continue conversion, previously checkpointed by --write-marks" where arg (F.ReadMarks s) = Just s arg _ = Nothing writeMarks :: PrimDarcsOption (Maybe String) writeMarks = singleStrArg [] ["write-marks"] F.WriteMarks arg "FILE" "checkpoint conversion to continue it later" where arg (F.WriteMarks s) = Just s arg _ = Nothing -- | Deprecated flag, still present to output an error message. hashed :: PrimDarcsOption () hashed = deprecated [ "All repositories are now \"hashed\", so this option was removed." , "Use --darcs-1 to get the effect that --hashed had previously." ] $ [ RawNoArg [] ["hashed"] F.Hashed () "deprecated, use --darcs-1 instead" ] patchFormat :: PrimDarcsOption PatchFormat patchFormat = withDefault PatchFormat2 [ RawNoArg [] ["darcs-2"] F.UseFormat2 PatchFormat2 "Standard darcs patch format" , RawNoArg [] ["darcs-1"] F.UseFormat1 PatchFormat1 "Older patch format (for compatibility)" ] -- ** dist distname :: PrimDarcsOption (Maybe String) distname = singleStrArg ['d'] ["dist-name"] F.DistName arg "DISTNAME" "name of version" where arg (F.DistName s) = Just s arg _ = Nothing distzip :: PrimDarcsOption Bool distzip = singleNoArg [] ["zip"] F.DistZip "generate zip archive instead of gzip'ed tar" -- ** log data ChangesFormat = HumanReadable | MachineReadable | GenContext | GenXml | NumberPatches | CountPatches deriving (Eq, Show) changesFormat :: PrimDarcsOption (Maybe ChangesFormat) changesFormat = withDefault Nothing [ RawNoArg [] ["context"] F.GenContext (Just GenContext) "give output suitable for clone --context" , __xmloutput (Just GenXml) , __humanReadable (Just HumanReadable) , __machineReadable (Just MachineReadable) , RawNoArg [] ["number"] F.NumberPatches (Just NumberPatches) "number the changes" , RawNoArg [] ["count"] F.Count (Just CountPatches) "output count of changes" ] -- ** replace tokens :: PrimDarcsOption (Maybe String) tokens = singleStrArg [] ["token-chars"] F.Toks arg "\"[CHARS]\"" "define token to contain these characters" where arg (F.Toks s) = Just s; arg _ = Nothing forceReplace :: PrimDarcsOption Bool forceReplace = withDefault False [ RawNoArg ['f'] ["force"] F.ForceReplace True "proceed with replace even if 'new' token already exists" , RawNoArg [] ["no-force"] F.NonForce False "don't force the replace if it looks scary" ] -- ** test data TestStrategy = Once | Linear | Backoff | Bisect deriving (Eq, Show) testStrategy :: PrimDarcsOption TestStrategy testStrategy = withDefault Once [ RawNoArg [] ["once"] F.Once Once "run test on current version only" , RawNoArg [] ["linear"] F.Linear Linear "locate the most recent version lacking an error" , RawNoArg [] ["backoff"] F.Backoff Backoff "exponential backoff search" , RawNoArg [] ["bisect"] F.Bisect Bisect "binary instead of linear search" ] -- ** show files files :: PrimDarcsOption Bool files = withDefault True [ RawNoArg [] ["files"] F.Files True "include files in output" , RawNoArg [] ["no-files"] F.NoFiles False "don't include files in output" ] directories :: PrimDarcsOption Bool directories = withDefault True [ RawNoArg [] ["directories"] F.Directories True "include directories in output" , RawNoArg [] ["no-directories"] F.NoDirectories False "don't include directories in output" ] pending :: PrimDarcsOption Bool pending = withDefault True [ RawNoArg [] ["pending"] F.Pending True "reflect pending patches in output" , RawNoArg [] ["no-pending"] F.NoPending False "only include recorded patches in output" ] -- "null" is already taken nullFlag :: PrimDarcsOption Bool nullFlag = singleNoArg ['0'] ["null"] F.NullFlag "separate file names by NUL characters" -- ** show repo enumPatches :: PrimDarcsOption EnumPatches enumPatches = withDefault YesEnumPatches [ RawNoArg [] ["enum-patches"] F.EnumPatches YesEnumPatches "include statistics requiring enumeration of patches" , RawNoArg [] ["no-enum-patches"] F.NoEnumPatches NoEnumPatches "don't include statistics requiring enumeration of patches" ] -- ** gzcrcs data GzcrcsAction = GzcrcsCheck | GzcrcsRepair deriving (Eq, Show) gzcrcsActions :: PrimDarcsOption (Maybe GzcrcsAction) gzcrcsActions = withDefault Nothing [ RawNoArg [] ["check"] F.Check (Just GzcrcsCheck) "Specify checking mode" , RawNoArg [] ["repair"] F.Repair (Just GzcrcsRepair) "Specify repair mode" ] -- ** optimize siblings :: PrimDarcsOption [AbsolutePath] siblings = multiAbsPathArg [] ["sibling"] F.Sibling mkV "DIRECTORY" "specify a sibling directory" where mkV fs = [ s | F.Sibling s <- fs ] reorder :: PrimDarcsOption Reorder reorder = withDefault NoReorder [ RawNoArg [] ["reorder-patches"] F.Reorder Reorder "reorder the patches in the repository" , RawNoArg [] ["no-reorder-patches"] F.NoReorder NoReorder "don't reorder the patches in the repository" ] optimizePatchIndex :: PrimDarcsOption (Maybe WithPatchIndex) optimizePatchIndex = withDefault Nothing [ __patchIndex (Just YesPatchIndex) , __noPatchIndex (Just NoPatchIndex) ] darcs-2.14.5/src/Darcs/UI/Options/Core.hs0000644000000000000000000002620207346545000016111 0ustar0000000000000000{-# LANGUAGE RecordWildCards #-} {-| Option specifications using continuations with a changing answer type. Based on @@ with additional inspiration provided by @@ which shows how the same format specifiers can be used for both @sprintf@ and @sscanf@. The 'OptSpec' type corresponds to the format specifiers for the sprintf and sscanf functions, which I called 'ounparse' and 'oparse' here; they no longer work on 'String's but instead on any list (the intention is, of course, that this is a list of flags). As explained in the original paper by Kenichi Asai, we cannot use 'Control.Monad.Trans.Cont.Cont', even with the recent additions of the @shift@ and @reset@ combinators, since 'Control.Monad.Trans.Cont.Cont' requires that the answer type remains the same over the whole computation, while the trick used here requires that the answer type can change. Besides parsing and unparsing, the 'OptSpec' type contains two more members: 'odesc' is the list of 'OptDescr' that 'System.Console.GetOpt.getOpt' needs as input for parsing the command line and for generating the usage help, while 'ocheck' takes a list of flags and returns a list of error messages, which can be used to check for conflicting options. -} module Darcs.UI.Options.Core where import Prelude () import Darcs.Prelude import Darcs.UI.Options.Iso -- * Option specifications {-| A type for option specifications. It consists of four components: a parser, an unparser, a checker, and a list of descriptions. The parser converts a flag list to some result value. This can never fail: we demand that primitive parsers are written so that there is always a default value (use 'Maybe' with default 'Nothing' as a last resort). The unparser does the opposite of the parser: a value is converted back to a flag list. The checker returns a list of error messages (which should be empty if there are no problems found). This can be used to e.g. check whether there are conflicting flags in the list. Separating the checker and parser is unusual. The reason for this is that we want to support flags coming from multiple sources, such as the command line or a defaults file. Prioritising these sources is done by concatenating the flag lists in the order of precedence, so that earlier flags win over later ones. That means that when parsing the (final) flag list, conflicting flags are resolved by picking the first flag that matches an option. The checker, on the other hand, can be called for each source separately. The last component is a list of descriptors for each single switch/flag that the option is made of. The 'OptSpec' type is heavily parameterized. The type arguments are: [@f@] The flag type, such as 'Darcs.UI.Flags.DarcsFlag'. [@d@] A type that describes an single flag, such as 'System.Console.GetOpt.OptDescr' or 'Darcs.UI.Options.DarcsOptDescr'. It should be a 'Data.Functor.Functor'. Abstracting over these types is not technically necessary: for the intended application in Darcs, we could as well fix them as @d='Darcs.UI.Options.DarcsOptDescr'@, and @f='Darcs.UI.Flags.DarcsFlag'@, saving two type parameters. However, doing that here would only obscure what's going on, making the code harder to understand, not easier. Besides, the resulting more general type signatures give us additional guarantees, known as \"free theorems\" (free as in beer, not in speak). In contrast, the type parameters [@a@, @b@] are necessary to make chaining of options a la typed printf/scanf possible. In a nutshell, @a@ is the result type of a function that consumes the result of parsing or unparsing an option, while @b@ is the complete type of such a function. The 'ounparse' and 'oparse' members use continuation passing style, which is the reason for their apparently \"inverted\" type signature. To understand them, it helps to look at the type of \"primitive\" (not yet combined) options (see 'PrimOptSpec' below). For a primitive option, @b@ gets instantiated to @v -> a@, where @v@ is the type of values associated with the option. The whole option spec then has type > o :: 'OptSpec' d f a (v -> a) so that the 'oparse' and 'ounparse' members are instantiated to > ounparse :: forall a. ([f] -> a) -> (x -> a) > oparse :: forall a. (x -> a) -> ([f] -> a) which can be easily seen to be equivalent to > ounparse :: x -> [f] > oparse :: [f] -> x Chaining such options results in a combined option of type > o1 ^ o2 ^ ... :: OptSpec d f a (v1 -> v2 -> ... -> a) that is, @b@ gets instantiated to > v1 -> v2 -> ... -> a To use such an option (primitive or combined), you pass in the consumer. A typical consumer of option values is a command implementation. Given > cmd :: v1 -> v2 -> ... -> [String] -> IO () we can parse the flags and pass the results to @cmd@: > oparse (o1 ^ o2 ^ ...) cmd flags -} data OptSpec d f a b = OptSpec { ounparse :: ([f] -> a) -> b -- ^ Convert option value (back) to flag list, in CPS. , oparse :: b -> ([f] -> a) -- ^ Convert flag list to option value, in CPS. Note: as a pure -- function, it is not supposed to fail. , ocheck :: [f] -> [String] -- ^ Check for erros in a flag list, returns error messages. , odesc :: [d f] -- ^ Descriptions, one for each flag that makes up the option. } -- ** Primitive combinators {- $category The type @'OptSpec' d f@, together with the operation '^' and the unit 'oid' forms a category. We could express this with an @ instance 'Control.Category.Category' ('OptSpec' d f) where 'Control.Category.id' = 'oid' ('Control.Category..') = ('^') @ I decided against doing that because I like the 'id' and '.' from the "Prelude". Proving the category laws is easy because the operation and unit are implemented independently for each component. This means @'OptSpec' d f@ is simply the product of four categories, reducing the problem to proving the laws for each component separately. ['odesc'] This is just list concatenation, which is a monoid, and every monoid is a category (by adding two phantom type arguments). ['ocheck'] Same here, noting that @([f] ->)@ is a monoid homomorphism (as expressed by the @instance 'Monoid' b => 'Monoid' (a -> b)@ in "Data.Monoid"). ['oparse'] This can be seen by flipping the arguments (which is a functor i.e. preserves category laws), so the type becomes @[f] -> b -> a@, and noting as before that @([f] ->)@ is a monoid homomorphism and thus a functor (by adding two phantom type arguments), reducing the operation to simple function composition. If this rather abstract argument doesn't convince you, do the calculations as an exercise. ['ounparse'] for this I don't have an easy abstract argument at hand, so I'll do the calculation: @ o1 ^ (o2 ^ o3) = definition outer (^) \k -> o1 (\f1 -> (o2 ^ o3) (\f23 -> k (f1 ++ f23))) = definition inner (^) \k -> o1 (\f1 -> (\k' -> o2 (\f2 -> o3 (\f3 -> k' (f2 ++ f3)))) (\f23 -> k (f1 ++ f23))) = beta reduce: f1 --> \f23 -> k (f1 ++ f23) \k -> o1 (\f1 -> (o2 (\f2 -> o3 (\f3 -> (\f23 -> k (f1 ++ f23)) (f2 ++ f3))))) = beta reduce: f23 --> f2 ++ f3 \k -> o1 (\f1 -> (o2 (\f2 -> o3 (\f3 -> (k (f1 ++ (f2 ++ f3))))))) @ and from the other side: @ (o1 ^ o2) ^ o3 = definition outer (^) \k -> (o1 ^ o2) (\f12 -> o3 (\f3 -> k (f12 ++ f3))) = definition inner (^) \k -> (\k' -> o1 (\f1 -> o2 (\f2 -> k' (f1 ++ f2)))) (\f12 -> o3 (\f3 -> k (f12 ++ f3))) = beta reduce: k' --> \f12 -> o3 (\f3 -> k (f12 ++ f3)) \k -> (o1 (\f1 -> o2 (\f2 -> (\f12 -> o3 (\f3 -> k (f12 ++ f3))) (f1 ++ f2)))) = beta reduce: f12 --> f1 ++ f2 \k -> (o1 (\f1 -> o2 (\f2 -> (o3 (\f3 -> k ((f1 ++ f2) ++ f3)))))) @ so again we have reduced the problem to the associativity of @('++')@. Left and right unit laws are left to the reader... -} -- | Identity 'OptSpec', unit for '^' oid :: OptSpec d f a a oid = OptSpec {..} where ounparse k = k [] oparse k _ = k ocheck _ = [] odesc = [] -- | 'OptSpec' composition, associative (^) :: OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c OptSpec ou1 op1 oc1 od1 ^ OptSpec ou2 op2 oc2 od2 = OptSpec {..} where ounparse k = ou1 (\fs1 -> ou2 (\fs2 -> k (fs1 ++ fs2))) oparse k fs = op2 (op1 k fs) fs ocheck fs = oc1 fs ++ oc2 fs odesc = od1 ++ od2 -- ** Derived combinators -- | Normalise a flag list by parsing and then unparsing it. This adds all -- implicit (default) flags to the list, which is useful as long as there is -- legacy code that circumvents the 'OptSpec' abstraction and directly tests -- for flag membership. -- -- prop> onormalise opts = (oparse opts . ounparse opts) id onormalise :: OptSpec d f [f] b -> [f] -> [f] onormalise opts = (oparse opts . ounparse opts) id -- | The list of default flags for an 'OptSpec'. -- -- prop> defaultFlags opts = onormalise opts [] defaultFlags :: OptSpec d f [f] b -> [f] defaultFlags opts = onormalise opts [] -- ** Lifting isomorphisms -- | Lift an isomorphism between @b@ and @c@ to one between -- @'OptSpec' d f a b@ and @'OptSpec' d f a c@. -- -- The forward component of the 'Iso' is needed for 'ounparse', the backward -- component for 'oparse'. For the other two components this is the identity. oimap :: Iso b c -> OptSpec d f a b -> OptSpec d f a c oimap (Iso fw bw) (OptSpec ou op oc od) = OptSpec {..} where ounparse k = fw (ou k) oparse k = op (bw k) ocheck = oc odesc = od instance IsoFunctor (OptSpec d f a) where imap = oimap -- * Primitive options -- | Type of primitive (not yet combined) options. The type parameter @b@ -- gets instantiated to @(v -> a)@, adding one argument of type @v@ -- to the answer type of the continuation. type PrimOptSpec d f a v = OptSpec d f a (v -> a) -- | Combine two list valued options of the same type \"in parellel\". This -- is done by concatenating the resulting option values ('oparse'), flags -- ('ounparse'), errors ('ocheck'), and descriptors ('odesc'), -- respectively, of the input options. oappend :: PrimOptSpec d f a [v] -> PrimOptSpec d f a [v] -> PrimOptSpec d f a [v] OptSpec ou1 op1 oc1 od1 `oappend` OptSpec ou2 op2 oc2 od2 = OptSpec {..} where ounparse k bs = ou1 (\fs1 -> ou2 (\fs2 -> k (fs1 ++ fs2)) bs) bs oparse k fs = op2 (\bs2 -> op1 (\bs1 -> k (bs1 ++ bs2)) fs) fs ocheck fs = oc1 fs ++ oc2 fs odesc = od1 ++ od2 -- | Unit for 'oappend'. oempty :: PrimOptSpec d f a [v] oempty = OptSpec {..} where ounparse k _ = k [] oparse k _ = k [] ocheck _ = [] odesc = [] instance Semigroup (PrimOptSpec d f a [v]) where (<>) = oappend -- | See 'oappend' and 'oempty'. instance Monoid (PrimOptSpec d f a [v]) where mappend = oappend mempty = oempty -- | Parse a list of flags against a primitive option spec, returning the -- value associated with the option. As noted above, this cannot fail because -- options always have a default value. -- -- prop> parseFlags o fs = oparse o id fs parseFlags :: (forall a. PrimOptSpec d f a v) -> [f] -> v parseFlags o fs = oparse o id fs -- no assoiativity, higher precedence than comparisons operators (4) -- and lower than arithemic operators (6,7,8) infix 5 ? -- | Operator version of 'parseFlags' -- -- prop> opt ? flags = parseFlags opt flags (?) :: (forall a. PrimOptSpec d f a v) -> [f] -> v (?) = parseFlags darcs-2.14.5/src/Darcs/UI/Options/Flags.hs0000644000000000000000000001125207346545000016254 0ustar0000000000000000-- |This module should only be imported by Darcs.UI.Options.* -- and by 'Darcs.UI.Flags'. Other modules needing access to 'DarcsFlag' -- should import 'Darcs.UI.Flags' module Darcs.UI.Options.Flags ( DarcsFlag(..) ) where import Prelude () import Darcs.Prelude import Darcs.Util.Path ( AbsolutePath, AbsolutePathOrStd ) -- | The 'DarcsFlag' type is a list of all flags that can ever be -- passed to darcs, or to one of its commands. data DarcsFlag = Version | ExactVersion | ListCommands | Help | ListOptions | NoTest | Test | OnlyChangesToFiles | ChangesToAllFiles | LeaveTestDir | NoLeaveTestDir | Timings | Debug | DebugHTTP | Verbose | NormalVerbosity | Quiet | To String | Cc String | Output AbsolutePathOrStd | OutputAutoName AbsolutePath | Mail | Subject String | InReplyTo String | Charset String | SendmailCmd String | Author String | SelectAuthor | PatchName String | OnePatch String | SeveralPatch String | OneHash String | AfterPatch String | UpToPatch String | AfterHash String | UpToHash String | TagName String | LastN Int | MaxCount String | PatchIndexRange Int Int | NumberPatches | OneTag String | AfterTag String | UpToTag String | GenContext | Context AbsolutePath | Count | LogFile AbsolutePath | RmLogFile | DontRmLogFile | DistName String | DistZip | All | Recursive | NoRecursive | Minimize | NoMinimize | Reorder | NoReorder | RestrictPaths | DontRestrictPaths | AskDeps | NoAskDeps | IgnoreTimes | DontIgnoreTimes | LookForAdds | NoLookForAdds | LookForMoves | NoLookForMoves | LookForReplaces | NoLookForReplaces | UseMyersDiff | UsePatienceDiff | Intersection | Union | Complement | Sign | SignAs String | NoSign | SignSSL String | HappyForwarding | NoHappyForwarding | Verify AbsolutePath | VerifySSL AbsolutePath | RemoteDarcsOpt String | EditDescription | NoEditDescription | Toks String | EditLongComment | NoEditLongComment | PromptLongComment | KeepDate | NoKeepDate | AllowConflicts | MarkConflicts | NoAllowConflicts | SkipConflicts | Boring | SkipBoring | AllowCaseOnly | DontAllowCaseOnly | AllowWindowsReserved | DontAllowWindowsReserved | DontGrabDeps | DontPromptForDependencies | PromptForDependencies | Compress | NoCompress | UnCompress | WorkRepoDir String | WorkRepoUrl String | RemoteRepo String | NewRepo String | NotInRemote (Maybe String) | Reply String | ApplyAs String | MachineReadable | HumanReadable | Pipe | Interactive | DiffCmd String | ExternalMerge String | Summary | NoSummary | PauseForGui | NoPauseForGui | Unified | NonUnified | Reverse | Forward | Complete | Lazy | DiffFlags String | XMLOutput | ForceReplace | OnePattern String | SeveralPattern String | AfterPattern String | UpToPattern String | NonApply | NonVerify | NonForce | DryRun | SetDefault | NoSetDefault | Disable | SetScriptsExecutable | DontSetScriptsExecutable | Once | Linear | Backoff | Bisect | Hashed -- deprecated flag, here to output an error message | UseFormat1 | UseFormat2 | UseNoWorkingDir | UseWorkingDir | Sibling AbsolutePath | Files | NoFiles | Directories | NoDirectories | Pending | NoPending | PosthookCmd String | NoPosthook | AskPosthook | RunPosthook | PrehookCmd String | NoPrehook | AskPrehook | RunPrehook | UMask String | StoreInMemory | ApplyOnDisk | NoHTTPPipelining | Packs | NoPacks | NoCache | AllowUnrelatedRepos | Check | Repair | JustThisRepo | ReadMarks String | WriteMarks String | NullFlag | NoAmendUnrecord | AmendUnrecord | PatchIndexFlag | NoPatchIndexFlag | EnumPatches | NoEnumPatches deriving ( Eq, Show ) darcs-2.14.5/src/Darcs/UI/Options/Iso.hs0000644000000000000000000000145607346545000015757 0ustar0000000000000000module Darcs.UI.Options.Iso where import Prelude () import Darcs.Prelude -- * Isomorphisms -- | Lightweight type ismomorphisms (a.k.a. invertible functions). If -- -- > Iso fw bw :: Iso a b -- -- then @fw@ and @bw@ are supposed to satisfy -- -- prop> fw . bw = id = bw . fw data Iso a b = Iso (a -> b) (b -> a) -- | Lift an isomorphism between @a@ and @b@ to one between @f a@ and @f b@. -- Like 'Functor', except we can only map invertible functions (i.e. an -- Isomorphisms). class IsoFunctor f where imap :: Iso a b -> f a -> f b -- | Apply an iso under a functor. under :: Functor f => Iso a b -> Iso (f a) (f b) under (Iso fw bw) = Iso (fmap fw) (fmap bw) -- | Apply an iso under cps (which is a cofunctor). cps :: Iso a b -> Iso (a -> c) (b -> c) cps (Iso fw bw) = Iso (\k -> k . bw) (\k -> k . fw) darcs-2.14.5/src/Darcs/UI/Options/Markdown.hs0000644000000000000000000000273407346545000017007 0ustar0000000000000000-- Support for @darcs help markdown@ module Darcs.UI.Options.Markdown ( optionsMarkdown ) where import Prelude () import Darcs.Prelude import Data.Functor.Compose ( Compose(..) ) import System.Console.GetOpt ( OptDescr(..), ArgDescr(..) ) import Darcs.UI.Options.Util ( DarcsOptDescr ) optionsMarkdown :: [DarcsOptDescr f] -> String optionsMarkdown opts = unlines [ "", unlines (map optionMarkdown opts), "
" ] optionMarkdown :: DarcsOptDescr f -> String optionMarkdown (Compose (Option a b (NoArg _) h)) = unlines [ "", "", showShortOptionsMd a, "" , "", showLongOptionsMd b , "" , "", h, "" , "" ] optionMarkdown (Compose (Option a b (ReqArg _ arg) h)) = unlines [ "", "", showShortOptionsMd a, "" , "", showLongOptionsMd (map (++(' ' : arg)) b), "" , "", h, "", "" ] optionMarkdown (Compose (Option a b (OptArg _ arg) h)) = unlines [ "", "", showShortOptionsMd a, "" , "", showLongOptionsMd (map (++("[="++arg++"]")) b), "" , "", h, "", "" ] showShortOptionsMd :: [Char] -> String showShortOptionsMd [] = "" showShortOptionsMd [c] = "`-"++[c]++"` " showShortOptionsMd (c:cs) = "`-"++[c]++"`,"++showShortOptionsMd cs showLongOptionsMd :: [String] -> String showLongOptionsMd [] = " " showLongOptionsMd [s] = "`--" ++ s ++ "` " showLongOptionsMd (s:ss) = "`--" ++ s ++ "`,"++ showLongOptionsMd ss darcs-2.14.5/src/Darcs/UI/Options/Matching.hs0000644000000000000000000002140207346545000016750 0ustar0000000000000000{-# LANGUAGE RecordWildCards #-} {-| Patch matching options. These are all of the same type 'MatchOption' defined below. Multiple flags per option are allowed and do not raise a conflict error. This is how Darcs currently operates, even though I suspect that it ignores all but the first 'MatchFlag' (since it does so for many other options). Given a suitable semantics (and documentation thereof), for instance \"all the given patterns must match\", this could be turned into a useful feature. -} module Darcs.UI.Options.Matching ( MatchFlag(..) -- re-export , matchUpToOne , matchOneContext , matchOneNontag , matchSeveral , matchSeveralOrFirst , matchSeveralOrLast , matchRange , matchSeveralOrRange -- * exported for for checking , context , matchLast , matchFrom , matchAny -- temporary hack ) where import Prelude () import Darcs.Prelude hiding ( last ) import Data.Char ( isDigit ) import Darcs.Patch.Match ( MatchFlag(..) ) import qualified Darcs.UI.Options.Flags as F ( DarcsFlag(..) ) import Darcs.UI.Options.Core import Darcs.UI.Options.Util -- * Type instantiations type MatchOption = PrimDarcsOption [MatchFlag] -- * Combined matching options matchUpToOne :: MatchOption -- ^ show files/contents, dist, annotate matchUpToOne = mconcat [match, patch, hash, tag, index] -- | Used by: clone matchOneContext :: MatchOption matchOneContext = mconcat [toMatch, toPatch, toHash, tag, context] -- [NOTE --index removed from matchOneNontag because issue1926] -- The --index option was removed for 2.5 release because it isn't handled -- by amend-record (see issue1926). -- -- At this moment, amend-record is the only command that uses 'matchOneNontag', -- so there is no other command affected. -- | Used by: amend matchOneNontag :: MatchOption matchOneNontag = match <> patch <> hash -- | Used by: rebase pull/apply, send, push, pull, apply, fetch matchSeveral :: MatchOption matchSeveral = matches <> patches <> tags <> hash matchLast :: MatchOption matchLast = last -- | Used by: rebase unsuspend/reify matchSeveralOrFirst :: MatchOption matchSeveralOrFirst = mconcat [ matchTo, last, matches, patches, tags, hash ] -- | Used by: unrecord, obliterate, rebase suspend, rollback matchSeveralOrLast :: MatchOption matchSeveralOrLast = mconcat [ matchFrom, last, matches, patches, tags, hash ] -- | Used by: diff matchRange :: MatchOption matchRange = mconcat [ matchTo, matchFrom, match, patch, hash, last, indexes ] -- | Used by: log matchSeveralOrRange :: MatchOption matchSeveralOrRange = mconcat [ matchTo, matchFrom, last, indexes, matches, patches, tags, hash ] matchTo :: MatchOption matchTo = toMatch <> toPatch <> toHash <> toTag matchFrom :: MatchOption matchFrom = fromMatch <> fromPatch <> fromHash <> fromTag matchAny :: MatchOption matchAny = mconcat [ toMatch, toPatch, toHash, toTag, fromMatch, fromPatch, fromHash, fromTag, tag, tags, patch, patches, hash, match, matches, index, indexes, context, last ] -- * Primitive matching options toMatch, toPatch, toHash, toTag, fromMatch, fromPatch, fromHash, fromTag, tag, tags, patch, patches, hash, match, matches, index, indexes, context, last :: MatchOption toMatch = OptSpec {..} where ounparse k mfs = k [ F.UpToPattern s | UpToPattern s <- mfs ] oparse k fs = k [ UpToPattern s | F.UpToPattern s <- fs ] ocheck _ = [] odesc = [ strArg [] ["to-match"] F.UpToPattern "PATTERN" "select changes up to a patch matching PATTERN" ] toPatch = OptSpec {..} where ounparse k mfs = k [ F.UpToPatch s | UpToPatch s <- mfs ] oparse k fs = k [ UpToPatch s | F.UpToPatch s <- fs ] ocheck _ = [] odesc = [ strArg [] ["to-patch"] F.UpToPatch "REGEXP" "select changes up to a patch matching REGEXP" ] toHash = OptSpec {..} where ounparse k mfs = k [ F.UpToHash s | UpToHash s <- mfs ] oparse k fs = k [ UpToHash s | F.UpToHash s <- fs ] ocheck _ = [] odesc = [ strArg [] ["to-hash"] F.UpToHash "HASH" "select changes up to a patch with HASH" ] context = OptSpec {..} where ounparse k mfs = k [ F.Context p | Context p <- mfs ] oparse k fs = k [ Context p | F.Context p <- fs ] ocheck _ = [] odesc = [ absPathArg [] ["context"] F.Context "FILENAME" "version specified by the context in FILENAME" ] toTag = OptSpec {..} where ounparse k mfs = k [ F.UpToTag s | UpToTag s <- mfs ] oparse k fs = k [ UpToTag s | F.UpToTag s <- fs ] ocheck _ = [] odesc = [ strArg [] ["to-tag"] F.UpToTag "REGEXP" "select changes up to a tag matching REGEXP" ] fromMatch = OptSpec {..} where ounparse k mfs = k [ F.AfterPattern s | AfterPattern s <- mfs ] oparse k fs = k [ AfterPattern s | F.AfterPattern s <- fs ] ocheck _ = [] odesc = [ strArg [] ["from-match"] F.AfterPattern "PATTERN" "select changes starting with a patch matching PATTERN" ] fromPatch = OptSpec {..} where ounparse k mfs = k [ F.AfterPatch s | AfterPatch s <- mfs ] oparse k fs = k [ AfterPatch s | F.AfterPatch s <- fs ] ocheck _ = [] odesc = [ strArg [] ["from-patch"] F.AfterPatch "REGEXP" "select changes starting with a patch matching REGEXP" ] fromHash = OptSpec {..} where ounparse k mfs = k [ F.AfterHash s | AfterHash s <- mfs ] oparse k fs = k [ AfterHash s | F.AfterHash s <- fs ] ocheck _ = [] odesc = [ strArg [] ["from-hash"] F.AfterHash "HASH" "select changes starting with a patch with HASH" ] fromTag = OptSpec {..} where ounparse k mfs = k [ F.AfterTag s | AfterTag s <- mfs ] oparse k fs = k [ AfterTag s | F.AfterTag s <- fs ] ocheck _ = [] odesc = [ strArg [] ["from-tag"] F.AfterTag "REGEXP" "select changes starting with a tag matching REGEXP" ] tag = OptSpec {..} where ounparse k mfs = k [ F.OneTag s | OneTag s <- mfs ] oparse k fs = k [ OneTag s | F.OneTag s <- fs ] ocheck _ = [] odesc = [ strArg ['t'] ["tag"] F.OneTag "REGEXP" "select tag matching REGEXP" ] tags = OptSpec {..} where ounparse k mfs = k [ F.OneTag s | OneTag s <- mfs ] oparse k fs = k [ OneTag s | F.OneTag s <- fs ] ocheck _ = [] odesc = [ strArg ['t'] ["tags"] F.OneTag "REGEXP" "select tags matching REGEXP" ] patch = OptSpec {..} where ounparse k mfs = k [ F.OnePatch s | OnePatch s <- mfs ] oparse k fs = k [ OnePatch s | F.OnePatch s <- fs ] ocheck _ = [] odesc = [ strArg ['p'] ["patch"] F.OnePatch "REGEXP" "select a single patch matching REGEXP" ] patches = OptSpec {..} where ounparse k mfs = k [ F.SeveralPatch s | SeveralPatch s <- mfs ] oparse k fs = k [ SeveralPatch s | F.SeveralPatch s <- fs ] ocheck _ = [] odesc = [ strArg ['p'] ["patches"] F.SeveralPatch "REGEXP" "select patches matching REGEXP" ] hash = OptSpec {..} where ounparse k mfs = k [ F.OneHash s | OneHash s <- mfs ] oparse k fs = k [ OneHash s | F.OneHash s <- fs ] ocheck _ = [] odesc = [ strArg ['h'] ["hash"] F.OneHash "HASH" "select a single patch with HASH" ] match = OptSpec {..} where ounparse k mfs = k [ F.OnePattern s | OnePattern s <- mfs ] oparse k fs = k [ OnePattern s | F.OnePattern s <- fs ] ocheck _ = [] odesc = [ strArg [] ["match"] F.OnePattern "PATTERN" "select a single patch matching PATTERN" ] matches = OptSpec {..} where ounparse k mfs = k [ F.SeveralPattern s | SeveralPattern s <- mfs ] oparse k fs = k [ SeveralPattern s | F.SeveralPattern s <- fs ] ocheck _ = [] odesc = [ strArg [] ["matches"] F.SeveralPattern "PATTERN" "select patches matching PATTERN" ] last = OptSpec {..} where ounparse k mfs = k [ F.LastN s | LastN s <- mfs ] oparse k fs = k [ LastN s | F.LastN s <- fs ] ocheck _ = [] odesc = [ strArg [] ["last"] (F.LastN . toInt) "NUMBER" "select the last NUMBER patches" ] toInt s = if not (null s) && all isDigit s then read s else (-1) -- | TODO: see 'Darcs.UI.Options.maxCount'. index = OptSpec {..} where ounparse k mfs = k [ F.PatchIndexRange n m | PatchIndexRange n m <- mfs ] oparse k fs = k [ PatchIndexRange n m | F.PatchIndexRange n m <- fs ] ocheck _ = [] odesc = [ strArg ['n'] ["index"] indexrange "N" "select one patch" ] indexrange s = if all isDigit s then F.PatchIndexRange (read s) (read s) else F.PatchIndexRange 0 0 -- | TODO: see 'Darcs.UI.Options.maxCount'. indexes = OptSpec {..} where ounparse k mfs = k [ F.PatchIndexRange n m | PatchIndexRange n m <- mfs ] oparse k fs = k [ PatchIndexRange n m | F.PatchIndexRange n m <- fs ] ocheck _ = [] odesc = [ strArg ['n'] ["index"] indexrange "N-M" "select a range of patches" ] indexrange s = if all isokay s then if '-' `elem` s then let x1 = takeWhile (/= '-') s x2 = reverse $ takeWhile (/= '-') $ reverse s in F.PatchIndexRange (read x1) (read x2) else F.PatchIndexRange (read s) (read s) else F.PatchIndexRange 0 0 isokay c = isDigit c || c == '-' darcs-2.14.5/src/Darcs/UI/Options/Util.hs0000644000000000000000000003040307346545000016134 0ustar0000000000000000{-# LANGUAGE RecordWildCards #-} -- | Constructing 'OptSpec's and 'OptDescr's module Darcs.UI.Options.Util ( Flag , PrimDarcsOption , DarcsOptDescr , noArg , strArg , optStrArg , absPathArg , absPathOrStdArg , optAbsPathArg , RawOptSpec(..) , withDefault , singleNoArg , singleStrArg , multiStrArg , multiOptStrArg , singleAbsPathArg , multiAbsPathArg , deprecated -- Re-exports , AbsolutePath , AbsolutePathOrStd , makeAbsolute , makeAbsoluteOrStd ) where import Prelude () import Darcs.Prelude import System.Console.GetOpt ( OptDescr(..), ArgDescr(..) ) import Data.Functor.Compose import Data.List ( intercalate ) import Data.Maybe ( maybeToList, fromMaybe ) import Darcs.UI.Options.Core import Darcs.UI.Options.Flags ( DarcsFlag ) import Darcs.UI.Options.Iso import Darcs.Util.Path ( AbsolutePath , AbsolutePathOrStd , makeAbsolute , makeAbsoluteOrStd ) -- * Instantiating 'OptSpec' and 'PrimOptSpec' -- | This type synonym is here for brevity and because we want to import -- the data constructors (but not the type) of 'DarcsFlag' qualified. type Flag = DarcsFlag {- | We do not instantiate the @d@ in @'OptSpec' d f@ directly with 'System.Console.GetOpt.OptDescr'. Instead we (post-) compose it with @(->) 'DarcsUtil.Path.AbsolutePath'@. Modulo newtype noise, this is the same as @ type 'DarcsOptDescr f = 'System.Console.GetOpt.OptDescr' ('AbsolutePath' -> f)@ This is so we can pass a directory relative to which an option argument is interpreted (if it has the form of a relative path). -} type DarcsOptDescr = Compose OptDescr ((->) AbsolutePath) -- | This is 'PrimOptSpec' instantiated with 'DarcsOptDescr and 'Flag'. type PrimDarcsOption v = forall a. PrimOptSpec DarcsOptDescr Flag a v -- * Constructing 'OptDescr's -- | Construct an 'DarcsOptDescr with no arguments. noArg :: [Char] -> [String] -> f -> String -> DarcsOptDescr f noArg s l f h = Compose $ Option s l (NoArg (const f)) h -- | A 'DarcsOptDescr' that requires a single argument of type 'a' and handles -- flags of type 'f'. type SingleArgOptDescr a f = [Char] -> [String] -> (a -> f) -> String -> String -> DarcsOptDescr f -- | Construct an 'DarcsOptDescr with a 'String' argument. strArg :: SingleArgOptDescr String f strArg s l f a h = Compose $ Option s l (ReqArg (\x _ -> f x) a) h -- | Construct an 'DarcsOptDescr with an optional 'String' argument. optStrArg :: SingleArgOptDescr (Maybe String) f optStrArg s l f a h = Compose $ Option s l (OptArg (\x _ -> f x) a) h -- | Construct an 'DarcsOptDescr with an 'AbsolutePath' -- argument. absPathArg :: SingleArgOptDescr AbsolutePath f absPathArg s l f a h = Compose $ Option s l (ReqArg (\x wd -> f $ makeAbsolute wd x) a) h -- | Construct an 'DarcsOptDescr with an 'AbsolutePathOrStd' -- argument. absPathOrStdArg :: SingleArgOptDescr AbsolutePathOrStd f absPathOrStdArg s l f a h = Compose $ Option s l (ReqArg (\x wd -> f $ makeAbsoluteOrStd wd x) a) h -- | Construct an 'DarcsOptDescr with an optional 'AbsolutePath' -- argument. optAbsPathArg :: [Char] -> [String] -> String -> (AbsolutePath -> f) -> String -> String -> DarcsOptDescr f optAbsPathArg s l d f a h = Compose $ Option s l (OptArg (\x wd -> f $ makeAbsolute wd $ fromMaybe d x) a) h -- * Raw option specs -- | The raw material from which multi-valued options are built. See 'withDefault'. data RawOptSpec f v = RawNoArg [Char] [String] f v String | RawStrArg [Char] [String] (String -> f) (f -> [String]) (String -> v) (v -> [String]) String String | RawAbsPathArg [Char] [String] (AbsolutePath -> f) (f -> [AbsolutePath]) (AbsolutePath -> v) (v -> [AbsolutePath]) String String | RawAbsPathOrStdArg [Char] [String] (AbsolutePathOrStd -> f) (f -> [AbsolutePathOrStd]) (AbsolutePathOrStd -> v) (v -> [AbsolutePathOrStd]) String String | RawOptAbsPathArg [Char] [String] (AbsolutePath -> f) (f -> [AbsolutePath]) (AbsolutePath -> v) (v -> [AbsolutePath]) String String String instance IsoFunctor (RawOptSpec f) where imap (Iso fw _) (RawNoArg s l f v h) = RawNoArg s l f (fw v) h imap (Iso fw bw) (RawStrArg s l mkF unF mkV unV n h) = RawStrArg s l mkF unF (fw . mkV) (unV . bw) n h imap (Iso fw bw) (RawAbsPathArg s l mkF unF mkV unV n h) = RawAbsPathArg s l mkF unF (fw . mkV) (unV . bw) n h imap (Iso fw bw) (RawAbsPathOrStdArg s l mkF unF mkV unV n h) = RawAbsPathOrStdArg s l mkF unF (fw . mkV) (unV . bw) n h imap (Iso fw bw) (RawOptAbsPathArg s l mkF unF mkV unV d n h) = RawOptAbsPathArg s l mkF unF (fw . mkV) (unV . bw) d n h -- | Get the long switch names from a raw option. Used to construct error messages. switchNames :: RawOptSpec f v -> [String] switchNames (RawNoArg _ l _ _ _) = l switchNames (RawStrArg _ l _ _ _ _ _ _) = l switchNames (RawAbsPathArg _ l _ _ _ _ _ _) = l switchNames (RawAbsPathOrStdArg _ l _ _ _ _ _ _) = l switchNames (RawOptAbsPathArg _ l _ _ _ _ _ _ _) = l -- | Given a list of 'RawOptSpec', find all flags that match a given value. rawUnparse :: Eq v => [RawOptSpec f v] -> v -> [f] rawUnparse ropts val = [ f | RawNoArg _ _ f v _ <- ropts, v == val ] ++ [ mkF s | RawStrArg _ _ mkF _ mkV unV _ _ <- ropts, s <- unV val, mkV s == val ] ++ [ mkF p | RawAbsPathArg _ _ mkF _ mkV unV _ _ <- ropts, p <- unV val, mkV p == val ] ++ [ mkF p | RawAbsPathOrStdArg _ _ mkF _ mkV unV _ _ <- ropts, p <- unV val, mkV p == val ] ++ [ mkF p | RawOptAbsPathArg _ _ mkF _ mkV unV _ _ _ <- ropts, p <- unV val, mkV p == val ] -- | Given a list of 'RawOptSpec', find all values that match a given flag list -- in the order in which they appear in the flag list. rawParse :: Eq f => [RawOptSpec f v] -> [f] -> [(v,RawOptSpec f v)] rawParse ropts = concatMap rawParseFlag where rawParseFlag f = concatMap (go f) ropts go f o@(RawNoArg _ _ f' v _) = [ (v, o) | f == f' ] go f o@(RawStrArg _ _ _ unF mkV _ _ _) = [ (mkV s, o) | s <- unF f ] go f o@(RawAbsPathArg _ _ _ unF mkV _ _ _) = [ (mkV p, o) | p <- unF f ] go f o@(RawAbsPathOrStdArg _ _ _ unF mkV _ _ _) = [ (mkV p, o) | p <- unF f ] go f o@(RawOptAbsPathArg _ _ _ unF mkV _ _ _ _) = [ (mkV p, o) | p <- unF f ] -- [ (v, o) | f <- fs, o@(RawNoArg _ _ f' v _) <- ropts, f == f' ] -- ++ [ (mkV s, o) | f <- fs, o@(RawStrArg _ _ _ unF mkV _ _ _) <- ropts, s <- unF f ] -- ++ [ (mkV p, o) | f <- fs, o@(RawAbsPathArg _ _ _ unF mkV _ _ _) <- ropts, p <- unF f ] -- ++ [ (mkV p, o) | f <- fs, o@(RawAbsPathOrStdArg _ _ _ unF mkV _ _ _) <- ropts, p <- unF f ] -- ++ [ (mkV p, o) | f <- fs, o@(RawOptAbsPathArg _ _ _ unF mkV _ _ _ _) <- ropts, p <- unF f ] -- | The first element of a list, or a default if the list is empty. defHead :: a -> [a] -> a defHead def [] = def defHead _ (x:_) = x -- | Append \" [DEFAULT\" to the help text of options that match the default value. addDefaultHelp :: Eq v => v -> RawOptSpec f v -> DarcsOptDescr f addDefaultHelp dval (RawNoArg s l f v h) | dval == v = noArg s l f (h++" [DEFAULT]") | otherwise = noArg s l f h addDefaultHelp dval (RawStrArg s l mkF _ mkV unV a h) | [dval] == map mkV (unV dval) = strArg s l mkF a (h++" [DEFAULT]") | otherwise = strArg s l mkF a h addDefaultHelp dval (RawAbsPathArg s l mkF _ mkV unV a h) | [dval] == map mkV (unV dval) = absPathArg s l mkF a (h++" [DEFAULT]") | otherwise = absPathArg s l mkF a h addDefaultHelp dval (RawAbsPathOrStdArg s l mkF _ mkV unV a h) | [dval] == map mkV (unV dval) = absPathOrStdArg s l mkF a (h++" [DEFAULT]") | otherwise = absPathOrStdArg s l mkF a h addDefaultHelp dval (RawOptAbsPathArg s l mkF _ mkV unV d a h) | [dval] == map mkV (unV dval) = optAbsPathArg s l d mkF a (h++" [DEFAULT]") | otherwise = optAbsPathArg s l d mkF a h -- | Construct a 'PrimDarcsOption' from a default value and a list of 'RawOptSpec'. -- -- Precondition: the list must have an entry for each possible value (type @v@). withDefault :: Eq v => v -> [RawOptSpec Flag v] -> PrimDarcsOption v withDefault dval ropts = OptSpec {..} where ounparse k = k . rawUnparse ropts oparse k = k . defHead dval . map fst . rawParse ropts ocheck fs = case map snd (rawParse ropts fs) of [] -> [] -- error "this should not happen" [_] -> [] ropts' -> ["conflicting options: " ++ intercalate ", " (map (intercalate "/" . switchNames) ropts')] odesc = map (addDefaultHelp dval) ropts -- * Simple primitive scalar valued options -- | Construct a 'Bool' valued option with a single flag that takes no arguments -- and has no default flag. -- -- The arguments are: short switches, long switches, flag value, help string. singleNoArg :: [Char] -> [String] -> Flag -> String -> PrimDarcsOption Bool singleNoArg s l f h = withDefault False [RawNoArg s l f True h] -- | Construct a @'Maybe' 'String'@ valued option with a single flag that takes a -- 'String' argument and has no default flag. -- -- The arguments are: short switches, long switches, flag constructor, single flag -- parser, help string. singleStrArg :: [Char] -> [String] -> (String -> Flag) -> (Flag -> Maybe String) -> String -> String -> PrimDarcsOption (Maybe String) singleStrArg s l mkf isf n h = withDefault Nothing [ RawStrArg s l mkf (maybeToList . isf) Just maybeToList n h ] -- | Construct a @'Maybe' 'AbsolutePath'@ valued option with a single flag that -- takes an 'AbsolutePath' argument and has no default flag. -- -- The arguments are: short switches, long switches, flag constructor, single flag -- parser, help string. singleAbsPathArg :: [Char] -> [String] -> (AbsolutePath -> Flag) -> (Flag -> Maybe AbsolutePath) -> String -> String -> PrimDarcsOption (Maybe AbsolutePath) singleAbsPathArg s l mkf isf n h = withDefault Nothing [ RawAbsPathArg s l mkf (maybeToList . isf) Just maybeToList n h ] -- * Simple primitive list valued options -- | Similar to 'singleStrArg', except that the flag can be given more than once. -- The flag arguments are collected in a list of 'String's. multiStrArg :: [Char] -> [String] -> (String -> Flag) -> ([Flag] -> [String]) -> String -> String -> PrimDarcsOption [String] multiStrArg = multiArg strArg -- | Similar to 'multiStrArg', except that the flag arguments are optional. multiOptStrArg :: [Char] -> [String] -> (Maybe String -> Flag) -> ([Flag] -> [Maybe String]) -> String -> String -> PrimDarcsOption [Maybe String] multiOptStrArg = multiArg optStrArg -- | Similar to 'singleAbsPathArg', except that the flag can be given more than once. -- The flag arguments are collected in a list of 'AbsolutePath's. multiAbsPathArg :: [Char] -> [String] -> (AbsolutePath -> Flag) -> ([Flag] -> [AbsolutePath]) -> String -> String -> PrimDarcsOption [AbsolutePath] multiAbsPathArg = multiArg absPathArg -- | A multi-arg option, defined in terms of a single-arg option, returning a -- list of single args. -- -- The parameters are: single argument description, short switches, long -- switches, flag constructor, flag list parser, arg name string, help string. multiArg :: SingleArgOptDescr a Flag -> [Char] -> [String] -> (a -> Flag) -> ([Flag] -> [a]) -> String -> String -> PrimDarcsOption [a] multiArg singleArg s l mkf isf n h = OptSpec {..} where ounparse k xs = k [ mkf x | x <- xs ] oparse k = k . isf ocheck _ = [] odesc = [singleArg s l mkf n h] -- | A deprecated option. If you want to deprecate only some flags and not the -- whole option, extract the 'RawOptSpec's out of the original option and create -- a new deprecated option. -- The strings in the first argument are appended to the automatically generated -- error message in case additional hints should be provided. deprecated :: [String] -> [RawOptSpec Flag v] -> PrimDarcsOption () deprecated comments ropts = OptSpec {..} where ounparse k _ = k [] oparse k _ = k () ocheck fs = case map snd (rawParse ropts fs) of [] -> [] ropts' -> ("deprecated option(s): " ++ intercalate ", " (concatMap switchNames ropts')) : comments odesc = map noDefaultHelp ropts noDefaultHelp (RawNoArg s l f _ h) = noArg s l f h noDefaultHelp (RawStrArg s l mkF _ _ _ a h) = strArg s l mkF a h noDefaultHelp (RawAbsPathArg s l mkF _ _ _ a h) = absPathArg s l mkF a h noDefaultHelp (RawAbsPathOrStdArg s l mkF _ _ _ a h) = absPathOrStdArg s l mkF a h noDefaultHelp (RawOptAbsPathArg s l mkF _ _ _ d a h) = optAbsPathArg s l d mkF a h darcs-2.14.5/src/Darcs/UI/PatchHeader.hs0000644000000000000000000003065207346545000015742 0ustar0000000000000000module Darcs.UI.PatchHeader ( getLog , getAuthor , updatePatchHeader, AskAboutDeps(..) , HijackT, HijackOptions(..) , runHijackT ) where import Prelude () import Darcs.Prelude import Darcs.Patch ( IsRepoType, RepoPatch, PrimPatch, PrimOf, fromPrims , effect , summaryFL ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch.Info ( PatchInfo, piAuthor, piName, piLog, piDateString, patchinfo, isInverted, invertName, ) import Darcs.Patch.Named.Wrapped ( infopatch, getdeps, adddeps ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, n2pia, hopefully, info ) import Darcs.Patch.Prim ( canonizeFL ) import Darcs.Patch.Witnesses.Ordered ( FL(..), (+>+) ) import Darcs.Repository ( Repository ) import Darcs.Util.Lock ( readTextFile , writeTextFile ) import Darcs.UI.External ( editFile ) import Darcs.UI.Flags ( getEasyAuthor, promptAuthor, getDate ) import qualified Darcs.UI.Options.All as O import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions(..) ) import Darcs.UI.SelectChanges ( askAboutDepends ) import qualified Darcs.Util.Diff as D ( DiffAlgorithm ) import Darcs.Util.English ( capitalize ) import Darcs.Util.Global ( darcsLastMessage ) import Darcs.Util.Path ( FilePathLike, toFilePath ) import Darcs.Util.Prompt ( PromptConfig(..), askUser, promptChar, promptYorn ) import Darcs.Util.Printer ( text, ($$), vcat, prefixLines, renderString ) import qualified Darcs.Util.Ratified as Ratified ( hGetContents ) import Darcs.Util.Tree ( Tree ) import Control.Exception ( catch, IOException ) import Control.Monad ( when, void ) import Control.Monad.Trans ( liftIO ) import Control.Monad.Trans.State.Strict ( StateT(..), evalStateT, get, put ) import Data.List ( isPrefixOf ) import System.Exit ( exitSuccess ) import System.IO ( stdin ) data PName = FlagPatchName String | PriorPatchName String | NoPatchName -- | Options for how to deal with the situation where we are somehow -- modifying a patch that is not our own data HijackOptions = IgnoreHijack -- ^ accept all hijack requests | RequestHijackPermission -- ^ prompt once, accepting subsequent hijacks if yes | AlwaysRequestHijackPermission -- ^ always prompt -- | Transformer for interactions with a hijack warning state that we -- need to thread through type HijackT = StateT HijackOptions -- | Get the patch name and long description from one of -- -- * the configuration (flags, defaults, hard-coded) -- -- * an existing log file -- -- * stdin (e.g. a pipe) -- -- * a text editor -- -- It ensures the patch name is not empty nor starts with the prefix TAG. -- -- The last result component is a possible path to a temporary file that should be removed later. getLog :: forall prim wX wY . PrimPatch prim => Maybe String -- ^ patchname option -> Bool -- ^ pipe option -> O.Logfile -- ^ logfile option -> Maybe O.AskLongComment -- ^ askLongComment option -> Maybe (String, [String]) -- ^ possibly an existing patch name and long description -> FL prim wX wY -- ^ changes to record -> IO (String, [String], Maybe String) -- ^ patch name, long description and possibly the path -- to the temporary file that should be removed later getLog m_name has_pipe log_file ask_long m_old chs = go has_pipe log_file ask_long where go True _ _ = do p <- case patchname_specified of FlagPatchName p -> return p PriorPatchName p -> return p NoPatchName -> prompt_patchname False putStrLn "What is the log?" thelog <- lines `fmap` Ratified.hGetContents stdin return (p, thelog, Nothing) go _ (O.Logfile { O._logfile = Just f }) _ = do mlp <- readTextFile f `catch` (\(_ :: IOException) -> return []) firstname <- case (patchname_specified, mlp) of (FlagPatchName p, []) -> return p (_, p:_) -> if badName p then prompt_patchname True else return p -- logfile trumps prior! (PriorPatchName p, []) -> return p (NoPatchName, []) -> prompt_patchname True append_info f firstname when (ask_long == Just O.YesEditLongComment) (void $ editFile f) (name, thelog) <- read_long_comment f firstname return (name, thelog, if O._rmlogfile log_file then Just $ toFilePath f else Nothing) go _ _ (Just O.YesEditLongComment) = case patchname_specified of FlagPatchName p -> actually_get_log p PriorPatchName p -> actually_get_log p NoPatchName -> actually_get_log "" go _ _ (Just O.NoEditLongComment) = case patchname_specified of FlagPatchName p -> return (p, default_log, Nothing) -- record (or amend) -m PriorPatchName p -> return (p, default_log, Nothing) -- amend NoPatchName -> do p <- prompt_patchname True -- record return (p, [], Nothing) go _ _ (Just O.PromptLongComment) = case patchname_specified of FlagPatchName p -> prompt_long_comment p -- record (or amend) -m PriorPatchName p -> prompt_long_comment p NoPatchName -> prompt_patchname True >>= prompt_long_comment go _ _ Nothing = case patchname_specified of FlagPatchName p -> return (p, default_log, Nothing) -- record (or amend) -m PriorPatchName "" -> actually_get_log "" PriorPatchName p -> return (p, default_log, Nothing) NoPatchName -> actually_get_log "" patchname_specified = case (m_name, m_old) of (Just name, _) | badName name -> NoPatchName | otherwise -> FlagPatchName name (Nothing, Just (name,_)) -> PriorPatchName name (Nothing, Nothing) -> NoPatchName badName "" = True badName n = "TAG" `isPrefixOf` n default_log = case m_old of Nothing -> [] Just (_,l) -> l prompt_patchname retry = do n <- askUser "What is the patch name? " if badName n then if retry then prompt_patchname retry else fail "Bad patch name!" else return n prompt_long_comment oldname = do y <- promptYorn "Do you want to add a long comment?" if y then actually_get_log oldname else return (oldname, [], Nothing) actually_get_log p = do let logf = darcsLastMessage -- TODO: make sure encoding used for logf is the same everywhere -- probably should be locale because the editor will assume it writeTextFile logf $ unlines $ p : default_log append_info logf p _ <- editFile logf (name,long) <- read_long_comment logf p if badName name then do putStrLn "WARNING: empty or incorrect patch name!" pn <- prompt_patchname True return (pn, long, Nothing) else return (name,long,Just logf) read_long_comment :: FilePathLike p => p -> String -> IO (String, [String]) read_long_comment f oldname = do t <- readTextFile f let filter_out_info = filter (not.("#" `isPrefixOf`)) case reverse $ dropWhile null $ reverse $ filter_out_info t of [] -> return (oldname, []) (n:ls) -> return (n, ls) append_info f oldname = do fc <- readTextFile f writeTextFile f $ renderString $ vcat (map text $ if null fc then [oldname] else fc) $$ text "# Please enter the patch name in the first line, and" $$ text "# optionally, a long description in the following lines." $$ text "#" $$ text "# Lines starting with '#' will be ignored." $$ text "#" $$ text "#" $$ text "# Summary of selected changes:" $$ text "#" $$ prefixLines (text "#") (summaryFL chs) -- |specify whether to ask about dependencies with respect to a particular repository, or not data AskAboutDeps rt p wR wU wT = AskAboutDeps (Repository rt p wR wU wT) | NoAskAboutDeps -- | Run a job that involves a hijack confirmation prompt. -- -- See 'RequestHijackPermission' for initial values runHijackT :: Monad m => HijackOptions -> HijackT m a -> m a runHijackT = flip evalStateT -- | Update the metadata for a patch. -- This potentially involves a bit of interactivity, so we may return @Nothing@ -- if there is cause to abort what we're doing along the way updatePatchHeader :: forall rt p wX wY wR wU wT . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => String -- ^ verb: command name -> AskAboutDeps rt p wR wU wT -> S.PatchSelectionOptions -> D.DiffAlgorithm -> Bool -- keepDate -> Bool -- selectAuthor -> Maybe String -- author -> Maybe String -- patchname -> Maybe O.AskLongComment -> PatchInfoAnd rt p wT wX -> FL (PrimOf p) wX wY -> HijackT IO (Maybe String, PatchInfoAnd rt p wT wY) updatePatchHeader verb ask_deps pSelOpts da nKeepDate nSelectAuthor nAuthor nPatchname nAskLongComment oldp chs = do let newchs = canonizeFL da (effect oldp +>+ chs) let old_pdeps = getdeps $ hopefully oldp newdeps <- case ask_deps of AskAboutDeps repository -> liftIO $ askAboutDepends repository newchs pSelOpts old_pdeps NoAskAboutDeps -> return old_pdeps let old_pinf = info oldp prior = (piName old_pinf, piLog old_pinf) date <- if nKeepDate then return (piDateString old_pinf) else liftIO $ getDate False new_author <- getAuthor verb nSelectAuthor nAuthor old_pinf liftIO $ do (new_name, new_log, mlogf) <- getLog nPatchname False (O.Logfile Nothing False) nAskLongComment (Just prior) chs let maybe_invert = if isInverted old_pinf then invertName else id new_pinf <- maybe_invert `fmap` patchinfo date new_name new_author new_log let newp = n2pia (adddeps (infopatch new_pinf (fromPrims newchs)) newdeps) return (mlogf, newp) -- | @getAuthor@ tries to return the updated author for the patch. -- There are two different scenarios: -- -- * [explicit] Either we want to override the patch author, be it by -- prompting the user (@select@) or having them pass it in from -- the UI (@new_author@), or -- -- * [implicit] We want to keep the original author, in which case we -- also double-check that we are not inadvertently \"hijacking\" -- somebody else's patch (if the patch author is not the same as the -- repository author, we give them a chance to abort the whole -- operation) getAuthor :: String -- ^ verb: command name -> Bool -- ^ select: prompt for new auhor -> Maybe String -- ^ new author: explict new author -> PatchInfo -- ^ patch to update -> HijackT IO String getAuthor _ True _ _ = do auth <- liftIO $ promptAuthor False True return auth getAuthor _ False (Just new) _ = return new getAuthor verb False Nothing pinfo = do whitelist <- liftIO $ getEasyAuthor hj <- get if orig `elem` whitelist || canIgnore hj then allowHijack else do hijackResp <- liftIO $ askAboutHijack hj case hijackResp of 'y' -> allowHijack 'a' -> put IgnoreHijack >> allowHijack _ -> liftIO exitSuccess where askAboutHijack hj = promptChar (PromptConfig msg opts [] Nothing []) where msg = "You're not " ++ orig ++"! " ++ capitalize verb ++ " anyway? " opts = case hj of AlwaysRequestHijackPermission -> "yn" _ -> "yna" canIgnore IgnoreHijack = True canIgnore RequestHijackPermission = False canIgnore AlwaysRequestHijackPermission = False allowHijack = return orig orig = piAuthor pinfo darcs-2.14.5/src/Darcs/UI/PrintPatch.hs0000644000000000000000000000572007346545000015644 0ustar0000000000000000-- Copyright (C) 2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.PrintPatch ( printPatch , contextualPrintPatch , printPatchPager , printFriendly , showFriendly ) where import Prelude () import Darcs.Prelude import Darcs.Util.Tree.Monad( virtualTreeIO ) import Darcs.Util.Tree( Tree ) import Darcs.Util.Printer.Color ( fancyPrinters ) import Darcs.Patch.Apply ( ApplyState ) import Darcs.Patch ( showContextPatch, showPatch, showNicely, description, summary ) import Darcs.Patch.Show ( ShowPatch, ShowContextPatch, ShowPatchFor(ForDisplay) ) import Darcs.UI.External ( viewDocWith ) import Darcs.UI.Options.All ( Verbosity(..), Summary(..), WithContext(..) ) import Darcs.Util.Printer ( Doc, putDocLnWith ) -- | @'printFriendly' opts patch@ prints @patch@ in accordance with the flags -- in opts, ie, whether @--verbose@ or @--summary@ were passed at the -- command-line. printFriendly :: (ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) => Maybe (Tree IO) -> Verbosity -> Summary -> WithContext -> p wX wY -> IO () printFriendly (Just pristine) _ _ YesContext = contextualPrintPatch pristine printFriendly _ v s _ = putDocLnWith fancyPrinters . showFriendly v s -- | @'showFriendly' flags patch@ returns a 'Doc' representing the right -- way to show @patch@ given the list @flags@ of flags darcs was invoked with. showFriendly :: ShowPatch p => Verbosity -> Summary -> p wX wY -> Doc showFriendly Verbose _ = showNicely showFriendly _ YesSummary = summary showFriendly _ NoSummary = description -- | 'printPatch' prints a patch on standard output. printPatch :: ShowPatch p => p wX wY -> IO () printPatch p = putDocLnWith fancyPrinters $ showPatch ForDisplay p -- | 'printPatchPager' runs '$PAGER' and shows a patch in it. printPatchPager :: ShowPatch p => p wX wY -> IO () printPatchPager p = viewDocWith fancyPrinters $ showPatch ForDisplay p -- | 'contextualPrintPatch' prints a patch, together with its context, on -- standard output. contextualPrintPatch :: (ShowContextPatch p, ApplyState p ~ Tree) => Tree IO -> p wX wY -> IO () contextualPrintPatch s p = do (contextedPatch, _) <- virtualTreeIO (showContextPatch ForDisplay p) s putDocLnWith fancyPrinters contextedPatch darcs-2.14.5/src/Darcs/UI/RunCommand.hs0000644000000000000000000002426607346545000015641 0ustar0000000000000000-- Copyright (C) 2002,2003,2005 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | This is the actual heavy lifter code, which is responsible for parsing the -- arguments and then running the command itself. module Darcs.UI.RunCommand ( runTheCommand ) where import Prelude () import Darcs.Prelude import Data.List ( intercalate ) import Control.Monad ( unless, when ) import System.Console.GetOpt( ArgOrder( Permute, RequireOrder ), OptDescr( Option ), getOpt ) import System.Exit ( ExitCode ( ExitSuccess ), exitWith ) import Darcs.UI.Options ( (^), odesc, oparse, parseFlags, optDescr, (?) ) import Darcs.UI.Options.All ( stdCmdActions, StdCmdAction(..) , anyVerbosity, verbosity, Verbosity(..), network, NetworkOptions(..) , HooksConfig(..), hooks ) import Darcs.UI.Defaults ( applyDefaults ) import Darcs.UI.External ( viewDoc ) import Darcs.UI.Flags ( DarcsFlag (NewRepo), matchAny, fixRemoteRepos ) import Darcs.UI.Commands ( CommandArgs( CommandOnly, SuperCommandOnly, SuperCommandSub ) , CommandControl , DarcsCommand , commandName , commandCommand , commandPrereq , commandExtraArgHelp , commandExtraArgs , commandArgdefaults , commandCompleteArgs , commandOptions , commandParseOptions , wrappedCommandName , disambiguateCommands , getSubcommands , extractCommands , superName ) import Darcs.UI.Commands.GZCRCs ( doCRCWarnings ) import Darcs.UI.Commands.Clone ( makeRepoName, cloneToSSH ) import Darcs.UI.Usage ( getCommandHelp , getCommandMiniHelp , subusage ) import Darcs.Patch.Match ( checkMatchSyntax ) import Darcs.Repository.Prefs ( getGlobal, getPreflist ) import Darcs.Repository.Test ( runPosthook, runPrehook ) import Darcs.Util.AtExit ( atexit ) import Darcs.Util.Download ( setDebugHTTP, disableHTTPPipelining ) import Darcs.Util.Exception ( die ) import Darcs.Util.Global ( setDebugMode, setTimingsMode ) import Darcs.Util.Path ( AbsolutePath, getCurrentDirectory, toPath, ioAbsoluteOrRemote, makeAbsolute ) import Darcs.Util.Progress ( setProgressMode ) import Darcs.Util.Text ( chompTrailingNewline, quote ) runTheCommand :: [CommandControl] -> String -> [String] -> IO () runTheCommand commandControlList cmd args = either die rtc $ disambiguateCommands commandControlList cmd args where rtc (CommandOnly c, as) = runCommand Nothing c as rtc (SuperCommandOnly c, as) = runRawSupercommand c as rtc (SuperCommandSub c s, as) = runCommand (Just c) s as runCommand :: Maybe (DarcsCommand pf1) -> DarcsCommand pf2 -> [String] -> IO () runCommand _ _ args -- Check for "dangerous" typoes... | "-all" `elem` args = -- -all indicates --all --look-for-adds! die "Are you sure you didn't mean --all rather than -all?" runCommand msuper cmd args = do old_wd <- getCurrentDirectory let options = commandOptions old_wd cmd case fixupMsgs $ getOpt Permute options args of (cmdline_flags,orig_extra,getopt_errs) -> do -- FIXME This code is highly order-dependent because of hidden state: the -- current directory. Like almost all Repository functions, getGlobal and -- getPreflist assume that the cwd is the base of our work repo (if any). -- This is supposed to be ensured by commandPrereq. Which means we must -- first call commandPrereq, then getGlobal and getPreflist, and then we -- must use the (saved) original working directory to resolve possibly -- relative paths to absolute paths. prereq_errors <- commandPrereq cmd cmdline_flags -- we must get the cwd again because commandPrereq has the side-effect of changing it. new_wd <- getCurrentDirectory user_defs <- getGlobal "defaults" repo_defs <- getPreflist "defaults" let (flags,flag_errors) = applyDefaults (fmap commandName msuper) cmd old_wd user_defs repo_defs cmdline_flags case parseFlags stdCmdActions flags of Just Help -> viewDoc $ getCommandHelp msuper cmd Just ListOptions -> do setProgressMode False possible_args <- commandCompleteArgs cmd (new_wd, old_wd) flags orig_extra mapM_ putStrLn $ optionList options ++ possible_args Just Disable -> die $ "Command "++commandName cmd++" disabled with --disable option!" Nothing -> case prereq_errors of Left complaint -> die $ "Unable to " ++ quote ("darcs " ++ superName msuper ++ commandName cmd) ++ " here.\n\n" ++ complaint Right () -> case getopt_errs ++ flag_errors of [] -> do extra <- commandArgdefaults cmd flags old_wd orig_extra case extraArgumentsError extra cmd msuper of Nothing -> runWithHooks cmd (new_wd, old_wd) flags extra Just msg -> die msg es -> die (intercalate "\n" es) fixupMsgs :: (a, b, [String]) -> (a, b, [String]) fixupMsgs (fs,as,es) = (fs,as,map (("command line: "++).chompTrailingNewline) es) runWithHooks :: DarcsCommand pf -> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO () runWithHooks cmd (new_wd, old_wd) flags extra = do checkMatchSyntax $ matchAny ? flags -- set any global variables oparse (anyVerbosity ^ network) setGlobalVariables flags -- actually run the command and its hooks let hooksCfg = parseFlags hooks flags let verb = parseFlags verbosity flags preHookExitCode <- runPrehook (pre hooksCfg) verb new_wd if preHookExitCode /= ExitSuccess then exitWith preHookExitCode else do fixedFlags <- fixRemoteRepos old_wd flags phDir <- getPosthookDir new_wd cmd fixedFlags extra let parsedFlags = commandParseOptions cmd fixedFlags commandCommand cmd (new_wd, old_wd) parsedFlags extra postHookExitCode <- runPosthook (post hooksCfg) verb phDir exitWith postHookExitCode setGlobalVariables :: Bool -> Bool -> Verbosity -> Bool -> NetworkOptions -> IO () setGlobalVariables debug debugHttp verb timings net = do when timings setTimingsMode when debug setDebugMode when debugHttp setDebugHTTP when (verb == Quiet) $ setProgressMode False when (noHttpPipelining net) disableHTTPPipelining unless (verb == Quiet) $ atexit $ doCRCWarnings (verb == Verbose) -- | Returns the working directory for the posthook. For most commands, the -- first parameter is returned. For the \'get\' command, the path of the newly -- created repository is returned if it is not an ssh url. getPosthookDir :: AbsolutePath -> DarcsCommand pf -> [DarcsFlag] -> [String] -> IO AbsolutePath getPosthookDir new_wd cmd flags extra | commandName cmd `elem` ["get","clone"] = do case extra of [inrepodir, outname] -> getPosthookDir new_wd cmd (NewRepo outname:flags) [inrepodir] [inrepodir] -> case cloneToSSH flags of Nothing -> do repodir <- toPath <$> ioAbsoluteOrRemote inrepodir reponame <- makeRepoName False flags repodir return $ makeAbsolute new_wd reponame _ -> return new_wd _ -> die "You must provide 'clone' with either one or two arguments." getPosthookDir new_wd _ _ _ = return new_wd -- | Checks if the number of extra arguments matches the number of extra -- arguments supported by the command as specified in `commandExtraArgs`. -- Extra arguments are arguments that follow the command but aren't -- considered a flag. In `darcs push xyz`, xyz would be an extra argument. extraArgumentsError :: [String] -- extra commands provided by user -> DarcsCommand pf1 -> Maybe (DarcsCommand pf2) -> Maybe String extraArgumentsError extra cmd msuper | extraArgsCmd < 0 = Nothing | extraArgsInput > extraArgsCmd = Just badArg | extraArgsInput < extraArgsCmd = Just missingArg | otherwise = Nothing where extraArgsInput = length extra extraArgsCmd = commandExtraArgs cmd badArg = "Bad argument: `" ++ unwords extra ++ "'\n" ++ getCommandMiniHelp msuper cmd missingArg = "Missing argument: " ++ nthArg (length extra + 1) ++ "\n" ++ getCommandMiniHelp msuper cmd nthArg n = nthOf n (commandExtraArgHelp cmd) nthOf 1 (h:_) = h nthOf n (_:hs) = nthOf (n-1) hs nthOf _ [] = "UNDOCUMENTED" optionList :: [OptDescr DarcsFlag] -> [String] optionList = concatMap names where names (Option sos los _ desc) = map (short desc) sos ++ map (long desc) los short d o = '-' : o : ";" ++ d long d o = "--" ++ o ++ ";" ++ d runRawSupercommand :: DarcsCommand pf -> [String] -> IO () runRawSupercommand super [] = die $ "Command '"++ commandName super ++"' requires a subcommand!\n\n" ++ subusage super runRawSupercommand super args = do cwd <- getCurrentDirectory case fixupMsgs $ getOpt RequireOrder (map (optDescr cwd) (odesc stdCmdActions)) args of -- note: we do not apply defaults here (flags,_,getopt_errs) -> case parseFlags stdCmdActions flags of Just Help -> viewDoc $ getCommandHelp Nothing super Just ListOptions -> do putStrLn "--help" mapM_ (putStrLn . wrappedCommandName) (extractCommands $ getSubcommands super) Just Disable -> do die $ "Command " ++ commandName super ++ " disabled with --disable option!" Nothing -> die $ case getopt_errs of [] -> "Invalid subcommand!\n\n" ++ subusage super _ -> intercalate "\n" getopt_errs darcs-2.14.5/src/Darcs/UI/SelectChanges.hs0000644000000000000000000011770407346545000016306 0ustar0000000000000000-- Copyright (C) 2002-2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.SelectChanges ( -- * Working with changes WhichChanges(..) , viewChanges , withSelectedPatchFromRepo , runSelection , selectionContextPrim , selectionContextGeneric , selectionContext , PatchSelectionContext(allowSkipAll) , printSummary -- * Interactive selection utils , PatchSelectionOptions(..) , InteractiveSelectionM , InteractiveSelectionContext(..) -- ** Navigating the patchset , currentPatch , skipMundane , skipOne , backOne , backAll , showCur -- ** Decisions , decide , decideWholeFile -- ** Prompts and queries , isSingleFile , currentFile , promptUser , prompt , KeyPress(..) , keysFor , helpFor , askAboutDepends ) where import Prelude () import Darcs.Prelude import Control.Monad ( liftM, unless, when, (>=>) ) import Control.Monad.Identity ( Identity (..) ) import Control.Monad.Reader ( ReaderT , asks , runReaderT ) import Control.Monad.State ( StateT, execStateT, gets , modify, runStateT, state ) import Control.Monad.Trans ( liftIO ) import Data.List ( intercalate, union ) import Data.Maybe ( isJust, catMaybes ) import System.Exit ( exitSuccess ) import Darcs.Patch ( IsRepoType, RepoPatch, PrimOf , commuteFLorComplain, invert , listTouchedFiles, fromPrims ) import qualified Darcs.Patch ( thing, things, summary ) import Darcs.Patch.Apply ( Apply, ApplyState ) import Darcs.Patch.Choices ( PatchChoices, Slot (..), LabelledPatch , mkPatchChoices, forceFirsts , forceFirst, forceLast, forceMatchingFirst , forceMatchingLast, getChoices , makeEverythingLater, makeEverythingSooner , forceMiddle, patchChoices , patchSlot , refineChoices, selectAllMiddles , separateFirstFromMiddleLast , substitute, label, unLabel , labelPatches ) import Darcs.Patch.Commute ( Commute ) import Darcs.Patch.Info ( PatchInfo ) import Darcs.Patch.Inspect ( PatchInspect ) import Darcs.Patch.Invert ( Invert ) import Darcs.Patch.Match ( haveNonrangeMatch, matchAPatch ) import Darcs.Patch.Named.Wrapped ( anonymous ) import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info, n2pia ) import Darcs.Patch.Set ( PatchSet(..), patchSet2RL ) import Darcs.Patch.Show ( ShowPatch, ShowContextPatch ) import Darcs.Patch.Split ( Splitter(applySplitter,canonizeSplit) ) import Darcs.Patch.TouchesFiles ( selectNotTouching, deselectNotTouching ) import Darcs.Patch.Type ( PatchType (..) ) import Darcs.Patch.Witnesses.Eq ( unsafeCompare ) import Darcs.Patch.Witnesses.Ordered ( (:>) (..), (:||:) (..), FL (..) , RL (..), filterFL, lengthFL, mapFL , mapFL_FL, spanFL, spanFL_M , (+>+), (+<<+), (+>>+) ) import Darcs.Patch.Witnesses.Sealed ( FlippedSeal (..), Sealed2 (..) , flipSeal, seal2, unseal2 ) import Darcs.Patch.Witnesses.WZipper ( FZipper (..), left, right , rightmost, toEnd, toStart ) import Darcs.Repository ( Repository, repoLocation, readRepo, readTentativeRepo ) import Darcs.UI.External ( editText ) import Darcs.UI.Options.All ( Verbosity(..), Summary(..) , WithContext(..), SelectDeps(..), MatchFlag ) import Darcs.UI.PrintPatch ( printFriendly, printPatch , printPatchPager, showFriendly ) import Darcs.Util.English ( Noun (..), englishNum, capitalize ) import Darcs.Util.Printer ( prefix, putDocLn, putDocLnWith, greenText ) import Darcs.Util.Printer.Color ( fancyPrinters ) import Darcs.Util.Prompt ( PromptConfig (..), askUser, promptChar ) import Darcs.Util.Tree ( Tree ) -- | When asking about patches, we either ask about them in -- oldest-first or newest first (with respect to the current ordering -- of the repository), and we either want an initial segment or a -- final segment of the poset of patches. -- -- 'First': ask for an initial -- segment, first patches first (default for all pull-like commands) -- -- 'FirstReversed': ask for an initial segment, last patches first -- (used to ask about dependencies in record, and for pull-like -- commands with the @--reverse@ flag). -- -- 'LastReversed': ask for a final segment, last patches first. (default -- for unpull-like commands, except for selecting *primitive* patches in -- rollback) -- -- 'Last': ask for a final segment, first patches first. (used for selecting -- primitive patches in rollback, and for unpull-like commands with the -- @--reverse@ flag -- -- IOW: First = initial segment -- Last = final segment -- Reversed = start with the newest patch instead of oldest -- As usual, terminology is not, ahem, very intuitive. data WhichChanges = Last | LastReversed | First | FirstReversed deriving (Eq, Show) -- | A 'WhichChanges' is 'backward' if the segment of patches we ask for -- is at the opposite end of where we start to present them. backward :: WhichChanges -> Bool backward w = w == Last || w == FirstReversed -- | A 'WhichChanges' is reversed if the order in which patches are presented -- is latest (or newest) patch first. reversed :: WhichChanges -> Bool reversed w = w == LastReversed || w == FirstReversed -- | The type of the function we use to filter patches when @--match@ is -- given. data MatchCriterion p = MatchCriterion { mcHasNonrange :: Bool , mcFunction :: forall wA wB. WhichChanges -> LabelledPatch p wA wB -> Bool } data PatchSelectionOptions = PatchSelectionOptions { verbosity :: Verbosity , matchFlags :: [MatchFlag] , interactive :: Bool , selectDeps :: SelectDeps , summary :: Summary , withContext :: WithContext } -- | A @PatchSelectionContext@ contains all the static settings for selecting -- patches. See "PatchSelectionM" data PatchSelectionContext p = PSC { opts :: PatchSelectionOptions , splitter :: Maybe (Splitter p) , files :: Maybe [FilePath] , matchCriterion :: MatchCriterion p , jobname :: String , allowSkipAll :: Bool , pristine :: Maybe (Tree IO) , whichChanges :: WhichChanges } -- | A 'PatchSelectionContext' for selecting 'Prim' patches. selectionContextPrim :: WhichChanges -> String -> PatchSelectionOptions -> Maybe (Splitter prim) -> Maybe [FilePath] -> Maybe (Tree IO) -> PatchSelectionContext prim selectionContextPrim whch jn o spl fs p = PSC { opts = o , splitter = spl , files = fs , matchCriterion = triv , jobname = jn , allowSkipAll = True , pristine = p , whichChanges = whch } -- | A 'PatchSelectionContext' for selecting full patches ('PatchInfoAnd' patches) selectionContext :: (IsRepoType rt, RepoPatch p) => WhichChanges -> String -> PatchSelectionOptions -> Maybe (Splitter (PatchInfoAnd rt p)) -> Maybe [FilePath] -> PatchSelectionContext (PatchInfoAnd rt p) selectionContext whch jn o spl fs = PSC { opts = o , splitter = spl , files = fs , matchCriterion = iswanted seal2 (matchFlags o) , jobname = jn , allowSkipAll = True , pristine = Nothing , whichChanges = whch } -- | A generic 'PatchSelectionContext'. selectionContextGeneric :: (IsRepoType rt, RepoPatch p, Invert q) => (forall wX wY . q wX wY -> Sealed2 (PatchInfoAnd rt p)) -> WhichChanges -> String -> PatchSelectionOptions -> Maybe [FilePath] -> PatchSelectionContext q selectionContextGeneric extract whch jn o fs = PSC { opts = o , splitter = Nothing , files = fs , matchCriterion = iswanted extract (matchFlags o) , jobname = jn , allowSkipAll = True , pristine = Nothing , whichChanges = whch } -- | The dynamic parameters for interactive selection of patches. data InteractiveSelectionContext p wX wY = ISC { total :: Int -- ^ total number of patches , current :: Int -- ^ number of already-seen patches , lps :: FZipper (LabelledPatch p) wX wY -- ^ the patches we offer , choices :: PatchChoices p wX wY -- ^ the user's choices } type PatchSelectionM p a = ReaderT (PatchSelectionContext p) a type InteractiveSelectionM p wX wY a = StateT (InteractiveSelectionContext p wX wY) (PatchSelectionM p IO) a -- Common match criteria -- | For commands without @--match@, 'triv' matches all patches triv :: MatchCriterion p triv = MatchCriterion { mcHasNonrange = False, mcFunction = \ _ _ -> True } -- | 'iswanted' selects patches according to the given match flags iswanted :: forall rt p q . (IsRepoType rt, RepoPatch p, Invert q) => (forall wX wY . q wX wY -> Sealed2 (PatchInfoAnd rt p)) -> [MatchFlag] -> MatchCriterion q iswanted extract mflags = MatchCriterion { mcHasNonrange = haveNonrangeMatch (PatchType :: PatchType rt p) mflags , mcFunction = isWantedMcFunction } where isWantedMcFunction w = unseal2 (matchAPatch mflags) . extract_reverse w . unLabel -- TODO inverting should not be necessary here, at least I would expect -- -- prop> matchAPatch (invert x) == matchAPatch x extract_reverse w = if reversed w then extract . invert else extract -- | Run a 'PatchSelection' action in the given 'PatchSelectionContext'. runSelection :: forall p wX wY . ( Invert p, Commute p, Apply p, PatchInspect p, ShowPatch p , ShowContextPatch p, ApplyState p ~ Tree ) => FL p wX wY -> PatchSelectionContext p -> IO ((FL p :> FL p) wX wY) runSelection ps psc = runReaderT (selection ps) psc where selection | reversed whch = fmap invert . doit . invert | otherwise = doit -- efficiency note: we should first filterUnwanted to apply matchers, -- as this often requires to read only metadata; then filterNotTouching -- applies path restrictions which needs to read patch contents doit = fmap (canonizeAfterSplitter . selectedPatches) . selectChanges . filterNotTouching . filterUnwanted . patchChoices -- configuration whch = whichChanges psc fs = files psc os = opts psc crit = matchCriterion psc mspl = splitter psc -- after selecting with a splitter, the results may not be canonical canonizeAfterSplitter :: (FL p :> FL p) wA wB -> (FL p :> FL p) wA wB canonizeAfterSplitter (x :> y) = let canonizeIfNeeded = maybe id canonizeSplit mspl in canonizeIfNeeded x :> canonizeIfNeeded y -- retrieve the results of patch selection selectedPatches :: PatchChoices p wA wB -> (FL p :> FL p) wA wB selectedPatches pc | backward whch = case getChoices pc of fc :> mc :> lc -> mapFL_FL unLabel (fc +>+ mc) :> mapFL_FL unLabel lc | otherwise = case separateFirstFromMiddleLast pc of xs :> ys -> mapFL_FL unLabel xs :> mapFL_FL unLabel ys selectChanges :: PatchChoices p wA wB -> PatchSelectionM p IO (PatchChoices p wA wB) selectChanges | interactive os = refineChoices textSelect | otherwise = return . promote promote | backward whch = makeEverythingLater | otherwise = makeEverythingSooner demote | backward whch = makeEverythingSooner | otherwise = makeEverythingLater filterNotTouching | backward whch = selectNotTouching fs | otherwise = deselectNotTouching fs -- when using @--match@, remove unmatched patches -- not depended upon by matched patches filterUnwanted :: PatchChoices p wA wB -> PatchChoices p wA wB filterUnwanted | mcHasNonrange crit = case selectDeps os of NoDeps -> deselectUnwanted _ -> demote . selectWanted | otherwise = id selectWanted | backward whch = forceMatchingLast iswanted_ | otherwise = forceMatchingFirst iswanted_ deselectUnwanted | backward whch = forceMatchingFirst (not . iswanted_) | otherwise = forceMatchingLast (not . iswanted_) iswanted_ = mcFunction crit whch {- end of runSelection -} -- | The equivalent of 'runSelection' for the @darcs log@ command viewChanges :: (ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) => PatchSelectionOptions -> [Sealed2 p] -> IO () viewChanges ps_opts = textView ps_opts Nothing 0 [] -- | The type of the answers to a "shall I [wiggle] that [foo]?" question -- They are found in a [[KeyPress]] bunch, each list representing a set of -- answers which belong together data KeyPress = KeyPress { kp :: Char , kpHelp :: String } -- | Generates the help for a set of basic and advanced 'KeyPress' groups. helpFor :: String -> [[KeyPress]] -> [[KeyPress]] -> String helpFor jn basicKeypresses advancedKeyPresses = unlines $ [ "How to use "++jn++":" ] ++ intercalate [""] (map (map help) keypresses) ++ [ "" , "?: show this help" , "" , ": accept the current default (which is capitalized)" ] where help i = kp i:(": "++kpHelp i) keypresses = basicKeypresses ++ advancedKeyPresses -- | The keys used by a list of 'keyPress' groups. keysFor :: [[KeyPress]] -> [Char] keysFor = concatMap (map kp) -- | The function for selecting a patch to amend record. Read at your own risks. withSelectedPatchFromRepo :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => String -- name of calling command (always "amend" as of now) -> Repository rt p wR wU wT -> PatchSelectionOptions -> (forall wA . (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wA wR -> IO ()) -> IO () withSelectedPatchFromRepo jn repository o job = do patchSet <- readRepo repository sp <- wspfr jn (matchAPatch $ matchFlags o) (patchSet2RL patchSet) NilFL case sp of Just (FlippedSeal (skipped :> selected')) -> job (skipped :> selected') Nothing -> putStrLn $ "Cancelling " ++ jn ++ " since no patch was selected." data SkippedReason = SkippedAutomatically | SkippedManually data WithSkipped p wX wY = WithSkipped { _skippedReason :: SkippedReason , skippedPatch :: p wX wY } -- | This ensures that the selected patch commutes freely with the skipped -- patches, including pending and also that the skipped sequences has an -- ending context that matches the recorded state, z, of the repository. wspfr :: forall rt p wX wY wU. (RepoPatch p, ApplyState p ~ Tree) => String -> (forall wA wB . (PatchInfoAnd rt p) wA wB -> Bool) -> RL (PatchInfoAnd rt p) wX wY -> FL (WithSkipped (PatchInfoAnd rt p)) wY wU -> IO (Maybe (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)) wspfr _ _ NilRL _ = return Nothing wspfr jn matches remaining@(pps:<:p) skipped | not $ matches p = wspfr jn matches pps (WithSkipped SkippedAutomatically p :>: skipped) | otherwise = case commuteFLorComplain (p :> mapFL_FL skippedPatch skipped) of Left _ -> do putStrLn "\nSkipping depended-upon patch:" defaultPrintFriendly p wspfr jn matches pps (WithSkipped SkippedAutomatically p :>: skipped) Right (skipped' :> p') -> do defaultPrintFriendly p yorn <- promptChar PromptConfig { pPrompt = prompt' , pBasicCharacters = keysFor basicOptions , pAdvancedCharacters = keysFor advancedOptions , pDefault = Just 'n' , pHelp = "?h" } case yorn of 'y' -> return $ Just $ flipSeal $ skipped' :> p' 'n' -> nextPatch 'j' -> nextPatch 'k' -> previousPatch remaining skipped 'v' -> printPatch p >> repeatThis 'p' -> printPatchPager p >> repeatThis 'x' -> do putDocLn $ prefix " " $ Darcs.Patch.summary p repeatThis 'q' -> do putStrLn $ (capitalize jn) ++ " cancelled." exitSuccess _ -> do putStrLn $ helpFor jn basicOptions advancedOptions repeatThis where repeatThis = wspfr jn matches (pps:<:p) skipped prompt' = "Shall I " ++ jn ++ " this patch?" nextPatch = wspfr jn matches pps (WithSkipped SkippedManually p:>:skipped) previousPatch :: RL (PatchInfoAnd rt p) wX wQ -> FL (WithSkipped (PatchInfoAnd rt p)) wQ wU -> IO (Maybe (FlippedSeal (FL (PatchInfoAnd rt p) :> PatchInfoAnd rt p) wU)) previousPatch remaining' NilFL = wspfr jn matches remaining' NilFL previousPatch remaining' (WithSkipped sk prev :>: skipped'') = case sk of SkippedManually -> wspfr jn matches (remaining' :<: prev) skipped'' SkippedAutomatically -> previousPatch (remaining' :<: prev) skipped'' basicOptions = [[ KeyPress 'y' (jn ++ " this patch") , KeyPress 'n' ("don't " ++ jn ++ " it") , KeyPress 'j' "skip to next patch" , KeyPress 'k' "back up to previous patch" ]] advancedOptions = [[ KeyPress 'v' "view this patch in full" , KeyPress 'p' "view this patch in full with pager" , KeyPress 'x' "view a summary of this patch" , KeyPress 'q' ("cancel " ++ jn) ]] defaultPrintFriendly = printFriendly Nothing NormalVerbosity NoSummary NoContext -- | Runs a function on the underlying @PatchChoices@ object liftChoices :: StateT (PatchChoices p wX wY) Identity a -> InteractiveSelectionM p wX wY a liftChoices act = do ch <- gets choices let (result, _) = runIdentity $ runStateT act ch modify $ \isc -> isc {choices = ch} -- Should this be ch or the result of runState? return result -- | @justDone n@ notes that @n@ patches have just been processed justDone :: Int -> InteractiveSelectionM p wX wY () justDone n = modify $ \isc -> isc{ current = current isc + n} -- | The actual interactive selection process. textSelect :: ( Commute p, Invert p, ShowPatch p, ShowContextPatch p , PatchInspect p, ApplyState p ~ Tree ) => FL (LabelledPatch p) wX wY -> PatchChoices p wX wY -> PatchSelectionM p IO (PatchChoices p wX wY) textSelect lps' pcs = do userSelection <- execStateT (skipMundane >> showCur >> textSelectIfAny) ISC { total = lengthFL lps' , current = 0 , lps = FZipper NilRL lps' , choices = pcs } return $ choices userSelection where textSelectIfAny = do z <- gets lps unless (rightmost z) $ textSelect' textSelect' :: ( Commute p, Invert p, ShowPatch p, ShowContextPatch p , PatchInspect p, ApplyState p ~ Tree ) => InteractiveSelectionM p wX wY () textSelect' = do z <- gets lps done <- if not $ rightmost z then textSelectOne else lastQuestion unless done $ textSelect' optionsBasic :: String -> String -> [KeyPress] optionsBasic jn aThing = [ KeyPress 'y' (jn++" this "++aThing) , KeyPress 'n' ("don't "++jn++" it") , KeyPress 'w' "wait and decide later, defaulting to no" ] optionsFile :: String -> [KeyPress] optionsFile jn = [ KeyPress 's' ("don't "++jn++" the rest of the changes to this file") , KeyPress 'f' (jn++" the rest of the changes to this file") ] optionsView :: String -> String -> [KeyPress] optionsView aThing someThings = [ KeyPress 'v' ("view this "++aThing++" in full") , KeyPress 'p' ("view this "++aThing++" in full with pager") , KeyPress 'l' ("list all selected "++someThings) ] optionsSummary :: String -> [KeyPress] optionsSummary aThing = [ KeyPress 'x' ("view a summary of this "++aThing) ] optionsQuit :: String -> Bool -> String -> [KeyPress] optionsQuit jn allowsa someThings = [ KeyPress 'd' (jn++" selected "++someThings++ ", skipping all the remaining "++someThings) | allowsa ] ++ [ KeyPress 'a' (jn++" all the remaining "++someThings) , KeyPress 'q' ("cancel "++jn) ] optionsNav :: String -> Bool -> [KeyPress] optionsNav aThing isLast= [ KeyPress 'j' ("skip to next "++ aThing) | not isLast ] ++ [ KeyPress 'k' ("back up to previous "++ aThing) , KeyPress 'g' ("start over from the first "++aThing)] optionsSplit :: Maybe (Splitter a) -> String -> [KeyPress] optionsSplit split aThing | Just _ <- split = [ KeyPress 'e' ("interactively edit this "++ aThing) ] | otherwise = [] optionsLast :: String -> String -> ([[KeyPress]], [[KeyPress]]) optionsLast jn aThing = (optionsNav aThing True: [[ KeyPress 'y' "confirm this operation" , KeyPress 'q' ("cancel " ++ jn) ] , [ KeyPress 'l' "list all selected" ] ] ,[[KeyPress 'a' "confirm this operation" , KeyPress 'd' "confirm this operation" , KeyPress 'n' ("cancel " ++ jn) ]]) options :: (ShowPatch p) => Bool -> InteractiveSelectionM p wX wY ([[KeyPress]],[[KeyPress]]) options single = do split <- asks splitter jn <- asks jobname allowsa <- asks allowSkipAll aThing <- thing someThings <- things o <- asks opts return ([optionsBasic jn aThing] ,[optionsSplit split aThing] ++ [optionsFile jn | single] ++ [optionsView aThing someThings ++ if summary o == YesSummary then [] else optionsSummary aThing] ++ [optionsQuit jn allowsa someThings] ++ [optionsNav aThing False] ) -- | Returns a @Sealed2@ version of the patch we are asking the user -- about. currentPatch :: InteractiveSelectionM p wX wY (Maybe (Sealed2 (LabelledPatch p))) currentPatch = do FZipper _ lps_todo <- gets lps case lps_todo of NilFL -> return Nothing (lp:>:_) -> return $ Just (Sealed2 lp) -- | Returns the patches we have yet to ask the user about. todo :: InteractiveSelectionM p wX wY (FlippedSeal (FL (LabelledPatch p)) wY) todo = do (FZipper _ lps_todo) <- gets lps return (FlippedSeal lps_todo) -- | Modify the underlying @PatchChoices@ by some function modifyChoices :: (PatchChoices p wX wY -> PatchChoices p wX wY) -> InteractiveSelectionM p wX wY () modifyChoices f = modify $ \isc -> isc{choices = f $ choices isc} -- | returns @Just f@ if the 'currentPatch' only modifies @f@, -- @Nothing@ otherwise. currentFile :: (PatchInspect p) => InteractiveSelectionM p wX wY (Maybe FilePath) currentFile = do c <- currentPatch return $ case c of Nothing -> Nothing Just (Sealed2 lp) -> case listTouchedFiles lp of [f] -> Just f _ -> Nothing -- | @decide True@ selects the current patch, and @decide False@ deselects -- it. decide :: Commute p => Bool -> LabelledPatch p wT wU -> InteractiveSelectionM p wX wY () decide takeOrDrop lp = do whch <- asks whichChanges if backward whch == takeOrDrop -- we go backward xor we are dropping then modifyChoices $ forceLast (label lp) else modifyChoices $ forceFirst (label lp) -- | like 'decide', but for all patches touching @file@ decideWholeFile :: (Commute p, PatchInspect p) => FilePath -> Bool -> InteractiveSelectionM p wX wY () decideWholeFile file takeOrDrop = do FlippedSeal lps_todo <- todo let patches_to_skip = filterFL (\lp' -> listTouchedFiles lp' == [file]) lps_todo mapM_ (unseal2 $ decide takeOrDrop) patches_to_skip -- | Undecide the current patch. postponeNext :: Commute p => InteractiveSelectionM p wX wY () postponeNext = do Just (Sealed2 lp) <- currentPatch modifyChoices $ forceMiddle (label lp) -- | Focus the next patch. skipOne :: InteractiveSelectionM p wX wY () skipOne = modify so where so x = x{lps = right (lps x), current = current x +1} -- | Focus the previous patch. backOne :: InteractiveSelectionM p wX wY () backOne = modify so where so isc = isc{lps = left (lps isc), current = max (current isc-1) 0} -- | Split the current patch (presumably a hunk), and add the replace it -- with its parts. splitCurrent :: Splitter p -> InteractiveSelectionM p wX wY () splitCurrent s = do FZipper lps_done (lp:>:lps_todo) <- gets lps case applySplitter s (unLabel lp) of Nothing -> return () Just (text, parse) -> do newText <- liftIO $ editText "darcs-patch-edit" text case parse newText of Nothing -> return () Just ps -> do lps_new <- liftIO $ return $ labelPatches (Just (label lp)) ps modify $ \isc -> isc { total = total isc + lengthFL lps_new - 1 , lps = FZipper lps_done (lps_new +>+ lps_todo) , choices = substitute (seal2 (lp :||: lps_new)) (choices isc) } -- | Shows the patch that is actually being selected the way the user -- should see it. repr :: Invert p => WhichChanges -> LabelledPatch p wX wY -> Sealed2 p repr w p | reversed w = Sealed2 (invert (unLabel p)) | otherwise = Sealed2 (unLabel p) -- | Returns a list of the currently selected patches, in -- their original context, i.e., not commuted past unselected -- patches. selected :: (Commute p, Invert p) => InteractiveSelectionM p wX wY [Sealed2 p] selected = do w <- asks whichChanges chs <- gets choices (first_chs :> _ :> last_chs) <- return $ getChoices chs return $ if backward w then mapFL (repr w) last_chs else mapFL (repr w) first_chs -- | Prints the list of the selected patches. See 'selected'. printSelected :: (Invert p, Commute p, ShowPatch p) => InteractiveSelectionM p wX wY () printSelected = do someThings <- things o <- asks opts s <- selected liftIO $ do putDocLnWith fancyPrinters $ greenText $ "---- selected "++someThings++" ----" mapM_ (putDocLnWith fancyPrinters . unseal2 (showFriendly (verbosity o) (summary o))) s putDocLnWith fancyPrinters $ greenText $ "---- end of selected "++someThings++" ----" printSummary :: ShowPatch p => p wX wY -> IO () printSummary = putDocLn . prefix " " . Darcs.Patch.summary -- | Skips all remaining patches. skipAll :: InteractiveSelectionM p wX wY () skipAll = modify $ \isc -> isc {lps = toEnd $ lps isc} backAll :: InteractiveSelectionM p wX wY () backAll = modify $ \isc -> isc {lps = toStart $ lps isc ,current = 0} isSingleFile :: PatchInspect p => p wX wY -> Bool isSingleFile p = length (listTouchedFiles p) == 1 askConfirmation :: InteractiveSelectionM p wX wY () askConfirmation = do jn <- asks jobname liftIO $ when (jn `elem` ["unpull", "unrecord", "obliterate"]) $ do yorn <- askUser $ "Really " ++ jn ++ " all undecided patches? " case yorn of ('y':_) -> return () _ -> exitSuccess -- | The singular form of the noun for items of type @p@. thing :: (ShowPatch p) => InteractiveSelectionM p wX wY String thing = (Darcs.Patch.thing . helper) `liftM` gets choices where helper :: PatchChoices p wA wB -> p wA wB helper = undefined -- | The plural form of the noun for items of type @p@. things :: (ShowPatch p) => InteractiveSelectionM p wX wY String things = (Darcs.Patch.things . helper) `liftM` gets choices where helper :: PatchChoices p wA wB -> p wA wB helper = undefined -- | The question to ask about one patch. prompt :: (ShowPatch p) => InteractiveSelectionM p wX wY String prompt = do jn <- asks jobname aThing <- thing n <- gets current n_max <- gets total return $ "Shall I "++jn++" this "++aThing++"? " ++ "(" ++ show (n+1) ++ "/" ++ show n_max ++ ") " -- | Asks the user about one patch, returns their answer. promptUser :: (ShowPatch p) => Bool -> Char -> InteractiveSelectionM p wX wY Char promptUser single def = do thePrompt <- prompt (basicOptions,advancedOptions) <- options single liftIO $ promptChar PromptConfig { pPrompt = thePrompt , pBasicCharacters = keysFor basicOptions , pAdvancedCharacters = keysFor advancedOptions , pDefault = Just def , pHelp = "?h" } -- | Ask the user what to do with the next patch. textSelectOne :: ( Invert p, Commute p, ShowPatch p, ShowContextPatch p, PatchInspect p , ApplyState p ~ Tree ) => InteractiveSelectionM p wX wY Bool textSelectOne = do c <- currentPatch case c of Nothing -> return False Just (Sealed2 lp) -> do jn <- asks jobname spl <- asks splitter whichch <- asks whichChanges let singleFile = isSingleFile (unLabel lp) reprCur = repr whichch lp (basicOptions,advancedOptions) <- options singleFile theSlot <- liftChoices $ state $ patchSlot lp let the_default = getDefault (backward whichch) theSlot yorn <- promptUser singleFile the_default let nextPatch = skipMundane >> showCur case yorn of 'y' -> decide True lp >> skipOne >> nextPatch >> return False 'n' -> decide False lp >> skipOne >> nextPatch >> return False 'w' -> postponeNext >> skipOne >> nextPatch >> return False 'e' | (Just s) <- spl -> splitCurrent s >> showCur >> return False 's' -> currentFile >>= maybe (return ()) (\f -> decideWholeFile f False) >> nextPatch >> return False 'f' -> currentFile >>= maybe (return ()) (\f -> decideWholeFile f True) >> nextPatch >> return False 'v' -> liftIO $ unseal2 printPatch reprCur >> return False 'p' -> liftIO $ unseal2 printPatchPager reprCur >> return False 'l' -> printSelected >> showCur >> return False 'x' -> liftIO $ unseal2 printSummary reprCur >> return False 'd' -> skipAll >> return True 'g' -> backAll >> showCur >> return False 'a' -> do askConfirmation modifyChoices $ selectAllMiddles (backward whichch) skipAll return True 'q' -> liftIO $ do putStrLn $ capitalize jn ++ " cancelled." exitSuccess 'j' -> skipOne >> showCur >> return False 'k' -> backOne >> showCur >> return False _ -> do liftIO . putStrLn $ helpFor jn basicOptions advancedOptions return False lastQuestion :: (Commute p, Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) => InteractiveSelectionM p wX wY Bool lastQuestion = do jn <- asks jobname theThings <-things aThing <- thing let (basicOptions, advancedOptions) = optionsLast jn aThing yorn <- liftIO . promptChar $ PromptConfig { pPrompt = "Do you want to "++capitalize jn++ " these "++theThings++"?" , pBasicCharacters = "yglqk" , pAdvancedCharacters = "dan" , pDefault = Just 'y' , pHelp = "?h"} case yorn of c | c `elem` "yda" -> return True | c `elem` "qn" -> liftIO $ do putStrLn $ jn ++" cancelled." exitSuccess 'g' -> backAll >> showCur >> return False 'l' -> printSelected >> return False 'k' -> backOne >> showCur >> return False _ -> do liftIO . putStrLn $ helpFor "this confirmation prompt" basicOptions advancedOptions return False -- | Shows the current patch as it should be seen by the user. showCur :: (Invert p, ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) => InteractiveSelectionM p wX wY () showCur = do o <- asks opts p <- asks pristine c <- currentPatch whichch <- asks whichChanges case c of Nothing -> return () Just (Sealed2 lp) -> do let reprCur = repr whichch lp liftIO . unseal2 (printFriendly p (verbosity o) (summary o) (withContext o)) $ reprCur -- | The interactive part of @darcs changes@ textView :: (ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) => PatchSelectionOptions -> Maybe Int -> Int -> [Sealed2 p] -> [Sealed2 p] -> IO () textView _ _ _ _ [] = return () textView o n_max n ps_done ps_todo@(p:ps_todo') = do unseal2 (printFriendly Nothing (verbosity o) (summary o) (withContext o)) p repeatThis -- prompt the user where prev_patch :: IO () prev_patch = case ps_done of [] -> repeatThis (p':ps_done') -> textView o n_max (n-1) ps_done' (p':ps_todo) next_patch :: IO () next_patch = case ps_todo' of [] -> -- May as well work out the length now we have all -- the patches in memory textView o n_max n ps_done [] _ -> textView o n_max (n+1) (p:ps_done) ps_todo' first_patch = textView o n_max 0 [] (ps_done++ps_todo) options_yn = [ KeyPress 'y' "view this patch and go to the next" , KeyPress 'n' "skip to the next patch" ] optionsView' = [ KeyPress 'v' "view this patch in full" , KeyPress 'p' "view this patch in full with pager" ] optionsSummary' = [ KeyPress 'x' "view a summary of this patch" ] optionsNav' = [ KeyPress 'q' "quit view changes" , KeyPress 'k' "back up to previous patch" , KeyPress 'j' "skip to next patch" , KeyPress 'g' "start over from the first patch" , KeyPress 'c' "count total patch number" ] basicOptions = [ options_yn ] advancedOptions = (optionsView' ++ if summary o == YesSummary then [] else optionsSummary') : [ optionsNav' ] prompt' = "Shall I view this patch? " ++ "(" ++ show (n+1) ++ "/" ++ maybe "?" show n_max ++ ")" repeatThis :: IO () repeatThis = do yorn <- promptChar (PromptConfig prompt' (keysFor basicOptions) (keysFor advancedOptions) (Just 'n') "?h") case yorn of 'y' -> unseal2 printPatch p >> next_patch 'n' -> next_patch 'v' -> unseal2 printPatch p >> repeatThis 'p' -> unseal2 printPatchPager p >> repeatThis 'x' -> do putDocLn $ prefix " " $ unseal2 Darcs.Patch.summary p repeatThis 'q' -> exitSuccess 'k' -> prev_patch 'j' -> next_patch 'g' -> first_patch 'c' -> textView o count_n_max n ps_done ps_todo _ -> do putStrLn $ helpFor "view changes" basicOptions advancedOptions repeatThis count_n_max | isJust n_max = n_max | otherwise = Just $ length ps_done + length ps_todo -- | Skips patches we should not ask the user about skipMundane :: (Commute p, ShowPatch p) => InteractiveSelectionM p wX wY () skipMundane = do (FZipper lps_done lps_todo) <- gets lps o <- asks opts crit <- asks matchCriterion jn <- asks jobname whichch <- asks whichChanges (skipped :> unskipped) <- liftChoices $ spanFL_M (state . patchSlot >=> return . decided) lps_todo let numSkipped = lengthFL skipped when (numSkipped > 0) . liftIO $ show_skipped o jn numSkipped skipped let boringThenInteresting = if selectDeps o == AutoDeps then spanFL (not. mcFunction crit whichch) unskipped else NilFL :> unskipped case boringThenInteresting of boring :> interesting -> do justDone $ lengthFL boring + numSkipped modify $ \isc -> isc {lps = FZipper (lps_done +<<+ skipped +<<+ boring) interesting} where show_skipped o jn n ps = do putStrLn $ _nevermind_ jn ++ _these_ n ++ "." when (verbosity o == Verbose) $ showskippedpatch ps _nevermind_ jn = "Will not ask whether to " ++ jn ++ " " _these_ n = show n ++ " already decided " ++ _elem_ n "" _elem_ n = englishNum n (Noun "patch") showskippedpatch :: ShowPatch p => FL (LabelledPatch p) wY wT -> IO () showskippedpatch = sequence_ . mapFL (printSummary . unLabel) decided :: Slot -> Bool decided InMiddle = False decided _ = True -- | The action bound to space, depending on the current status of the -- patch. getDefault :: Bool -> Slot -> Char getDefault _ InMiddle = 'w' getDefault True InFirst = 'n' getDefault True InLast = 'y' getDefault False InFirst = 'y' getDefault False InLast = 'n' askAboutDepends :: (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wT -> FL (PrimOf p) wT wY -> PatchSelectionOptions -> [PatchInfo] -> IO [PatchInfo] askAboutDepends repository pa' ps_opts olddeps = do -- ideally we'd just default the olddeps to yes but still ask about them. -- SelectChanges doesn't currently (17/12/09) offer a way to do this so would -- have to have this support added first. pps <- readTentativeRepo repository (repoLocation repository) pa <- n2pia `fmap` anonymous (fromPrims pa') -- FIXME: this code is completely unreadable FlippedSeal ps <- return $ case pps of PatchSet _ x -> FlippedSeal (x+>>+(pa:>:NilFL)) let my_lps = labelPatches Nothing ps pc = mkPatchChoices my_lps tas = case catMaybes (mapFL (\lp -> if pa `unsafeCompare` unLabel lp || info (unLabel lp) `elem` olddeps then Just (label lp) else Nothing) my_lps) of [] -> error "askAboutDepends: []" tgs -> tgs Sealed2 ps' <- return $ case getChoices (forceFirsts tas pc) of _ :> mc :> _ -> Sealed2 $ mapFL_FL unLabel mc (deps:>_) <- runSelection ps' $ selectionContext FirstReversed "depend on" ps_opts { matchFlags = [], interactive = True } Nothing Nothing return $ olddeps `union` mapFL info deps darcs-2.14.5/src/Darcs/UI/TheCommands.hs0000644000000000000000000001007607346545000015772 0ustar0000000000000000-- Copyright (C) 2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.UI.TheCommands ( commandControlList ) where import Prelude () import Darcs.UI.Commands.Add ( add ) import Darcs.UI.Commands.Amend ( amend, amendrecord ) import Darcs.UI.Commands.Annotate ( annotate ) import Darcs.UI.Commands.Apply ( apply ) import Darcs.UI.Commands.Clone ( clone, get, put ) import Darcs.UI.Commands.Convert ( convert ) import Darcs.UI.Commands.Diff ( diffCommand ) import Darcs.UI.Commands.Dist ( dist ) import Darcs.UI.Commands.GZCRCs ( gzcrcs ) import Darcs.UI.Commands.Init ( initialize ) import Darcs.UI.Commands.Log ( log, changes ) import Darcs.UI.Commands.Show ( showCommand ) import Darcs.UI.Commands.MarkConflicts ( markconflicts ) import Darcs.UI.Commands.Move ( move, mv ) import Darcs.UI.Commands.Optimize ( optimize ) import Darcs.UI.Commands.Pull ( pull, fetch ) import Darcs.UI.Commands.Push ( push ) import Darcs.UI.Commands.Rebase ( rebase ) import Darcs.UI.Commands.Record ( record, commit ) import Darcs.UI.Commands.Remove ( remove, rm, unadd ) import Darcs.UI.Commands.Repair ( repair, check ) import Darcs.UI.Commands.Replace ( replace ) import Darcs.UI.Commands.Revert ( revert ) import Darcs.UI.Commands.Rollback ( rollback ) import Darcs.UI.Commands.Send ( send ) import Darcs.UI.Commands.SetPref ( setpref ) import Darcs.UI.Commands.Tag ( tag ) import Darcs.UI.Commands.Test ( test ) import Darcs.UI.Commands.TransferMode ( transferMode ) import Darcs.UI.Commands.Unrecord ( unrecord, unpull, obliterate ) import Darcs.UI.Commands.Unrevert ( unrevert ) import Darcs.UI.Commands.WhatsNew ( whatsnew, status ) import Darcs.UI.Commands ( CommandControl, normalCommand, hiddenCommand, commandGroup ) -- | The commands that darcs knows about (e.g. whatsnew, record), -- organized into thematic groups. Note that hidden commands -- are also listed here. commandControlList :: [CommandControl] commandControlList = [ commandGroup "Most used/starting out:" , normalCommand initialize , normalCommand add , normalCommand whatsnew, hiddenCommand status , normalCommand record, hiddenCommand commit , normalCommand clone, hiddenCommand get, hiddenCommand put , normalCommand pull , normalCommand push , commandGroup "Preparing patches before recording:" , normalCommand move, hiddenCommand mv , normalCommand remove, hiddenCommand unadd, hiddenCommand rm , normalCommand replace , commandGroup "Querying the repository:" , normalCommand log, hiddenCommand changes , normalCommand annotate , normalCommand diffCommand , normalCommand showCommand , normalCommand test , commandGroup "Undoing and correcting:" , normalCommand revert , normalCommand unrevert , normalCommand amend, hiddenCommand amendrecord , normalCommand rebase , normalCommand rollback , normalCommand unrecord , normalCommand obliterate, hiddenCommand unpull , commandGroup "Direct modification of the repository:" , normalCommand tag , normalCommand setpref , commandGroup "Exchanging patches by e-mail:" , normalCommand send , normalCommand apply , commandGroup "Other commands:" , normalCommand optimize , normalCommand dist , normalCommand markconflicts , normalCommand repair, hiddenCommand check , normalCommand convert , normalCommand fetch , hiddenCommand gzcrcs , hiddenCommand transferMode ] darcs-2.14.5/src/Darcs/UI/Usage.hs0000644000000000000000000001610707346545000014635 0ustar0000000000000000-- | This module provides a variant of 'System.Console.GetOpt.usageInfo'. -- -- Unlike the standard @usageInfo@ function, lists of long switches are broken -- across multiple lines to economise on columns. For example, -- -- @ -- -r --recursive add contents of subdirectories -- --not-recursive, -- --no-recursive don't add contents of subdirectories -- @ {-# LANGUAGE OverloadedStrings #-} module Darcs.UI.Usage ( usageInfo , formatOptions , getCommandHelp , getCommandMiniHelp , usage , subusage ) where import Prelude () import Darcs.Prelude import Data.Functor.Compose import System.Console.GetOpt( OptDescr(..), ArgDescr(..) ) import Darcs.UI.Options.All ( stdCmdActions ) import Darcs.UI.Commands ( CommandControl(..) , DarcsCommand(..) , wrappedCommandName , wrappedCommandDescription , getSubcommands , commandAlloptions ) import Darcs.UI.Options ( DarcsOptDescr, odesc ) import Darcs.Util.Printer ( Doc, text, vsep, ($$), vcat, hsep , renderString ) formatOptions :: [DarcsOptDescr a] -> [String] formatOptions optDescrs = table where (ss,ls,ds) = (unzip3 . concatMap fmtOpt) optDescrs table = zipWith3 paste shortPadded (zipWith (++) (map (unlines' . init) ls) (sameLen $ map last ls)) ds shortPadded = sameLen ss prePad = replicate (3 + length (head shortPadded)) ' ' -- Similar to unlines (additional ',' and padding): unlines' = concatMap (\x -> x ++ ",\n" ++ prePad) -- Unchanged: paste x y z = " " ++ x ++ " " ++ y ++ " " ++ z sameLen xs = flushLeft ((maximum . map length) xs) xs flushLeft n xs = [ take n (x ++ repeat ' ') | x <- xs ] -- | Variant of 'System.Console.GetOpt.usageInfo'. -- Return a string describing the usage of a command, derived from the header -- (first argument) and the options described by the second argument. -- -- Sequences of long switches are presented on separate lines. usageInfo :: String -- header -> [DarcsOptDescr a] -- option descriptors -> String -- nicely formatted decription of options usageInfo header optDescrs = unlines (header:formatOptions optDescrs) -- Mild variant of the standard definition: 'losFmt' is a list rather than a -- comma separated string. fmtOpt :: DarcsOptDescr a -> [(String,[String],String)] fmtOpt (Compose (Option sos los ad descr)) = case lines descr of [] -> [(sosFmt,losFmt,"")] (d:ds) -> (sosFmt,losFmt,d) : [ ("",[],d') | d' <- ds ] where endBy _ [] = "" endBy ch [x] = x ++ [ch] endBy ch (x:xs) = x ++ ch:' ':endBy ch xs sosFmt = endBy ',' (map fmtShort sos) losFmt = map (fmtLong ad) los -------------------------------------------------------------------------------- -- Verbatim copies: these definitions aren't exported by System.Console.GetOpt -------------------------------------------------------------------------------- fmtShort :: Char -> String fmtShort so = "-" ++ [so] fmtLong :: ArgDescr a -> String -> String fmtLong (NoArg _ ) lo = "--" ++ lo fmtLong (ReqArg _ ad) lo = "--" ++ lo ++ "=" ++ ad fmtLong (OptArg _ ad) lo = "--" ++ lo ++ "[=" ++ ad ++ "]" -------------------------------------------------------------------------------- usage :: [CommandControl] -> Doc usage cs = vsep [ "Usage: darcs COMMAND ..." , "Commands:" $$ usageHelper cs , vcat [ "Use 'darcs COMMAND --help' for help on a single command." , "Use 'darcs --version' to see the darcs version number." , "Use 'darcs --exact-version' to see a detailed darcs version." , "Use 'darcs help patterns' for help on patch matching." , "Use 'darcs help environment' for help on environment variables." , "Use 'darcs help manpage' to display help in the manpage format." , "Use 'darcs help markdown' to display help in the markdown format." ] , "Check bug reports at http://bugs.darcs.net/" ] subusage :: DarcsCommand pf -> String subusage super = renderString $ vsep [ header , subcommandsHelp , vcat $ map text $ formatOptions $ odesc stdCmdActions , text $ commandHelp super ] where usageHelp = hsep $ map text [ "Usage:" , commandProgramName super , commandName super , "SUBCOMMAND ..." ] header = usageHelp $$ text (commandDescription super) subcommandsHelp = case getSubcommands super of [] -> mempty subcommands -> usageHelper subcommands usageHelper :: [CommandControl] -> Doc usageHelper xs = vsep (groups xs) where groups [] = [] groups (HiddenCommand _:cs) = groups cs groups (GroupName n:cs) = mempty : case groups cs of [] -> [text n] (g:gs) -> (text n $$ g) : gs groups (CommandData c:cs) = case groups cs of [] -> [cmdHelp c] (g:gs) -> (cmdHelp c $$ g) : gs cmdHelp c = text $ " " ++ padSpaces maxwidth (wrappedCommandName c) ++ wrappedCommandDescription c padSpaces n s = s ++ replicate (n - length s) ' ' maxwidth = maximum $ 15 : (map cwidth xs) cwidth (CommandData c) = length (wrappedCommandName c) + 2 cwidth _ = 0 getCommandMiniHelp :: Maybe (DarcsCommand pf1) -> DarcsCommand pf2 -> String getCommandMiniHelp msuper cmd = renderString $ vsep [ getCommandHelpCore msuper cmd , hsep $ map text [ "See" , commandProgramName cmd , "help" , maybe "" ((++ " ") . commandName) msuper ++ commandName cmd , "for details." ] ] getCommandHelp :: Maybe (DarcsCommand pf1) -> DarcsCommand pf2 -> Doc getCommandHelp msuper cmd = vsep [ getCommandHelpCore msuper cmd , subcommandsHelp , withHeading "Options:" basicOptionsHelp , withHeading "Advanced options:" advancedOptionsHelp , text $ commandHelp cmd ] where withHeading _ [] = mempty withHeading h ls = vcat (text h : map text ls) (basic, advanced) = commandAlloptions cmd -- call formatOptions with combined options so that -- both get the same formatting (basicOptionsHelp, advancedOptionsHelp) = splitAt (length basic) $ formatOptions (basic ++ advanced) subcommandsHelp = case msuper of Nothing -> case getSubcommands cmd of [] -> mempty subcommands -> usageHelper subcommands -- we don't want to list subcommands if we're already specifying them Just _ -> mempty getCommandHelpCore :: Maybe (DarcsCommand pf1) -> DarcsCommand pf2 -> Doc getCommandHelpCore msuper cmd = vcat [ hsep $ [ "Usage:" , text $ commandProgramName cmd , maybe mempty (text . commandName) msuper , text $ commandName cmd , "[OPTION]..." ] ++ args_help , text $ commandDescription cmd ] where args_help = case cmd of (DarcsCommand {}) -> map text $ commandExtraArgHelp cmd _ -> [] darcs-2.14.5/src/Darcs/Util/0000755000000000000000000000000007346545000013630 5ustar0000000000000000darcs-2.14.5/src/Darcs/Util/AtExit.hs0000644000000000000000000000506007346545000015363 0ustar0000000000000000-- Copyright (C) 2005 Tomasz Zielonka -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | -- Module : Darcs.Util.AtExit -- Copyright : 2005 Tomasz Zielonka -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable -- -- This was originally Tomasz Zielonka's AtExit module, slightly generalised -- to include global variables. Here, we attempt to cover broad, global -- features, such as exit handlers. These features slightly break the Haskellian -- purity of darcs, in favour of programming convenience. module Darcs.Util.AtExit ( atexit , withAtexit ) where import Prelude () import Darcs.Prelude import Control.Concurrent.MVar import Control.Exception ( bracket_, catch, SomeException , mask ) import System.IO.Unsafe (unsafePerformIO) import System.IO ( hPutStrLn, stderr, hPrint ) atexitActions :: MVar (Maybe [IO ()]) atexitActions = unsafePerformIO (newMVar (Just [])) {-# NOINLINE atexitActions #-} -- | Registers an IO action to run just before darcs exits. Useful for removing -- temporary files and directories, for example. Referenced in Issue1914. atexit :: IO () -> IO () atexit action = modifyMVar_ atexitActions $ \ml -> case ml of Just l -> return (Just (action : l)) Nothing -> do hPutStrLn stderr "It's too late to use atexit" return Nothing withAtexit :: IO a -> IO a withAtexit = bracket_ (return ()) exit where exit = mask $ \unmask -> do Just actions <- swapMVar atexitActions Nothing -- from now on atexit will not register new actions mapM_ (runAction unmask) actions runAction unmask action = catch (unmask action) $ \(exn :: SomeException) -> do hPutStrLn stderr "Exception thrown by an atexit registered action:" hPrint stderr exn darcs-2.14.5/src/Darcs/Util/ByteString.hs0000644000000000000000000003611007346545000016257 0ustar0000000000000000{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | -- Module : Darcs.Util.ByteString -- Copyright : (c) The University of Glasgow 2001, -- David Roundy 2003-2005 -- License : GPL (I'm happy to also license this file BSD style but don't -- want to bother distributing two license files with darcs. -- -- Maintainer : droundy@abridgegame.org -- Stability : experimental -- Portability : portable -- -- GZIp and MMap IO for ByteStrings, encoding utilities, and miscellaneous -- functions for Data.ByteString -- module Darcs.Util.ByteString ( -- * IO with mmap or gzip gzReadFilePS , mmapFilePS , gzWriteFilePS , gzWriteFilePSs , gzReadStdin , gzWriteHandle , FileSegment , readSegment -- * gzip handling , isGZFile , gzDecompress -- * list utilities , dropSpace , breakSpace , linesPS , unlinesPS , hashPS , breakFirstPS , breakLastPS , substrPS , readIntPS , isFunky , fromHex2PS , fromPS2Hex , betweenLinesPS , intercalate -- * encoding and unicode utilities , isAscii , decodeLocale , encodeLocale , unpackPSFromUTF8 , packStringToUTF8 -- * properties , prop_unlinesPS_linesPS_left_inverse , prop_linesPS_length , prop_unlinesPS_length , propHexConversion , spec_betweenLinesPS ) where import Prelude () import Darcs.Prelude import Codec.Binary.Base16 ( b16Enc, b16Dec ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Lazy as BL import Data.ByteString (intercalate) import System.IO ( withFile, IOMode(ReadMode) , hSeek, SeekMode(SeekFromEnd,AbsoluteSeek) , openBinaryFile, hClose, Handle, hGetChar , stdin) import System.IO.Error ( catchIOError ) import System.IO.Unsafe ( unsafePerformIO ) import Data.Bits ( rotateL ) import Data.Char ( ord, isSpace, toLower, toUpper ) import Data.Word ( Word8 ) import Data.Int ( Int32, Int64 ) import Data.List ( intersperse ) import Control.Monad ( when ) import Control.Monad.ST.Lazy ( ST ) import qualified Codec.Compression.GZip as GZ import qualified Codec.Compression.Zlib.Internal as ZI import Darcs.Util.Encoding ( decode, encode, decodeUtf8, encodeUtf8 ) import Darcs.Util.Global ( addCRCWarning ) #if mingw32_HOST_OS #else import System.IO.MMap( mmapFileByteString ) #endif import System.Mem( performGC ) import System.Posix.Files( fileSize, getSymbolicLinkStatus ) -- | readIntPS skips any whitespace at the beginning of its argument, and -- reads an Int from the beginning of the PackedString. If there is no -- integer at the beginning of the string, it returns Nothing, otherwise it -- just returns the int read, along with a B.ByteString containing the -- remainder of its input. readIntPS :: B.ByteString -> Maybe (Int, B.ByteString) readIntPS = BC.readInt . BC.dropWhile isSpace ------------------------------------------------------------------------ -- A locale-independent isspace(3) so patches are interpreted the same everywhere. -- ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r') isSpaceWord8 :: Word8 -> Bool isSpaceWord8 = (`elem` [0x20, 0x09, 0x0A, 0x0D]) {-# INLINE isSpaceWord8 #-} -- | Drop leading white space, where white space is defined as -- consisting of ' ', '\t', '\n', or '\r'. dropSpace :: B.ByteString -> B.ByteString dropSpace bs = B.dropWhile isSpaceWord8 bs -- | Split at first occurrence of ' ', '\t', '\n', or '\r'. breakSpace :: B.ByteString -> (B.ByteString, B.ByteString) breakSpace bs = B.break isSpaceWord8 bs ------------------------------------------------------------------------ {-# INLINE isFunky #-} isFunky :: B.ByteString -> Bool isFunky ps = 0 `B.elem` ps || 26 `B.elem` ps ------------------------------------------------------------------------ {-# INLINE hashPS #-} hashPS :: B.ByteString -> Int32 hashPS = B.foldl' hashByte 0 {-# INLINE hashByte #-} hashByte :: Int32 -> Word8 -> Int32 hashByte h x = fromIntegral x + rotateL h 8 {-# INLINE substrPS #-} substrPS :: B.ByteString -> B.ByteString -> Maybe Int substrPS tok str | B.null tok = Just 0 | B.length tok > B.length str = Nothing | otherwise = do n <- B.elemIndex (B.head tok) str let ttok = B.tail tok reststr = B.drop (n+1) str if ttok == B.take (B.length ttok) reststr then Just n else ((n+1)+) `fmap` substrPS tok reststr ------------------------------------------------------------------------ -- TODO: replace breakFirstPS and breakLastPS with definitions based on -- ByteString's break/breakEnd {-# INLINE breakFirstPS #-} breakFirstPS :: Char -> B.ByteString -> Maybe (B.ByteString,B.ByteString) breakFirstPS c p = case BC.elemIndex c p of Nothing -> Nothing Just n -> Just (B.take n p, B.drop (n+1) p) {-# INLINE breakLastPS #-} breakLastPS :: Char -> B.ByteString -> Maybe (B.ByteString,B.ByteString) breakLastPS c p = case BC.elemIndexEnd c p of Nothing -> Nothing Just n -> Just (B.take n p, B.drop (n+1) p) ------------------------------------------------------------------------ -- linesPS and unlinesPS {-# INLINE linesPS #-} linesPS :: B.ByteString -> [B.ByteString] linesPS ps | B.null ps = [B.empty] | otherwise = BC.split '\n' ps {-# INLINE unlinesPS #-} unlinesPS :: [B.ByteString] -> B.ByteString unlinesPS [] = B.empty unlinesPS x = B.concat $ intersperse (BC.singleton '\n') x -- properties of linesPS and unlinesPS prop_unlinesPS_linesPS_left_inverse :: B.ByteString -> Bool prop_unlinesPS_linesPS_left_inverse x = unlinesPS (linesPS x) == x prop_linesPS_length :: B.ByteString -> Bool prop_linesPS_length x = length (linesPS x) == length (BC.elemIndices '\n' x) + 1 prop_unlinesPS_length :: [B.ByteString] -> Bool prop_unlinesPS_length xs = B.length (unlinesPS xs) == if null xs then 0 else sum (map B.length xs) + length xs - 1 -- ----------------------------------------------------------------------------- -- gzReadFilePS -- |Decompress the given bytestring into a lazy list of chunks, along with a boolean -- flag indicating (if True) that the CRC was corrupted. -- Inspecting the flag will cause the entire list of chunks to be evaluated (but if -- you throw away the list immediately this should run in constant space). gzDecompress :: Maybe Int -> BL.ByteString -> ([B.ByteString], Bool) gzDecompress mbufsize = -- This is what the code would be without the bad CRC recovery logic: -- return . BL.toChunks . GZ.decompressWith decompressParams decompressWarn (ZI.decompressST ZI.gzipFormat decompressParams) where decompressParams = case mbufsize of Just bufsize -> GZ.defaultDecompressParams { GZ.decompressBufferSize = bufsize } Nothing -> GZ.defaultDecompressParams decompressWarn :: (forall s . ZI.DecompressStream (ST s)) -> BL.ByteString -> ([B.ByteString], Bool) decompressWarn = ZI.foldDecompressStreamWithInput (\x ~(xs, b) -> (x:xs, b)) (\xs -> if BL.null xs then ([], False) else error "trailing data at end of compressed stream" ) handleBad -- For a while a bug in darcs caused gzip files with good data but bad CRCs to be -- produced. Trap bad CRC messages, run the specified action to report that it happened, -- but continue on the assumption that the data is valid. handleBad (ZI.DataFormatError "incorrect data check") = ([], True) handleBad e = error (show e) isGZFile :: FilePath -> IO (Maybe Int) isGZFile f = do h <- openBinaryFile f ReadMode header <- B.hGet h 2 if header /= B.pack [31,139] then do hClose h return Nothing else do hSeek h SeekFromEnd (-4) len <- hGetLittleEndInt h hClose h return (Just len) -- | Read an entire file, which may or may not be gzip compressed, directly -- into a 'B.ByteString'. gzReadFilePS :: FilePath -> IO B.ByteString gzReadFilePS f = do mlen <- isGZFile f case mlen of Nothing -> mmapFilePS f Just len -> do -- Passing the length to gzDecompress means that it produces produces one chunk, -- which in turn means that B.concat won't need to copy data. -- If the length is wrong this will just affect efficiency, not correctness let doDecompress buf = let (res, bad) = gzDecompress (Just len) buf in do when bad $ addCRCWarning f return res compressed <- (BL.fromChunks . return) `fmap` mmapFilePS f B.concat `fmap` doDecompress compressed hGetLittleEndInt :: Handle -> IO Int hGetLittleEndInt h = do b1 <- ord `fmap` hGetChar h b2 <- ord `fmap` hGetChar h b3 <- ord `fmap` hGetChar h b4 <- ord `fmap` hGetChar h return $ b1 + 256*b2 + 65536*b3 + 16777216*b4 gzWriteFilePS :: FilePath -> B.ByteString -> IO () gzWriteFilePS f ps = gzWriteFilePSs f [ps] gzWriteFilePSs :: FilePath -> [B.ByteString] -> IO () gzWriteFilePSs f pss = BL.writeFile f $ GZ.compress $ BL.fromChunks pss gzWriteHandle :: Handle -> [B.ByteString] -> IO () gzWriteHandle h pss = BL.hPut h $ GZ.compress $ BL.fromChunks pss -- | Read standard input, which may or may not be gzip compressed, directly -- into a 'B.ByteString'. gzReadStdin :: IO B.ByteString gzReadStdin = do header <- B.hGet stdin 2 rest <- B.hGetContents stdin let allStdin = B.concat [header,rest] return $ if header /= B.pack [31,139] then allStdin else let decompress = fst . gzDecompress Nothing compressed = BL.fromChunks [allStdin] in B.concat $ decompress compressed -- | Pointer to a filesystem, possibly with start/end offsets. Supposed to be -- fed to (uncurry mmapFileByteString) or similar. type FileSegment = (FilePath, Maybe (Int64, Int)) -- | Read in a FileSegment into a Lazy ByteString. Implemented using mmap. readSegment :: FileSegment -> IO BL.ByteString readSegment (f,range) = do bs <- tryToRead `catchIOError` (\_ -> do size <- fileSize `fmap` getSymbolicLinkStatus f if size == 0 then return B.empty else performGC >> tryToRead) return $ BL.fromChunks [bs] where tryToRead = case range of Nothing -> B.readFile f Just (off, size) -> withFile f ReadMode $ \h -> do hSeek h AbsoluteSeek $ fromIntegral off B.hGet h size {-# INLINE readSegment #-} -- ----------------------------------------------------------------------------- -- mmapFilePS -- | Like readFilePS, this reads an entire file directly into a -- 'B.ByteString', but it is even more efficient. It involves directly -- mapping the file to memory. This has the advantage that the contents of -- the file never need to be copied. Also, under memory pressure the page -- may simply be discarded, wile in the case of readFilePS it would need to -- be written to swap. If you read many small files, mmapFilePS will be -- less memory-efficient than readFilePS, since each mmapFilePS takes up a -- separate page of memory. Also, you can run into bus errors if the file -- is modified. mmapFilePS :: FilePath -> IO B.ByteString #if mingw32_HOST_OS mmapFilePS = B.readFile #else mmapFilePS f = mmapFileByteString f Nothing `catchIOError` (\_ -> do size <- fileSize `fmap` getSymbolicLinkStatus f if size == 0 then return B.empty else performGC >> mmapFileByteString f Nothing) #endif -- ------------------------------------------------------------------------- -- fromPS2Hex fromPS2Hex :: B.ByteString -> B.ByteString fromPS2Hex = BC.map toLower . b16Enc -- ------------------------------------------------------------------------- -- fromHex2PS fromHex2PS :: B.ByteString -> B.ByteString fromHex2PS s = case b16Dec $ BC.map toUpper s of Right (result, remaining) | B.null remaining -> result _ -> error "fromHex2PS: input is not hex encoded" propHexConversion :: B.ByteString -> Bool propHexConversion x = fromHex2PS (fromPS2Hex x) == x -- ------------------------------------------------------------------------- -- betweenLinesPS -- | Return the B.ByteString between the two lines given, -- or Nothing if they do not appear. betweenLinesPS :: B.ByteString -> B.ByteString -> B.ByteString -> Maybe B.ByteString betweenLinesPS start end ps = case B.breakSubstring start_line ps of (before_start, at_start) | not (B.null at_start) , B.null before_start || BC.last before_start == '\n' -> case B.breakSubstring end_line (B.drop (B.length start_line) at_start) of (before_end, at_end) | not (B.null at_end) , B.null before_end || BC.last before_end == '\n' -> Just before_end | otherwise -> Nothing | otherwise -> Nothing where start_line = BC.snoc start '\n' end_line = BC.snoc end '\n' -- | Simpler but less efficient variant of 'betweenLinesPS'. spec_betweenLinesPS :: B.ByteString -> B.ByteString -> B.ByteString -> Maybe B.ByteString spec_betweenLinesPS start end ps = case break (start ==) (linesPS ps) of (_, _:after_start) -> case break (end ==) after_start of (before_end, _:_) -> Just $ BC.unlines before_end _ -> Nothing _ -> Nothing -- | Test if a ByteString is made of ascii characters isAscii :: B.ByteString -> Bool isAscii = B.all (< 128) -- * Encoding functions -- Use of 'unsafePerformIO' is ratified by the fact that these -- really are pure functions. -- | Decode a 'ByteString' containing UTF-8 to a 'String'. Decoding errors -- are flagged with the U+FFFD character. unpackPSFromUTF8 :: B.ByteString -> String unpackPSFromUTF8 = unsafePerformIO . decodeUtf8 -- | Encode a 'String' to a 'ByteString' using UTF-8. packStringToUTF8 :: String -> B.ByteString packStringToUTF8 = unsafePerformIO . encodeUtf8 -- | Decode a 'ByteString' to a 'String' according to the current locale, -- using lone surrogates for un-decodable bytes. decodeLocale :: B.ByteString -> String decodeLocale = unsafePerformIO . decode -- | Encode a 'String' to a 'ByteString' according to the current locale, -- converting lone surrogates back to the original byte. If that -- fails (because the locale does not support the full unicode range) -- then encode using utf-8, assuming that the un-ecodable characters -- come from patch meta data. -- -- See also 'Darcs.UI.Commands.setEnvCautiously'. encodeLocale :: String -> B.ByteString encodeLocale s = unsafePerformIO $ encode s `catchIOError` (\_ -> encodeUtf8 s) darcs-2.14.5/src/Darcs/Util/CommandLine.hs0000644000000000000000000001011307346545000016346 0ustar0000000000000000-- Copyright (C) 2005 Benedikt Schmidt -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | -- Module : Darcs.Util.CommandLine -- Copyright : 2005 Benedikt Schmidt -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable -- -- |A parser for commandlines, returns an arg list and expands -- format strings given in a translation table. Additionally -- the commandline can end with "%<" specifying that the command -- expects input on stdin. -- -- See Darcs.Test.Misc.CommandLine for tests. module Darcs.Util.CommandLine ( parseCmd , addUrlencoded ) where import Prelude () import Darcs.Prelude import Control.Arrow ( (***) ) import Data.Char ( ord, intToDigit, toUpper ) import Data.List ( find ) import Text.ParserCombinators.Parsec -- | assoc list mapping characters to strings -- eg (c,s) means that %c is replaced by s type FTable = [(Char,String)] commandline :: FTable -> Parser ([String], Bool) commandline ftable = consumeAll $ do l <- sepEndBy1 (arg ftable) (try separator) redir <- formatRedir spaces return (l,redir) arg :: FTable -> Parser String arg ftable = quotedArg ftable <|> unquotedArg ftable unquotedArg :: FTable -> Parser String unquotedArg ftable = try (format ftable) <|> many1 (noneOf " \t\"%") quotedArg :: FTable -> Parser String quotedArg ftable = between quoteChar quoteChar $ quoteContent ftable where quoteChar = char '"' quoteContent :: FTable -> Parser String quoteContent ftable = do s1 <- escape <|> try (format ftable) <|> many1 (noneOf "\"\\%") s2 <- quoteContent ftable return $ s1 ++ s2 <|> return "" formatRedir :: Parser Bool formatRedir = (string "%<" >> return True) <|> return False format :: FTable -> Parser String format ftable = do _ <- char '%' c <- oneOf (map fst ftable) return $ expandFormat ftable c escape :: Parser String escape = do _ <- char '\\' c <- anyChar return [c] consumeAll :: Parser a -> Parser a consumeAll p = do r <- p eof return r separator :: Parser () separator = skipMany1 space expandFormat :: FTable -> Char -> String expandFormat ftable c = case find ((==c) . fst) ftable of Just (_,s) -> s Nothing -> error "impossible" -- | parse a commandline returning a list of strings -- (intended to be used as argv) and a bool value which -- specifies if the command expects input on stdin -- format specifiers with a mapping in ftable are accepted -- and replaced by the given strings. E.g. if the ftable is -- [('s',"Some subject")], then "%s" is replaced by "Some subject" parseCmd :: FTable -> String -> Either ParseError ([String],Bool) parseCmd ftable = parse (commandline ftable) "" urlEncode :: String -> String urlEncode = concatMap escapeC where escapeC x = if allowed x then [x] else '%' : intToHex (ord x) intToHex i = map intToDigit [i `div` 16, i `mod` 16] allowed x = x `elem` allowedChars allowedChars = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ "!'()*-.~" -- | for every mapping (c,s), add a mapping with uppercase c -- and the urlencoded string s addUrlencoded :: FTable -> FTable addUrlencoded ftable = ftable ++ map (toUpper *** urlEncode) ftable darcs-2.14.5/src/Darcs/Util/Compat.hs0000644000000000000000000001147307346545000015415 0ustar0000000000000000{-# LANGUAGE CPP, ForeignFunctionInterface #-} module Darcs.Util.Compat ( stdoutIsAPipe , mkStdoutTemp , canonFilename , maybeRelink , atomicCreate , sloppyAtomicCreate ) where import Prelude () import Darcs.Prelude import Darcs.Util.File ( withCurrentDirectory ) #ifdef WIN32 import Data.Bits ( (.&.) ) import System.Random ( randomIO ) import Numeric ( showHex ) #else #endif import Control.Monad ( unless ) import Foreign.C.Types ( CInt(..) ) import Foreign.C.String ( CString, withCString #ifndef WIN32 , peekCString #endif ) import Foreign.C.Error ( throwErrno, eEXIST, getErrno ) import System.Directory ( getCurrentDirectory ) import System.IO ( hFlush, stdout, stderr, hSetBuffering, BufferMode(NoBuffering) ) import System.IO.Error ( mkIOError, alreadyExistsErrorType ) import System.Posix.Files ( stdFileMode ) import System.Posix.IO ( openFd, closeFd, stdOutput, stdError, dupTo, defaultFileFlags, exclusive, OpenMode(WriteOnly) ) import System.Posix.Types ( Fd(..) ) import Darcs.Util.SignalHandler ( stdoutIsAPipe ) canonFilename :: FilePath -> IO FilePath canonFilename f@(_:':':_) = return f -- absolute windows paths canonFilename f@('/':_) = return f canonFilename ('.':'/':f) = do cd <- getCurrentDirectory return $ cd ++ "/" ++ f canonFilename f = case reverse $ dropWhile (/='/') $ reverse f of "" -> fmap (++('/':f)) getCurrentDirectory rd -> withCurrentDirectory rd $ do fd <- getCurrentDirectory return $ fd ++ "/" ++ simplefilename where simplefilename = reverse $ takeWhile (/='/') $ reverse f #ifdef WIN32 mkstempCore :: FilePath -> IO (Fd, String) mkstempCore fp = do r <- randomIO let fp' = fp ++ showHexLen 6 (r .&. 0xFFFFFF :: Int) fd <- openFd fp' WriteOnly (Just stdFileMode) flags return (fd, fp') where flags = defaultFileFlags { exclusive = True } showHexLen :: (Integral a, Show a) => Int -> a -> String showHexLen n x = let s = showHex x "" in replicate (n - length s) ' ' ++ s #else mkstempCore :: String -> IO (Fd, String) mkstempCore str = withCString (str++"XXXXXX") $ \cstr -> do fd <- c_mkstemp cstr if fd < 0 then throwErrno $ "Failed to create temporary file "++str else do str' <- peekCString cstr fname <- canonFilename str' return (Fd fd, fname) foreign import ccall unsafe "static stdlib.h mkstemp" c_mkstemp :: CString -> IO CInt #endif mkStdoutTemp :: String -> IO String mkStdoutTemp str = do (fd, fn) <- mkstempCore str hFlush stdout hFlush stderr _ <- dupTo fd stdOutput _ <- dupTo fd stdError hFlush stdout hFlush stderr hSetBuffering stdout NoBuffering hSetBuffering stderr NoBuffering return fn foreign import ccall unsafe "maybe_relink.h maybe_relink" maybe_relink :: CString -> CString -> CInt -> IO CInt -- Checks whether src and dst are identical. If so, makes dst into a -- link to src. Returns True if dst is a link to src (either because -- we linked it or it already was). Safe against changes to src if -- they are not in place, but not to dst. maybeRelink :: String -> String -> IO Bool maybeRelink src dst = withCString src $ \csrc -> withCString dst $ \cdst -> do rc <- maybe_relink csrc cdst 1 case rc of 0 -> return True 1 -> return True -1 -> throwErrno ("Relinking " ++ dst) -2 -> return False -3 -> do putStrLn ("Relinking: race condition avoided on file " ++ dst) return False _ -> fail ("Unexpected situation when relinking " ++ dst) sloppyAtomicCreate :: FilePath -> IO () sloppyAtomicCreate fp = do fd <- openFd fp WriteOnly (Just stdFileMode) flags closeFd fd where flags = defaultFileFlags { exclusive = True } atomicCreate :: FilePath -> IO () atomicCreate fp = withCString fp $ \cstr -> do rc <- c_atomic_create cstr unless (rc >= 0) $ do errno <- getErrno pwd <- getCurrentDirectory if errno == eEXIST then ioError $ mkIOError alreadyExistsErrorType ("atomicCreate in "++pwd) Nothing (Just fp) else throwErrno $ "atomicCreate "++fp++" in "++pwd foreign import ccall unsafe "atomic_create.h atomic_create" c_atomic_create :: CString -> IO CInt darcs-2.14.5/src/Darcs/Util/DateMatcher.hs0000644000000000000000000002114707346545000016352 0ustar0000000000000000-- Copyright (C) 2004 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE ExistentialQuantification #-} -- | -- Module : Darcs.Util.DateMatcher -- Copyright : 2004 David Roundy -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.Util.DateMatcher ( parseDateMatcher -- for debugging only , DateMatcher(..) , getMatchers -- for testing (GHCi, etc) , testDate , testDateAt ) where import Prelude () import Darcs.Prelude import Control.Exception ( catchJust ) import Data.Maybe ( isJust ) import System.IO.Error ( isUserError, ioeGetErrorString ) import System.Time import Text.ParserCombinators.Parsec ( eof, parse, ParseError ) import Darcs.Util.IsoDate ( parseDate, englishDateTime, englishInterval, englishLast , iso8601Interval, resetCalendar, subtractFromMCal, getLocalTz , MCalendarTime(..), toMCalendarTime, unsafeToCalendarTime , unsetTime, readUTCDate ) -- | 'withinDay' @x y@ is true if @x <= y < (x + one_day)@ -- Note that this converts the two dates to @ClockTime@ to avoid -- any timezone-related errors withinDay :: CalendarTime -> CalendarTime -> Bool withinDay a b = within (Just $ toClockTime a) (Just (addToClockTime day $ toClockTime a)) (toClockTime b) where day = TimeDiff 0 0 1 0 0 0 0 -- | 'dateRange' @x1 x2 y@ is true if @x1 <= y < x2@ -- Since @x1@ and @x2@ can be underspecified, we simply assume the -- first date that they could stand for. dateRange :: Maybe MCalendarTime -> Maybe MCalendarTime -> CalendarTime -> Bool dateRange a b = cDateRange (fmap unsafeToCalendarTime a) (fmap unsafeToCalendarTime b) -- | 'cDateRange' @x1 x2 y@ is true if @x1 <= y < x2@ cDateRange :: Maybe CalendarTime -> Maybe CalendarTime -> CalendarTime -> Bool cDateRange a b c = within (fmap toClockTime a) (fmap toClockTime b) (toClockTime c) -- | 'within' @x1 x2 y@ is true if @x1 <= y < x2@ within :: Maybe ClockTime -> Maybe ClockTime -> ClockTime -> Bool within (Just start) (Just end) time = start <= time && time < end within Nothing (Just end) time = time < end within (Just start) Nothing time = start <= time within _ _ _ = undefined -- | 'samePartialDate' @range exact@ is true if @exact@ falls -- within the a range of dates represented by @range@. -- The purpose of this function is to support matching on partially -- specified dates. That is, if you only specify the date 2007, -- this function should match any dates within that year. On the -- other hand, if you specify 2007-01, this function will match any -- dates within that month. This function only matches up to the -- second. samePartialDate :: MCalendarTime -> CalendarTime -> Bool samePartialDate a b_ = within (Just clockA) (Just $ addToClockTime interval clockA) (toClockTime calB) where interval | isJust (mctSec a) = second | isJust (mctMin a) = minute | isJust (mctHour a) = hour | isJust (mctYDay a) = day | mctWeek a = maybe week (const day) (mctWDay a) | isJust (mctDay a) = day | isJust (mctMonth a) = month | otherwise = year year = TimeDiff 1 0 0 0 0 0 0 month = TimeDiff 0 1 0 0 0 0 0 week = TimeDiff 0 0 7 0 0 0 0 day = TimeDiff 0 0 1 0 0 0 0 hour = TimeDiff 0 0 0 1 0 0 0 minute = TimeDiff 0 0 0 0 1 0 0 second = TimeDiff 0 0 0 0 0 1 0 clockA = toClockTime $ unsafeToCalendarTime a calB = resetCalendar b_ -- | A 'DateMatcher' combines a potential parse for a date string -- with a "matcher" function that operates on a given date. -- We use an existential type on the matcher to allow -- the date string to either be interpreted as a point in time -- or as an interval. data DateMatcher = forall d . (Show d) => DM String -- name (Either ParseError d) -- parser (d -> CalendarTime -> Bool) -- matcher -- | 'parseDateMatcher' @s@ return the first matcher in -- 'getMatchers' that can parse 's' parseDateMatcher :: String -> IO (CalendarTime -> Bool) parseDateMatcher d = testDateMatcher `catchUserError` handleError where catchUserError = catchJust $ \e -> if isUserError e then Just (ioeGetErrorString e) else Nothing -- If the user enters a date > maxint seconds ago, the toClockTime -- function cannot work. handleError e = if e == "Time.toClockTime: invalid input" then error "Can't handle dates that far back!" else error e -- Hack: test the matcher against the current date and discard the results. -- We just want to make sure it won't throw any exceptions when we use it -- for real. testDateMatcher = do matcher <- tryMatchers `fmap` getMatchers d matcher `fmap` now >>= (`seq` return matcher) -- | 'getMatchers' @d@ returns the list of matchers that will be -- applied on @d@. If you wish to extend the date parsing code, -- this will likely be the function that you modify to do so. getMatchers :: String -> IO [DateMatcher] getMatchers d = do rightNow <- now let midnightToday = unsetTime rightNow mRightNow = toMCalendarTime rightNow matchIsoInterval (Left dur) = let durAgo = dur `subtractFromMCal` mRightNow in dateRange (Just durAgo) (Just mRightNow) matchIsoInterval (Right (a,b)) = dateRange (Just a) (Just b) tzNow <- getLocalTz return -- note that the order of these is quite important as some matchers can -- match the same date. [ DM "from English date" (parseDateWith $ englishLast midnightToday) (\(a,_) -> cDateRange (Just a) Nothing) , DM "specific English date" (parseDateWith $ englishDateTime midnightToday) withinDay , DM "English interval" (parseDateWith $ englishInterval rightNow) (uncurry cDateRange) , DM "ISO 8601 interval" (parseDateWith $ iso8601Interval tzNow) matchIsoInterval , DM "CVS, ISO 8601, old style, or RFC2822 date" (parseDate tzNow d) samePartialDate ] where tillEof p = do { x <- p; eof; return x } parseDateWith p = parse (tillEof p) "" d --- The following functions are for toying around in GHCi --- --- > testDate "2008/05/22 10:34" --- > testDateAt "2006-03-22 09:36" "2008/05/22 10:34" -- | 'tryMatchers' @ms@ returns the first successful match in @ms@ -- It is an error if there are no matches tryMatchers :: [DateMatcher] -> CalendarTime -> Bool tryMatchers (DM _ parsed matcher : ms) = case parsed of Left _ -> tryMatchers ms Right d -> matcher d tryMatchers [] = error "Can't support fancy dates." now :: IO CalendarTime now = getClockTime >>= toCalendarTime -- | 'testDate' @d@ shows the possible interpretations -- for the date string @d@ and how they match against -- the current date testDate :: String -> IO () testDate d = do cnow <- now testDateAtCal cnow d -- | 'testDate' @iso d@ shows the possible interpretations -- for the date string @d@ and how they match against -- the date represented by the ISO 8601 string @iso@ testDateAt :: String -> String -> IO () testDateAt iso = testDateAtCal (readUTCDate iso) -- | helper function for 'testDate' and 'testDateAt' testDateAtCal :: CalendarTime -> String -> IO () testDateAtCal c d = do ms <- getMatchers d putStr . unlines . map (showMatcher c) $ ms -- | 'showMatcher' @c dm@ tells us if @dm@ applies to -- 'CalendarTime' @c@; or if @dm@ just represents the -- failure to parse a date, in which case @c@ is moot. showMatcher :: CalendarTime -> DateMatcher -> String showMatcher cnow (DM n p m) = "==== " ++ n ++ " ====\n" ++ (case p of Left err -> shows err "" Right x -> show x ++ "\n" ++ show (m x cnow)) darcs-2.14.5/src/Darcs/Util/DateTime.hs0000644000000000000000000000404207346545000015660 0ustar0000000000000000-- Copyright (C) 2011 Eric Sessoms -- -- BSD3 module Darcs.Util.DateTime ( getCurrentTime, toSeconds , formatDateTime, fromClockTime, parseDateTime, startOfTime ) where import Prelude () import Darcs.Prelude import qualified Data.Time.Calendar as Calendar ( fromGregorian ) import Data.Time.Clock ( UTCTime(UTCTime), UniversalTime(ModJulianDate) , getModJulianDate, secondsToDiffTime, getCurrentTime ) import Data.Time.Format ( formatTime, parseTimeM ) import Data.Time.LocalTime ( utc , localTimeToUT1, ut1ToLocalTime , localTimeToUTC, utcToLocalTime ) import Data.Time ( defaultTimeLocale ) import System.Time ( ClockTime(TOD) ) toSeconds :: UTCTime -> Integer toSeconds dt = floor $ (86400.0 :: Double) * fromRational (toMJD dt - startOfTimeMJD) toMJD :: UTCTime -> Rational toMJD = getModJulianDate . toUniversalTime startOfTimeMJD :: Rational startOfTimeMJD = toMJD startOfTime startOfTime :: UTCTime startOfTime = fromGregorian' 1970 1 1 fromGregorian' :: Integer -> Int -> Int -> UTCTime fromGregorian' y m d = fromGregorian y m d 0 0 0 fromGregorian :: Integer -> Int -> Int -> Int -> Int -> Int -> UTCTime fromGregorian year month day hours minutes seconds = UTCTime day' (secondsToDiffTime . fromIntegral $ seconds') where day' = Calendar.fromGregorian year month day seconds' = 3600 * hours + 60 * minutes + seconds toUniversalTime :: UTCTime -> UniversalTime toUniversalTime = localTimeToUT1 0 . utcToLocalTime utc formatDateTime :: String -> UTCTime -> String formatDateTime = formatTime defaultTimeLocale parseDateTime :: String -> String -> Maybe UTCTime parseDateTime = parseTimeM True defaultTimeLocale fromClockTime :: ClockTime -> UTCTime fromClockTime (TOD s _) = fromSeconds s fromSeconds :: Integer -> UTCTime fromSeconds s = fromMJD $ fromIntegral s / 86400 + startOfTimeMJD fromMJD :: Rational -> UTCTime fromMJD = fromUniversalTime . ModJulianDate fromUniversalTime :: UniversalTime -> UTCTime fromUniversalTime = localTimeToUTC utc . ut1ToLocalTime 0 darcs-2.14.5/src/Darcs/Util/Diff.hs0000644000000000000000000000113607346545000015035 0ustar0000000000000000module Darcs.Util.Diff ( getChanges , DiffAlgorithm(..) ) where import Prelude () import Darcs.Prelude import qualified Darcs.Util.Diff.Myers as M ( getChanges ) import qualified Darcs.Util.Diff.Patience as P ( getChanges ) import qualified Data.ByteString as B ( ByteString ) data DiffAlgorithm = PatienceDiff | MyersDiff deriving ( Eq, Show ) getChanges :: DiffAlgorithm -> [B.ByteString] -> [B.ByteString] -> [(Int,[B.ByteString],[B.ByteString])] getChanges dac = case dac of PatienceDiff -> P.getChanges MyersDiff -> M.getChangesdarcs-2.14.5/src/Darcs/Util/Diff/0000755000000000000000000000000007346545000014500 5ustar0000000000000000darcs-2.14.5/src/Darcs/Util/Diff/Myers.hs0000644000000000000000000005103607346545000016140 0ustar0000000000000000-- Copyright (C) 2002 David Roundy -- Copyright (C) 2005 Benedikt Schmidt -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | -- Module : Darcs.Util.Diff.Myers -- Copyright : 2003 David Roundy -- 2005 Benedikt Schmidt -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable -- -- LCS stands for Longest Common Subsequence, and it is a relatively -- challenging problem to find an LCS efficiently. This module implements -- the algorithm described in: -- -- "An O(ND) Difference Algorithm and its Variations", Eugene Myers, -- Algorithmica Vol. 1 No. 2, 1986, pp. 251-266; -- especially the variation described in section 4.2 and most refinements -- implemented in GNU diff (D is the edit-distance). -- -- There is currently no heuristic to reduce the running time and produce -- suboptimal output for large inputs with many differences. It behaves like -- GNU diff with the -d option in this regard. -- -- In the first step, a hash value for every line is calculated and collisions -- are marked with a special value. This reduces a string comparison to an -- int comparison for line tuples where at least one of the hash values is -- not equal to the special value. After that, lines which only exists in one -- of the files are removed and marked as changed which reduces the running -- time of the following difference algorithm. GNU diff additionally removes -- lines that appear very often in the other file in some cases. -- The last step tries to create longer changed regions and line up deletions -- in the first file to insertions in the second by shifting changed lines -- forward and backward. module Darcs.Util.Diff.Myers ( getChanges , shiftBoundaries , initP , aLen , PArray , getSlice ) where import Prelude () import Darcs.Prelude import Control.Monad import Data.Int import Control.Monad.ST import Data.Maybe import Darcs.Util.ByteString (hashPS) import qualified Data.ByteString as B (empty, ByteString) import Data.Array.Base import Data.Array.Unboxed import qualified Data.Map as Map ( lookup, empty, insertWith ) -- | create a list of changes between a and b, each change has the form -- (starta, lima, startb, limb) which means that a[starta, lima) -- has to be replaced by b[startb, limb) getChanges :: [B.ByteString] -> [B.ByteString] -> [(Int,[B.ByteString],[B.ByteString])] getChanges a b = dropStart (initP a) (initP b) 1 dropStart :: PArray -> PArray -> Int -> [(Int,[B.ByteString],[B.ByteString])] dropStart a b off | off > aLen a = [(off - 1, [], getSlice b off (aLen b))] | off > aLen b = [(off - 1, getSlice a off (aLen a), [])] | a!off == b!off = dropStart a b (off + 1) | otherwise = dropEnd a b off 0 dropEnd :: PArray -> PArray -> Int -> Int -> [(Int,[B.ByteString],[B.ByteString])] dropEnd a b off end | off > alast = [(off - 1, [], getSlice b off blast)] | off > blast = [(off - 1, getSlice a off alast, [])] | a!alast == b!blast = dropEnd a b off (end + 1) | otherwise = getChanges' (a, (off, alast)) (b, (off, blast)) where alast = aLen a - end blast = aLen b - end getSlice :: PArray -> Int -> Int -> [B.ByteString] getSlice a from to | from > to = [] | otherwise = (a ! from) : getSlice a (from + 1) to getChanges' :: (PArray, (Int, Int)) -> (PArray, (Int, Int)) -> [(Int,[B.ByteString],[B.ByteString])] getChanges' (a, abounds) (b, bbounds) = map (convertPatch 0 a b) $ createPatch c_a c_b where -- If the last few characters of two lines are the same, the lines are -- probably the same. The choice of 20 is plucked out of the air. toHash x bnds = listArray bnds [ hashPS $ x!i | i <- range bnds] ah = toHash a abounds :: HArray mkAMap m (i:is) = let ins (_,_,_,new) (collision,_,_,old) = (collision || (new /= old), True, False, old) m' = Map.insertWith ins (ah!i) (False, True, False, a!i) m in mkAMap m' is mkAMap m _ = m hm_a = mkAMap Map.empty (range abounds) -- bh = toHash b bbounds :: HArray mkBMap m (i:is) = let ins (_,_,_,new) (collision,in_a,_,old) = (collision || (new /= old), in_a, True, old) m' = Map.insertWith ins (bh!i) (False, False, True, b!i) m in mkBMap m' is mkBMap m _ = m hm = mkBMap hm_a (range bbounds) -- take care of collisions, if there are different lines with the -- same hash in both files, then set the hash to markColl, -- PackedStrings are compared for two lines with the hash markColl get (i, h) = case Map.lookup h hm of Just (_,False,_,_) -> Nothing Just (_,_,False,_) -> Nothing Just (False,True,True,_) -> Just (i, h) Just (True,True,True,_) -> Just (i, markColl) Nothing -> impossible a' = mapMaybe get [(i, ah!i) | i <- range (bounds ah)] b' = mapMaybe get [(i, bh!i) | i <- range (bounds bh)] (c_a, c_b) = diffArr a' b' (a, abounds) (b, bbounds) -- | mark hash value where collision occured markColl :: Int32 markColl = 2345677 -- | return arrays with changes in a and b (1 indexed), offsets start with 0 diffArr :: [(Int,Int32)] -> [(Int,Int32)] -> (PArray, (Int, Int)) -> (PArray, (Int, Int)) -> (BArray, BArray) diffArr a b (p_a, (off_a, l_a)) (p_b, (off_b, l_b)) = runST ( do let h_a = initH (map snd a) h_b = initH (map snd b) m_a = initM (map fst a) m_b = initM (map fst b) end_a = aLen p_a end_b = aLen p_b c_a <- initVChanged end_a c_b <- initVChanged end_b mapM_ (\ (l,_) -> writeArray c_a l False) a mapM_ (\ (l,_) -> writeArray c_b l False) b _ <- cmpseq h_a h_b p_a p_b m_a m_b c_a c_b 0 0 (aLen h_a) (aLen h_b) let unchanged ar = do {xs <- getElems ar; return $ length (filter not xs) -1} err <- liftM2 (/=) (unchanged c_a) (unchanged c_b) when err impossible -- Mark common lines at beginning and end mapM_ (\ i -> writeArray c_a i False ) [1..(off_a - 1)] mapM_ (\ i -> writeArray c_b i False ) [1..(off_b - 1)] mapM_ (\ i -> writeArray c_a i False ) [(l_a + 1) .. end_a] mapM_ (\ i -> writeArray c_b i False ) [(l_b + 1) .. end_b] shiftBoundaries c_a c_b p_a 1 1 shiftBoundaries c_b c_a p_b 1 1 err1 <- liftM2 (/=) (unchanged c_a) (unchanged c_b) when err1 impossible c_a' <- unsafeFreeze c_a c_b' <- unsafeFreeze c_b return (c_a', c_b')) -- | set changes array for a and b and return number of changed lines cmpseq :: HArray -> HArray -> PArray -> PArray -> MapArray -> MapArray -> BSTArray s -> BSTArray s -> Int -> Int -> Int -> Int -> ST s Int cmpseq _ _ _ _ _ _ _ _ _ _ 0 0 = return 0 cmpseq h_a h_b p_a p_b m_a m_b c_a c_b off_a off_b l_a l_b = do let lim_a = off_a+l_a lim_b = off_b+l_b off_a' = findSnake h_a h_b p_a p_b m_a m_b off_a off_b l_a l_b off_a off_b off_b' = off_b+off_a'-off_a lim_a' = findSnakeRev h_a h_b p_a p_b m_a m_b lim_a lim_b off_a' off_b' lim_b' = lim_b+lim_a'-lim_a l_a' = lim_a'-off_a' l_b' = lim_b'-off_b' if l_a' == 0 || l_b' == 0 then if l_a' == 0 then do when (l_b' > 0) $ mapM_ (\i -> writeArray c_b (m_b!i) True) [(off_b' + 1) .. lim_b'] return l_b' else do when (l_a' > 0) $ mapM_ (\i -> writeArray c_a (m_a!i) True) [(off_a' + 1) .. lim_a'] return l_a' else do let m = l_a' + l_b' del = l_a' - l_b' dodd = odd del v <- initV m vrev <- initVRev m l_a' writeArray vrev 0 l_a' writeArray v 0 0 (xmid, ymid, _) <- findDiag 1 h_a h_b p_a p_b m_a m_b v vrev off_a' off_b' l_a' l_b' del dodd when ((xmid == 0 && ymid == 0) || (xmid == l_a' && ymid == l_b') || (xmid < 0 || ymid < 0 || xmid > l_a' || ymid > l_b')) impossible c1 <- cmpseq h_a h_b p_a p_b m_a m_b c_a c_b off_a' off_b' xmid ymid c2 <- cmpseq h_a h_b p_a p_b m_a m_b c_a c_b (off_a' + xmid) (off_b' + ymid) (l_a' - xmid) (l_b' - ymid) return $ c1 + c2 -- | return (xmid, ymid, cost) for the two substrings -- a[off_a+1..off_a+1+l_a] and b findDiag :: Int -> HArray -> HArray -> PArray -> PArray -> MapArray -> MapArray -> VSTArray s -> VSTArray s -> Int -> Int -> Int -> Int -> Int -> Bool -> ST s (Int, Int, Int) findDiag c h_a h_b p_a p_b m_a m_b v vrev off_a off_b l_a l_b del dodd = do when (c > l_a + l_b) $ error "findDiag failed" r <- findF case r of Just (xmid, ymid) -> return (xmid, ymid, c*2 - 1) Nothing -> do r' <- findR case r' of Just (xmid, ymid) -> return (xmid, ymid, c*2) Nothing -> findDiag (c + 1) h_a h_b p_a p_b m_a m_b v vrev off_a off_b l_a l_b del dodd where fdmax = if c <= l_a then c else l_a - ((l_a + c) `mod` 2) rdmax = if c <= l_b then c else l_b - ((l_b + c) `mod` 2) lastrdmax = if (c-1) <= l_b then c-1 else l_b-(l_b + (c-1) `mod` 2) lastrdmin = -(if (c-1) <= l_a then c-1 else l_a-((l_a + (c-1)) `mod` 2)) fdmin = -rdmax rdmin = -fdmax findF = findF' fdmax findR = findR' rdmax findF' d = do x <- findOne h_a h_b p_a p_b m_a m_b v d off_a off_b l_a l_b if dodd && d - del >= lastrdmin && d - del <= lastrdmax then do xr <- readArray vrev (d - del) if xr <= x then return $ Just (x, x - d) else if d <= fdmin then return Nothing else findF' (d-2) else if d <= fdmin then return Nothing else findF' (d-2) findR' d = do x <- findOneRev h_a h_b p_a p_b m_a m_b vrev d del off_a off_b if not dodd && (d + del >= fdmin) && (d + del <= fdmax) then do xf <- readArray v (d + del) if x <= xf then return $ Just (x,x-del-d) else if d <= rdmin then return Nothing else findR' (d-2) else if d <= rdmin then return Nothing else findR' (d-2) -- | find position on diag d with one more insert/delete going forward findOne :: HArray -> HArray -> PArray -> PArray -> MapArray -> MapArray -> VSTArray s -> Int -> Int -> Int -> Int -> Int -> ST s Int findOne h_a h_b p_a p_b m_a m_b v d off_a off_b l_a l_b = do x0 <- do xbelow <- readArray v (d - 1) xover <- readArray v (d + 1) return $ if xover > xbelow then xover else xbelow + 1 let y0 = x0 - d x = findSnake h_a h_b p_a p_b m_a m_b (x0+off_a) (y0+off_b) l_a l_b off_a off_b writeArray v d (x - off_a) return (x-off_a) -- | follow snake from northwest to southeast, x and y are absolute positions findSnake :: HArray -> HArray -> PArray -> PArray -> MapArray -> MapArray -> Int -> Int -> Int -> Int -> Int -> Int -> Int findSnake h_a h_b p_a p_b m_a m_b x y l_a l_b off_a off_b = if x < l_a + off_a && y < l_b + off_b && h_a!(x+1) == h_b!(y+1) && (h_a!(x+1) /= markColl || p_a!(m_a!(x+1)) == p_b!(m_b!(y+1))) then findSnake h_a h_b p_a p_b m_a m_b (x + 1) (y + 1) l_a l_b off_a off_b else x -- | find position on diag d with one more insert/delete going backward findOneRev :: HArray -> HArray -> PArray -> PArray -> MapArray -> MapArray -> VSTArray s -> Int -> Int -> Int -> Int -> ST s Int findOneRev h_a h_b p_a p_b m_a m_b v d del off_a off_b = do x0 <- do xbelow <- readArray v (d - 1) xover <- readArray v (d + 1) return $ if xbelow < xover then xbelow else xover-1 let y0 = x0 - del - d x = findSnakeRev h_a h_b p_a p_b m_a m_b (x0+off_a) (y0+off_b) off_a off_b writeArray v d (x-off_a) return (x-off_a) -- | follow snake from southeast to northwest, x and y are absolute positions findSnakeRev :: HArray -> HArray -> PArray -> PArray -> MapArray -> MapArray -> Int -> Int -> Int -> Int -> Int findSnakeRev h_a h_b p_a p_b m_a m_b x y off_a off_b = if x > off_a && y > off_b && h_a!x == h_b!y && (h_a!x /= markColl || p_a!(m_a!x) == p_b!(m_b!y)) then findSnakeRev h_a h_b p_a p_b m_a m_b (x - 1) (y - 1) off_a off_b else x -- | try to create nicer diffs by shifting around regions of changed lines shiftBoundaries :: BSTArray s -> BSTArray s -> PArray -> Int -> Int -> ST s () shiftBoundaries c_a c_b p_a i_ j_ = do x <- nextChanged c_a i_ case x of Just start -> do let skipped = start - i_ j1 <- nextUnchangedN c_b skipped j_ end <- nextUnchanged c_a start j2 <- nextUnchanged c_b j1 (i3,j3) <- expand start end j2 shiftBoundaries c_a c_b p_a i3 j3 Nothing -> return () -- no change up to end of file where noline = aLen p_a + 1 expand start i j = do let len = i - start (start0,i0,j0) <- shiftBackward start i j b <- if j0 > 1 then readArray c_b (j0-1) else return False let corr = if b then i0 else noline let blank = if p_a!(i0-1) == B.empty then i0 else noline (start1,i1,j1,corr1,blank1) <- shiftForward start0 i0 j0 corr blank -- prefer corresponding to ending with blank line let newi = if corr1 == noline then blank1 else corr1 (start2,i2,j2) <- moveCorr start1 i1 j1 newi if len /= i2 - start2 then expand start2 i2 j2 else return (i2, j2) shiftBackward start i j = if start > 1 && p_a!(i-1) == p_a!(start-1) then do when (i == start) impossible b1 <- readArray c_a (i-1) b2 <- readArray c_a (start-1) when (not b1 || b2) impossible writeArray c_a (i-1) False writeArray c_a (start-1) True b <- if start > 2 then readArray c_a (start-2) else return False start' <- if b then liftM (1+) (prevUnchanged c_a (start-2)) else return (start-1) j' <- prevUnchanged c_b (j-1) shiftBackward start' (i-1) j' else return (start,i,j) shiftForward start i j corr blank = if i <= aLen p_a && p_a!i == p_a!start && -- B.empty at the end of file marks empty line after final newline not ((i == aLen p_a) && (p_a!i == B.empty)) then do when (i == start) impossible b1 <- readArray c_a i b2 <- readArray c_a start when (not b2 || b1) impossible writeArray c_a i True writeArray c_a start False i0 <- nextUnchanged c_a (i+1) j0 <- nextUnchanged c_b (j+1) let corr0 | i0 > (i+1) = noline | j0-j > 2 = i0 | otherwise = corr let blank0 | i0 > i+1 = noline | p_a!(i0-1) == B.empty = i0 | otherwise = blank shiftForward (start+1) i0 j0 corr0 blank0 else return (start,i,j,corr,blank) moveCorr start i j corr = if corr >= i then return (start,i,j) else do b1 <- readArray c_a (i-1) b2 <- readArray c_a (start-1) when (not b1 || b2) impossible when (p_a!(i-1) /= p_a!(start-1)) impossible writeArray c_a (i-1) False writeArray c_a (start-1) True j' <- prevUnchanged c_b (j-1) moveCorr (start-1) (i-1) j' corr -- | goto next unchanged line, return the given line if unchanged nextUnchanged :: BSTArray s -> Int -> ST s Int nextUnchanged c i = do len <- aLenM c if i == len + 1 then return i else do b <- readArray c i if b then nextUnchanged c (i+1) else return i -- | skip at least one unchanged line, if there is none advance -- behind the last line skipOneUnChanged :: BSTArray s -> Int -> ST s Int skipOneUnChanged c i = do len <- aLenM c if i == len + 1 then return i else do b <- readArray c i if not b then return (i+1) else skipOneUnChanged c (i+1) -- | goto n-th next unchanged line nextUnchangedN :: BSTArray s -> Int -> Int -> ST s Int nextUnchangedN c n i = if n == 0 then return i else do i' <- skipOneUnChanged c i nextUnchangedN c (n-1) i' -- | goto next changed line, return the given line if changed nextChanged :: BSTArray s -> Int -> ST s (Maybe Int) nextChanged c i = do len <- aLenM c if i <= len then do b <- readArray c i if not b then nextChanged c (i+1) else return $ Just i else return Nothing -- | goto previous unchanged line, return the given line if unchanged prevUnchanged :: BSTArray s -> Int -> ST s Int prevUnchanged c i = do b <- readArray c i if b then prevUnchanged c (i-1) else return i type HArray = UArray Int Int32 type BArray = UArray Int Bool type PArray = Array Int B.ByteString type MapArray = UArray Int Int type VSTArray s = STUArray s Int Int type BSTArray s = STUArray s Int Bool initV :: Int -> ST s (VSTArray s) initV dmax = newArray (-(dmax + 1), dmax + 1) (-1) initVRev :: Int -> Int -> ST s (VSTArray s) initVRev dmax xmax = newArray (-(dmax + 1), dmax + 1) (xmax + 1) -- 1 indexed, v[0] is used as a guard element initVChanged :: Int -> ST s (BSTArray s) initVChanged l = do a <- newArray (0, l) True writeArray a 0 False return a -- set to false for all lines which have a mapping later -- other lines are only present in one of the files initH :: [Int32] -> HArray initH a = listArray (0, length a) (0:a) initM :: [Int] -> MapArray initM a = listArray (0, length a) (0:a) initP :: [B.ByteString] -> PArray initP a = listArray (0, length a) (B.empty:a) aLen :: (IArray a e) => a Int e -> Int aLen a = snd $ bounds a aLenM :: (MArray a e m) => a Int e -> m Int aLenM a = snd `liftM` getBounds a convertPatch :: Int -> PArray -> PArray -> (Int, Int, Int, Int) -> (Int,[B.ByteString],[B.ByteString]) convertPatch off a b (a0,a1,b0,b1) | b0 == b1 = (b0+off,getDelete a a0 a1,[]) | a0 == a1 = (b0+off,[],getInsert b b0 b1) | otherwise = (b0+off,getDelete a a0 a1,getInsert b b0 b1) getInsert :: PArray -> Int -> Int -> [B.ByteString] getInsert b from to | from >= to = [] | otherwise = (b!(from+1)):getInsert b (from+1) to getDelete :: PArray -> Int -> Int -> [B.ByteString] getDelete a from to | from >= to = [] | otherwise = (a!(from+1)):getDelete a (from+1) to createPatch :: BArray -> BArray -> [(Int, Int, Int, Int)] createPatch c_a c_b = reverse $ createP c_a c_b (aLen c_a) (aLen c_b) createP :: BArray -> BArray -> Int -> Int -> [(Int, Int, Int, Int)] createP _ _ 0 0 = [] createP c_a c_b ia ib = if c_a!ia || c_b!ib then let ia' = skipChangedRev c_a ia ib' = skipChangedRev c_b ib in (ia',ia,ib',ib):createP c_a c_b ia' ib' else createP c_a c_b (ia-1) (ib-1) skipChangedRev :: BArray -> Int -> Int skipChangedRev c i = if i >= 0 && c!i then skipChangedRev c (i-1) else i darcs-2.14.5/src/Darcs/Util/Diff/Patience.hs0000644000000000000000000004107207346545000016570 0ustar0000000000000000-- Copyright (C) 2002,2008-2009 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. module Darcs.Util.Diff.Patience ( getChanges ) where import Prelude () import Darcs.Prelude import Data.List ( sort ) import Data.Maybe ( fromJust ) import Data.Array.Unboxed import Data.Array.ST import Control.Monad.ST import qualified Data.Set as S import qualified Data.ByteString as B ( ByteString, elem ) import qualified Data.ByteString.Char8 as BC ( pack ) import qualified Data.Map.Strict as M ( Map, lookup, insertWith, empty, elems ) import qualified Data.Hashable as H ( hash ) import Darcs.Util.Diff.Myers (initP, aLen, PArray, getSlice) empty :: HunkMap empty = HunkMapInfo 0 M.empty getChanges :: [B.ByteString] -> [B.ByteString] -> [(Int,[B.ByteString],[B.ByteString])] getChanges a b = dropStart (initP a) (initP b) 1 dropStart :: PArray -> PArray -> Int -> [(Int,[B.ByteString],[B.ByteString])] dropStart a b off | off > aLen a = [(off - 1, [], getSlice b off (aLen b))] | off > aLen b = [(off - 1, getSlice a off (aLen a), [])] | a!off == b!off = dropStart a b (off + 1) | otherwise = dropEnd a b off 0 dropEnd :: PArray -> PArray -> Int -> Int -> [(Int,[B.ByteString],[B.ByteString])] dropEnd a b off end | off > alast = [(off - 1, [], getSlice b off blast)] | off > blast = [(off - 1, getSlice a off alast, [])] | a!alast == b!blast = dropEnd a b off (end + 1) | otherwise = getChanges' (off-1) (getSlice a off (aLen a - end')) (getSlice b off (aLen b - end')) where end' = addBorings end -- don't drop Borings just in case. See hidden_conflict2.sh addBorings e | e > 0 && a!(aLen a - (e-1)) `elem` borings' = addBorings (e-1) | otherwise = e alast = aLen a - end blast = aLen b - end getChanges' :: Int -> [B.ByteString] -> [B.ByteString] -> [(Int, [B.ByteString], [B.ByteString])] getChanges' off o n = convertLBS [] $ genNestedChanges [byparagraph, bylines] off oh nh where (_,m') = listToHunk borings' empty (oh,m) = listToHunk o m' (nh,lmap) = listToHunk n m convertLBS ys [] = reverse ys convertLBS ys ((i,os,ns):xs) = convertLBS ((i, hunkToBS os, hunkToBS ns):ys) xs hunkToBS hs = map (\h -> (!) harray (abs h)) hs harray = getBArray lmap type HMap = M.Map type Hash = Int type Hunk = Int data HunkMap = HunkMapInfo Int (HMap Hash [(Hunk, B.ByteString)]) getMap :: HunkMap -> HMap Hash [(Hunk, B.ByteString)] getMap (HunkMapInfo _ m) = m getSize :: HunkMap -> Int getSize (HunkMapInfo s _) = s getBArray :: HunkMap -> Array Hunk B.ByteString getBArray (HunkMapInfo size b) = array (1,size) $ map (\(x,a) -> (abs x, a)) $ concat $ M.elems b insert :: Hash -> B.ByteString -> HunkMap -> (Hunk, HunkMap) insert h bs hmap = (hunknumber, HunkMapInfo newsize (M.insertWith (\_ o -> (hunknumber,bs):o) h [(hunknumber,bs)] $ getMap hmap)) where hunknumber = if B.elem nl bs then -newsize -- used by bylines else newsize newsize = getSize hmap+1 nl = 10 -- '\n' --Given a HunkMap, check collisions and return the line with an updated Map toHunk' :: HunkMap -> B.ByteString -> (Hunk, HunkMap) toHunk' lmap bs | oldbs == Nothing || null oldhunkpair = insert hash bs lmap | otherwise = (fst $ head oldhunkpair, lmap) where hash = H.hash bs oldbs = M.lookup hash (getMap lmap) oldhunkpair = filter ((== bs) . snd) $ fromJust oldbs listToHunk :: [B.ByteString] -> HunkMap -> ([Hunk], HunkMap) listToHunk [] hmap = ([], hmap) listToHunk (x:xs) hmap = let (y, hmap') = toHunk' hmap x (ys, hmap'') = listToHunk xs hmap' in (y:ys, hmap'') --listToHunk :: [B.ByteString] -> HunkMap -> ([Hunk], HunkMap) --listToHunk = listToHunk' [] -- where listToHunk' xs [] hmap = (reverse xs, hmap) -- listToHunk' xs (y:ys) hmap = let (h,hmap') = toHunk' hmap y -- in listToHunk' (h:xs) ys hmap' genNestedChanges :: [[Hunk] -> [[Hunk]]] -> Int -> [Hunk] -> [Hunk] -> [(Int, [Hunk], [Hunk])] genNestedChanges (br:brs) i0 o0 n0 = nc i0 (lcus ol nl) ol nl where nl = br n0 ol = br o0 nc i [] o n = easydiff i o n nc i (x:xs) o n = case break (==x) o of (oa, _:ob) -> case break (==x) n of (na, _:nb) -> i' `seq` easydiff i oa na ++ nc i' xs ob nb where i' = i + length (concat na) + length x (_,[]) -> impossible (_,[]) -> impossible easydiff i o n = genNestedChanges brs i oo nn where (oo, nn) = (concat o, concat n) genNestedChanges [] i o n = mkdiff (all (`elem` borings)) i mylcs o n where mylcs = patientLcs (filter (`notElem` borings) o) (filter (`notElem` borings) n) borings :: [Hunk] borings = fst $ listToHunk borings' empty borings' :: [B.ByteString] borings' = map BC.pack ["", "\n", " ", ")", "(", ","] byparagraph :: [Hunk] -> [[Hunk]] byparagraph = reverse . map reverse . byparagraphAcc [] where byparagraphAcc xs [] = xs byparagraphAcc [] (a:b:c:d) | a == nl && c == nl && b == hnull = case d of [] -> [[c,b,a]] _ -> byparagraphAcc [[],[c,b,a]] d byparagraphAcc [] (a:as) = byparagraphAcc [[a]] as byparagraphAcc (x:xs) (a:b:c:d) | a == nl && c == nl && b == hnull = case d of [] -> (c:b:a:x):xs _ -> byparagraphAcc ([]:((c:b:a:x):xs)) d byparagraphAcc (x:xs) (a:as) = byparagraphAcc ((a:x):xs) as nl = -1 -- "\n" hunk hnull = 1 -- "" hunk toHunk $ BC.pack "" bylines :: [Hunk] -> [[Hunk]] bylines = reverse . bylinesAcc [] where bylinesAcc !ys [] = ys bylinesAcc !ys xs = case break (<0) xs of (_,[]) -> xs:ys (a,n:b) -> bylinesAcc ((a++[n]):ys) b -- | the longest common subsequence of unique items lcus :: Ord a => [a] -> [a] -> [a] lcus xs0 ys0 = lcs (filter (`S.member`u) xs0) (filter (`S.member`u) ys0) where uxs = findUnique xs0 uys = findUnique ys0 u = S.intersection uxs uys findUnique xs = S.fromList $ gru $ sort xs gru (x:x':xs) | x == x' = gru (dropWhile (==x) xs) gru (x:xs) = x : gru xs gru [] = [] mkdiff :: Ord a => ([a] -> Bool) -> Int -> [a] -> [a] -> [a] -> [(Int,[a],[a])] mkdiff b ny (l:ls) (x:xs) (y:ys) | l == x && l == y = mkdiff b (ny+1) ls xs ys mkdiff boring ny (l:ls) xs ys | rmd == add = mkdiff boring (ny+length add+1) ls restx resty | boring rmd && boring add = case lcs rmd add of [] -> prefixPostfixDiff ny rmd add ++ mkdiff boring (ny+length add+1) ls restx resty ll -> mkdiff (const False) ny ll rmd add ++ mkdiff boring (ny+length add+1) ls restx resty | otherwise = prefixPostfixDiff ny rmd add ++ mkdiff boring (ny+length add+1) ls restx resty where rmd = takeWhile (/= l) xs add = takeWhile (/= l) ys restx = drop (length rmd + 1) xs resty = drop (length add + 1) ys mkdiff _ _ [] [] [] = [] mkdiff boring ny [] rmd add | boring rmd && boring add = case lcs rmd add of [] -> prefixPostfixDiff ny rmd add ll -> mkdiff (const False) ny ll rmd add | otherwise = prefixPostfixDiff ny rmd add prefixPostfixDiff :: Ord a => Int -> [a] -> [a] -> [(Int,[a],[a])] prefixPostfixDiff _ [] [] = [] prefixPostfixDiff ny [] ys = [(ny,[],ys)] prefixPostfixDiff ny xs [] = [(ny,xs,[])] prefixPostfixDiff ny (x:xs) (y:ys) | x == y = prefixPostfixDiff (ny+1) xs ys | otherwise = [(ny, reverse rxs', reverse rys')] where (rxs',rys') = dropPref (reverse (x:xs)) (reverse (y:ys)) dropPref (a:as) (b:bs) | a == b = dropPref as bs dropPref as bs = (as,bs) -- | The patientLcs algorithm is inspired by the "patience" algorithm -- (for which I don't have a reference handy), in that it looks for -- unique lines, and uses them to subdivide the problem. I use lcs to -- diff the unique lines. It is slower, but should lead to "better" -- diffs, in the sense of ones that better align with what humans -- think changed. -- -- Note that when compared with the Meyers algorithm used in darcs, -- this is somewhat slower (maybe 4x in some of my tests), but is -- lacking its stack overflow problem. I'm not sure how it scales in -- general, but it scales fine (just 10x slower than GNU diff) when -- comparing a 6M american english dictionary with a british english -- dictionary of the same size (which isn't a great test, but is the -- largest pair of somewhat-differing files I could find). -- -- Note that the patientLcs algorithm is slower than the one used in -- lcs for sequences with mostly unique elements (as is common in text -- files), but much *faster* when the sequence has a high degree of -- redundancy. i.e. lines /usr/share/dict/words vs lines (cat -- /usr/share/dict/words | tr 'a-z' 'a') {-# SPECIALIZE patientLcs ::[Hunk] -> [Hunk] -> [Hunk] #-} patientLcs :: Ord a => [a] -> [a] -> [a] patientLcs [] _ = [] patientLcs _ [] = [] patientLcs (c1:c1s) (c2:c2s) | c1 == c2 = c1: patientLcs c1s c2s | otherwise = reverse $ patientLcs0 (reverse (c1:c1s)) (reverse (c2:c2s)) patientLcs0 :: Ord a => [a] -> [a] -> [a] patientLcs0 xs0@(cc1:cc1s) ys0@(cc2:cc2s) | cc1 == cc2 = cc1 : patientLcs0 cc1s cc2s | otherwise = case (filter (`S.member`uys) xs0, filter (`S.member`uxs) ys0) of ([],_) -> lcs xs0 ys0 (_,[]) -> lcs xs0 ys0 (xs',ys') -> joinU (lcs xs' ys') xs0 ys0 where uxs = findUnique xs0 uys = findUnique ys0 joinU [] x y = lcs x y joinU (b:bs) cs ds = case break (==b) cs of ([],_:c2) -> b : joinU bs c2 (drop 1 $ dropWhile (/= b) ds) (c1,_:c2) -> case break (==b) ds of ([],_:d2) -> b : joinU bs c2 d2 (d1,_:d2) -> lcs c1 d1 ++ b : joinU bs c2 d2 _ -> impossible _ -> impossible findUnique xs = S.fromList $ gru $ sort xs gru (x:x':xs) | x == x' = gru (dropWhile (==x) xs) gru (x:xs) = x : gru xs gru [] = [] --findUnique xs = fu S.empty S.empty xs -- where fu _ uni [] = uni -- fu multi uni (y:ys) -- | y `S.member` multi = fu multi uni ys -- | y `S.member` uni = fu (S.insert y multi) (S.delete y uni) ys -- | otherwise = fu multi (S.insert y uni) ys patientLcs0 [] _ = [] patientLcs0 _ [] = [] -- | ``LCS'' stands for ``Longest Common Subsequence,'' and it is a relatively -- challenging problem to find an LCS efficiently. I'm not going to explain -- here what an LCS is, but will point out that it is useful in finding how -- two sequences (lists, in this case) differ. This module implements the -- Hunt-Szymanski algorithm, which is appropriate for applications in which -- the sequence is on an infinite alphabet, such as diffing the lines in two -- files, where many, or most lines are unique. In the best case scenario, a -- permutation of unique lines, this algorithm is $O(n\log n)$. In the worst -- case scenario, that of a finite alphabet (i.e.\ where the number of elements -- in the sequence is much greater than the number of unique elements), it is -- an $O(n^2\log n)$ algorithm, which is pretty terrible. {-# SPECIALIZE lcs ::[Hunk] -> [Hunk] -> [Hunk] #-} lcs :: Ord a => [a] -> [a] -> [a] lcs [] _ = [] lcs _ [] = [] lcs (c1:c1s) (c2:c2s) | c1 == c2 = c1: lcs c1s c2s | otherwise = reverse $ lcsSimple (reverse (c1:c1s)) (reverse (c2:c2s)) lcsSimple :: Ord a => [a] -> [a] -> [a] lcsSimple [] _ = [] lcsSimple _ [] = [] lcsSimple s1@(c1:c1s) s2@(c2:c2s) | c1 == c2 = c1: lcs c1s c2s | otherwise = hunt $ pruneMatches s1 $! findMatches s1 s2 pruneMatches :: [a] -> [[Int]] -> [(a, [Int])] pruneMatches _ [] = [] pruneMatches [] _ = [] pruneMatches (_:cs) ([]:ms) = pruneMatches cs ms pruneMatches (c:cs) (m:ms) = (c,m): pruneMatches cs ms type Threshold s a = STArray s Int (Int,[a]) hunt :: [(a, [Int])] -> [a] hunt [] = [] hunt csmatches = runST ( do th <- emptyThreshold (length csmatches) l huntInternal csmatches th huntRecover th (-1) l ) where l = maximum (0 : concat (map snd csmatches)) huntInternal :: [(a, [Int])] -> Threshold s a -> ST s () huntInternal [] _ = return () huntInternal ((c,m):csms) th = do huntOneChar c m th huntInternal csms th huntOneChar :: a -> [Int] -> Threshold s a -> ST s () huntOneChar _ [] _ = return () huntOneChar c (j:js) th = do index_k <- myBs j th case index_k of Nothing -> return () Just k -> do (_, rest) <- readArray th (k-1) writeArray th k (j, c:rest) huntOneChar c js th -- This is O(n), which is stupid. huntRecover :: Threshold s a -> Int -> Int -> ST s [a] huntRecover th n limit = do (_, th_max) <- getBounds th if n < 0 then huntRecover th th_max limit else if n == 0 || n > th_max then return [] else do (thn, sn) <- readArray th n if thn <= limit then return $ reverse sn else huntRecover th (n-1) limit emptyThreshold :: Int -> Int -> ST s (Threshold s a) emptyThreshold l th_max = do th <- newArray (0,l) (th_max+1, []) writeArray th 0 (0, []) return th myBs :: Int -> Threshold s a -> ST s (Maybe Int) myBs j th = do bnds <- getBounds th myHelperBs j bnds th myHelperBs :: Int -> (Int,Int) -> Threshold s a -> ST s (Maybe Int) myHelperBs j (th_min,th_max) th = if th_max - th_min > 1 then do (midth, _) <- readArray th th_middle if j > midth then myHelperBs j (th_middle,th_max) th else myHelperBs j (th_min,th_middle) th else do (minth, _) <- readArray th th_min (maxth, _) <- readArray th th_max if minth < j && maxth > j then return $ Just th_max else if j < minth then return $ Just th_min else return Nothing where th_middle = (th_max+th_min) `div` 2 findMatches :: Ord a => [a] -> [a] -> [[Int]] findMatches [] [] = [] findMatches [] (_:bs) = []: findMatches [] bs findMatches _ [] = [] findMatches a b = unzipIndexed $ sort $ findSortedMatches indexeda indexedb [] [] where indexeda = sort $ zip a [1..] indexedb = sort $ zip b [1..] unzipIndexed :: [(Int,[a])] -> [[a]] unzipIndexed s = unzipIndexedHelper 1 s where unzipIndexedHelper _ [] = [] unzipIndexedHelper thisl ((l,c):rest) | thisl == l = c: unzipIndexedHelper (l+1) rest | otherwise = []: unzipIndexedHelper (thisl+1) ((l,c):rest) findSortedMatches :: Ord a => [(a, Int)] -> [(a, Int)] -> [a] -> [Int] -> [(Int, [Int])] findSortedMatches [] _ _ _ = [] findSortedMatches _ [] _ _ = [] findSortedMatches ((a,na):as) ((b,nb):bs) aold aoldmatches | [a] == aold = (na, aoldmatches) : findSortedMatches as ((b,nb):bs) aold aoldmatches | a > b = findSortedMatches ((a,na):as) bs aold aoldmatches | a < b = findSortedMatches as ((b,nb):bs) aold aoldmatches -- following line is inefficient if a line is repeated many times. findSortedMatches ((a,na):as) bs _ _ -- a == b = (na, matches) : findSortedMatches as bs [a] matches where matches = reverse $ map snd $ filter ((==a) . fst) bs darcs-2.14.5/src/Darcs/Util/Download.hs0000644000000000000000000003230107346545000015732 0ustar0000000000000000{-# LANGUAGE CPP #-} -- | -- Module : Darcs.Util.Download -- Copyright : 2008 Dmitry Kurochkin -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.Util.Download ( copyUrl , copyUrlFirst , setDebugHTTP , disableHTTPPipelining , maxPipelineLength , waitUrl , Cachable(Cachable, Uncachable, MaxAge) , environmentHelpProxy , environmentHelpProxyPassword , ConnectionError(..) ) where import Prelude ( (^) ) import Darcs.Prelude import Control.Arrow ( (&&&) ) import Control.Concurrent ( forkIO ) import Control.Concurrent.STM.TChan ( isEmptyTChan, newTChanIO, readTChan, writeTChan, TChan ) import Control.Concurrent.MVar ( isEmptyMVar, modifyMVar_, modifyMVar, newEmptyMVar, newMVar, putMVar, readMVar, withMVar, MVar ) import Control.Monad ( unless, when ) import Control.Monad.State ( evalStateT, get, modify, put, StateT ) import Control.Monad.STM ( atomically ) import Control.Monad.Trans ( liftIO ) import Data.IORef ( newIORef, readIORef, writeIORef, IORef ) import Data.Map ( Map ) import qualified Data.Map as Map import Data.Tuple ( swap ) import System.Directory ( copyFile ) import System.IO.Unsafe ( unsafePerformIO ) import System.Random ( randomRIO ) import Darcs.Util.AtExit ( atexit ) import Darcs.Util.File ( removeFileMayNotExist ) import Numeric ( showHex ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Download.Request import Darcs.Util.Workaround ( renameFile ) #ifdef HAVE_CURL import qualified Darcs.Util.Download.Curl as Curl #else import qualified Darcs.Util.Download.HTTP as HTTP #endif {-# NOINLINE maxPipelineLengthRef #-} maxPipelineLengthRef :: IORef Int maxPipelineLengthRef = unsafePerformIO $ do enabled <- pipeliningEnabled #ifdef HAVE_CURL unless enabled $ debugMessage $ "Warning: pipelining is disabled, because libcurl version darcs was " ++ "compiled with is too old (< 7.19.1)" #endif newIORef $ if enabled then 100 else 1 maxPipelineLength :: IO Int maxPipelineLength = readIORef maxPipelineLengthRef {-# NOINLINE urlNotifications #-} urlNotifications :: MVar (Map String (MVar (Maybe String))) urlNotifications = unsafePerformIO $ newMVar Map.empty {-# NOINLINE urlChan #-} urlChan :: TChan UrlRequest urlChan = unsafePerformIO $ do ch <- newTChanIO _ <- forkIO (urlThread ch) return ch type UrlM a = StateT UrlState IO a urlThread :: TChan UrlRequest -> IO () urlThread ch = do junk <- flip showHex "" `fmap` randomRIO rrange evalStateT urlThread' (UrlState Map.empty emptyQ 0 junk) where rrange = (0, 2 ^ (128 :: Integer) :: Integer) urlThread' :: UrlM () urlThread' = do empty <- liftIO $ atomically $ isEmptyTChan ch (l, w) <- (pipeLength &&& waitToStart) `fmap` get -- If we've got UrlRequests waiting on the chan, or there's nothing -- waiting to start and nothing already downloading, we just block -- waiting for more UrlRequests. reqs <- if not empty || (nullQ w && l == 0) then liftIO readAllRequests else return [] mapM_ addReq reqs checkWaitToStart waitNextUrl urlThread' readAllRequests :: IO [UrlRequest] readAllRequests = do r <- atomically $ readTChan ch debugMessage $ "URL.urlThread (" ++ url r ++ "\n"++ "-> " ++ file r ++ ")" empty <- atomically $ isEmptyTChan ch reqs <- if not empty then readAllRequests else return [] return (r : reqs) -- | addReq adds a UrlRequest to the current downloads, being careful to -- update the lists of target filenames if the url is already being -- downloaded. addReq :: UrlRequest -> UrlM () addReq (UrlRequest u f c p) = do d <- liftIO (alreadyDownloaded u) if d then dbg "Ignoring UrlRequest of URL that is already downloaded." else do (ip, wts) <- (inProgress &&& waitToStart) `fmap` get case Map.lookup u ip of Nothing -> modify $ \st -> st { inProgress = Map.insert u (f, [], c) ip , waitToStart = addUsingPriority p u wts } Just (f', fs', c') -> do let new_c = minCachable c c' when (c /= c') $ do let new_p = Map.insert u (f', fs', new_c) ip modify (\s -> s { inProgress = new_p }) dbg $ "Changing " ++ u ++ " request cachability from " ++ show c ++ " to " ++ show new_c when (u `elemQ` wts && p == High) $ do modify $ \s -> s { waitToStart = pushQ u (deleteQ u wts) } dbg $ "Moving " ++ u ++ " to head of download queue." if f `notElem` (f' : fs') then do let new_ip = Map.insert u (f', f : fs', new_c) ip modify (\s -> s { inProgress = new_ip }) dbg "Adding new file to existing UrlRequest." else dbg $ "Ignoring UrlRequest of file that's " ++ "already queued." alreadyDownloaded :: String -> IO Bool alreadyDownloaded u = do n <- withMVar urlNotifications $ return . Map.lookup u maybe (return True) (\v -> not `fmap` isEmptyMVar v) n -- |'checkWaitToStart' will inspect the current waiting-to-start queue, if the -- pipe isn't full, checkWaitToStart :: UrlM () checkWaitToStart = do st <- get let l = pipeLength st mpl <- liftIO maxPipelineLength when (l < mpl) $ case readQ (waitToStart st) of Nothing -> return () Just (u, rest) -> do case Map.lookup u (inProgress st) of Nothing -> bug $ "bug in URL.checkWaitToStart " ++ u Just (f, _, c) -> do dbg $ "URL.requestUrl (" ++ u ++ "\n" ++ "-> " ++ f ++ ")" let f_new = createDownloadFileName f st err <- liftIO $ requestUrl u f_new c if null err then do -- waitNextUrl might never return this url as -- complete/failed, so being careful, we should -- try and delete the corresponding file atexit liftIO $ atexit (removeFileMayNotExist f_new) -- We've started off another download, so the -- pipline length should increase. put $ st { waitToStart = rest , pipeLength = l + 1 } else do dbg $ "Failed to start download URL " ++ u ++ ": " ++ err liftIO $ do removeFileMayNotExist f_new downloadComplete u err put $ st { waitToStart = rest } checkWaitToStart copyUrlFirst :: String -> FilePath -> Cachable -> IO () copyUrlFirst = copyUrlWithPriority High copyUrl :: String -> FilePath -> Cachable -> IO () copyUrl = copyUrlWithPriority Low copyUrlWithPriority :: Priority -> String -> String -> Cachable -> IO () copyUrlWithPriority p u f c = do debugMessage $ "URL.copyUrlWithPriority (" ++ u ++ "\n" ++ "-> " ++ f ++ ")" v <- newEmptyMVar old_mv <- modifyMVar urlNotifications (return . swap . Map.insertLookupWithKey (\_k _n old -> old) u v) case old_mv of Nothing -> atomically $ writeTChan urlChan $ UrlRequest u f c p -- ok, new URL Just _ -> debugMessage $ "URL.copyUrlWithPriority already in progress, skip (" ++ u ++ "\n" ++ "-> " ++ f ++ ")" createDownloadFileName :: FilePath -> UrlState -> FilePath createDownloadFileName f st = f ++ "-new_" ++ randomJunk st waitNextUrl :: UrlM () waitNextUrl = do st <- get let l = pipeLength st when (l > 0) $ do dbg "URL.waitNextUrl start" (u, e, ce) <- liftIO waitNextUrl' let p = inProgress st liftIO $ case Map.lookup u p of Nothing -> -- A url finished downloading, but we don't have a record of it bug $ "bug in URL.waitNextUrl: " ++ u Just (f, fs, _) -> if null e then do -- Succesful download renameFile (createDownloadFileName f st) f mapM_ (safeCopyFile st f) fs downloadComplete u e debugMessage $ "URL.waitNextUrl succeeded: " ++ u ++ " " ++ f else do -- An error while downloading removeFileMayNotExist (createDownloadFileName f st) downloadComplete u (maybe e show ce) debugMessage $ "URL.waitNextUrl failed: " ++ u ++ " " ++ f ++ " " ++ e unless (null u) . put $ st { inProgress = Map.delete u p , pipeLength = l - 1 } where safeCopyFile st f t = do let new_t = createDownloadFileName t st copyFile f new_t renameFile new_t t downloadComplete :: String -> String -> IO () downloadComplete u e = do r <- withMVar urlNotifications (return . Map.lookup u) case r of Just notifyVar -> putMVar notifyVar $ if null e then Nothing else Just e Nothing -> debugMessage $ "downloadComplete URL '" ++ u ++ "' downloaded several times" waitUrl :: String -> IO () waitUrl u = do debugMessage $ "URL.waitUrl " ++ u r <- withMVar urlNotifications (return . Map.lookup u) case r of Nothing -> return () -- file was already downloaded Just var -> do mbErr <- readMVar var modifyMVar_ urlNotifications (return . Map.delete u) flip (maybe (return ())) mbErr $ \e -> do debugMessage $ "Failed to download URL " ++ u ++ ": " ++ e fail e dbg :: String -> StateT a IO () dbg = liftIO . debugMessage minCachable :: Cachable -> Cachable -> Cachable minCachable Uncachable _ = Uncachable minCachable _ Uncachable = Uncachable minCachable (MaxAge a) (MaxAge b) = MaxAge $ min a b minCachable (MaxAge a) _ = MaxAge a minCachable _ (MaxAge b) = MaxAge b minCachable _ _ = Cachable disableHTTPPipelining :: IO () disableHTTPPipelining = writeIORef maxPipelineLengthRef 1 setDebugHTTP :: IO () requestUrl :: String -> FilePath -> Cachable -> IO String waitNextUrl' :: IO (String, String, Maybe ConnectionError) pipeliningEnabled :: IO Bool #ifdef HAVE_CURL setDebugHTTP = Curl.setDebugHTTP requestUrl = Curl.requestUrl waitNextUrl' = Curl.waitNextUrl pipeliningEnabled = Curl.pipeliningEnabled #else setDebugHTTP = return () requestUrl = HTTP.requestUrl waitNextUrl' = HTTP.waitNextUrl pipeliningEnabled = return False #endif -- Usage of these environment variables happens in C code, so the -- closest to "literate" user documentation is here, where the -- offending function 'curl_request_url' is imported. environmentHelpProxy :: ([String], [String]) environmentHelpProxy = ( [ "HTTP_PROXY", "HTTPS_PROXY", "FTP_PROXY", "ALL_PROXY", "NO_PROXY"] , [ "If Darcs was built with libcurl, the environment variables" , "HTTP_PROXY, HTTPS_PROXY and FTP_PROXY can be set to the URL of a" , "proxy in the form" , "" , " [protocol://][:port]" , "" , "In which case libcurl will use the proxy for the associated protocol" , "(HTTP, HTTPS and FTP). The environment variable ALL_PROXY can be used" , "to set a single proxy for all libcurl requests." , "" , "If the environment variable NO_PROXY is a comma-separated list of" , "host names, access to those hosts will bypass proxies defined by the" , "above variables. For example, it is quite common to avoid proxying" , "requests to machines on the local network with" , "" , " NO_PROXY=localhost,*.localdomain" , "" , "For compatibility with lynx et al, lowercase equivalents of these" , "environment variables (e.g. $http_proxy) are also understood and are" , "used in preference to the uppercase versions." , "" , "If Darcs was not built with libcurl, all these environment variables" , "are silently ignored, and there is no way to use a web proxy." ] ) environmentHelpProxyPassword :: ([String], [String]) environmentHelpProxyPassword = ( [ "DARCS_PROXYUSERPWD" ] , [ "If Darcs was built with libcurl, and you are using a web proxy that" , "requires authentication, you can set the $DARCS_PROXYUSERPWD" , "environment variable to the username and password expected by the" , "proxy, separated by a colon. This environment variable is silently" , "ignored if Darcs was not built with libcurl." ] ) darcs-2.14.5/src/Darcs/Util/Download/0000755000000000000000000000000007346545000015377 5ustar0000000000000000darcs-2.14.5/src/Darcs/Util/Download/Curl.hs0000644000000000000000000000472507346545000016650 0ustar0000000000000000{-# LANGUAGE CPP, ForeignFunctionInterface #-} module Darcs.Util.Download.Curl where #ifdef HAVE_CURL import Prelude () import Darcs.Prelude import Control.Exception ( bracket ) import Control.Monad ( when ) import Foreign.C.Types ( CLong(..), CInt(..) ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Download.Request import Foreign.C.String ( withCString, peekCString, CString ) import Foreign.Ptr import Foreign.Marshal.Alloc import Foreign.Storable setDebugHTTP :: IO () setDebugHTTP = curl_enable_debug requestUrl :: String -> FilePath -> Cachable -> IO String requestUrl u f cache = withCString u $ \ustr -> withCString f $ \fstr -> bracket malloc free $ \ errorPointer -> do e <- curl_request_url ustr fstr (cachableToInt cache) errorPointer >>= peekCString errorNum <- peek errorPointer when (errorNum == 90 ) $ debugMessage "The environment variable DARCS_CONNECTION_TIMEOUT is not a number" return e waitNextUrl :: IO (String, String, Maybe ConnectionError) waitNextUrl = bracket malloc free $ \ errorPointer -> bracket malloc free $ \ httpErrorPointer -> do e <- curl_wait_next_url errorPointer httpErrorPointer >>= peekCString ce <- do errorNum <- peek errorPointer if null e then return Nothing else return $ case errorNum of 6 -> Just CouldNotResolveHost 7 -> Just CouldNotConnectToServer 28 -> Just OperationTimeout _ -> Nothing u <- curl_last_url >>= peekCString httpErrorCode <- peek httpErrorPointer let detailedErrorMessage = if httpErrorCode > 0 then e ++ " " ++ show httpErrorCode else e return (u, detailedErrorMessage, ce) pipeliningEnabled :: IO Bool pipeliningEnabled = do r <- curl_pipelining_enabled return $ r /= 0 cachableToInt :: Cachable -> CInt cachableToInt Cachable = -1 cachableToInt Uncachable = 0 cachableToInt (MaxAge n) = n foreign import ccall "hscurl.h curl_request_url" curl_request_url :: CString -> CString -> CInt -> Ptr CInt -> IO CString foreign import ccall "hscurl.h curl_wait_next_url" curl_wait_next_url :: Ptr CInt -> Ptr CLong-> IO CString foreign import ccall "hscurl.h curl_last_url" curl_last_url :: IO CString foreign import ccall "hscurl.h curl_enable_debug" curl_enable_debug :: IO () foreign import ccall "hscurl.h curl_pipelining_enabled" curl_pipelining_enabled :: IO CInt #endif darcs-2.14.5/src/Darcs/Util/Download/HTTP.hs0000644000000000000000000001003607346545000016512 0ustar0000000000000000{-# LANGUAGE CPP #-} module Darcs.Util.Download.HTTP ( fetchUrl, postUrl, requestUrl, waitNextUrl ) where import Prelude () import Darcs.Prelude import Darcs.Util.Global ( debugFail ) import Darcs.Util.Download.Request ( ConnectionError(..) ) import Control.Exception ( catch, IOException ) import Data.IORef ( newIORef, readIORef, writeIORef, IORef ) import Network.HTTP import Network.Browser ( browse, request, setCheckForProxy, setErrHandler, setOutHandler ) import Network.URI import System.IO.Error ( ioeGetErrorString ) import System.IO.Unsafe ( unsafePerformIO ) import Darcs.Util.Global ( debugMessage ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import Version ( version ) fetchUrl :: String -> IO String postUrl :: String -- ^ url -> String -- ^ body -> String -- ^ mime type -> IO () -- ^ result requestUrl :: String -> FilePath -> a -> IO String waitNextUrl :: IO (String, String, Maybe ConnectionError) headers :: [Header] headers = [Header HdrUserAgent $ "darcs-HTTP/" ++ version] fetchUrl url = case parseURI url of Nothing -> fail $ "Invalid URI: " ++ url Just uri -> do debugMessage $ "Fetching over HTTP: "++url resp <- catch (browse $ do setCheckForProxy True setOutHandler debugMessage setErrHandler debugMessage request Request { rqURI = uri, rqMethod = GET, rqHeaders = headers, rqBody = "" }) (\(err :: IOException) -> debugFail $ show err) case resp of (_, res@Response { rspCode = (2,0,0) }) -> return (rspBody res) (_, Response { rspCode = (x,y,z) }) -> debugFail $ "HTTP " ++ show x ++ show y ++ show z ++ " error getting " ++ show uri postUrl url body mime = case parseURI url of Nothing -> fail $ "Invalid URI: " ++ url Just uri -> do debugMessage $ "Posting to HTTP: "++url resp <- catch (browse $ do setCheckForProxy True setOutHandler debugMessage setErrHandler debugMessage request Request { rqURI = uri, rqMethod = POST, rqHeaders = headers ++ [Header HdrContentType mime, Header HdrAccept "text/plain", Header HdrContentLength (show $ length body) ], rqBody = body }) (\(err :: IOException) -> debugFail $ show err) case resp of (_, res@Response { rspCode = (2,y,z) }) -> do putStrLn $ "Success 2" ++ show y ++ show z putStrLn (rspBody res) return () (_, res@Response { rspCode = (x,y,z) }) -> do putStrLn $ rspBody res debugFail $ "HTTP " ++ show x ++ show y ++ show z ++ " error posting to " ++ show uri requestedUrl :: IORef (String, FilePath) requestedUrl = unsafePerformIO $ newIORef ("", "") requestUrl u f _ = do (u', _) <- readIORef requestedUrl if null u' then do writeIORef requestedUrl (u, f) return "" else return "URL already requested" waitNextUrl = do (u, f) <- readIORef requestedUrl if null u then return ("", "No URL requested", Nothing) else do writeIORef requestedUrl ("", "") e <- (fetchUrl u >>= \s -> B.writeFile f (BC.pack s) >> return "") `catch` h let ce = case e of "timeout" -> Just OperationTimeout _ -> Nothing return (u, e, ce) where h = return . ioeGetErrorString darcs-2.14.5/src/Darcs/Util/Download/Request.hs0000644000000000000000000000630707346545000017371 0ustar0000000000000000module Darcs.Util.Download.Request ( UrlRequest(..) , Cachable(..) , UrlState(..) , Q(..) , readQ , insertQ , pushQ , addUsingPriority , deleteQ , elemQ , emptyQ , nullQ , Priority(..) , ConnectionError(..) ) where import Prelude () import Darcs.Prelude import Data.List ( delete ) import Data.Map ( Map ) import Foreign.C.Types ( CInt ) data Priority = High | Low deriving Eq data Cachable = Cachable | Uncachable | MaxAge !CInt deriving (Show, Eq) -- | A UrlRequest object contains a url to get, the file into which the -- contents at the given url should be written, the cachability of this request -- and the request's priority. data UrlRequest = UrlRequest { url :: String , file :: FilePath , cachable :: Cachable , priority :: Priority } type InProgressStatus = ( FilePath -- FilePath to write url contents into , [FilePath] -- Extra paths to copy complete file into , Cachable -- Cachable status ) -- | A UrlState object contains a map of url -> InProgressStatus, a Q of urls -- waiting to be started, the current pipe length and the unique junk to -- create unique filenames. data UrlState = UrlState { inProgress :: Map String InProgressStatus , waitToStart :: Q String , pipeLength :: Int , randomJunk :: String } -- |Q represents a prioritised queue, with two-tier priority. The left list -- contains higher priority items than the right list. data Q a = Q [a] [a] -- |'readQ' will try and take an element from the Q, preferring elements from -- the high priority list. readQ :: Q a -> Maybe (a, Q a) readQ (Q (x : xs) ys) = return (x, Q xs ys) readQ (Q [] ys) = do x : xs <- return $ reverse ys return (x, Q xs []) -- | Return a function for adding an element based on the priority. addUsingPriority :: Priority -> a -> Q a -> Q a addUsingPriority High = pushQ addUsingPriority Low = insertQ -- |'insertQ' inserts a low priority item into a Q. insertQ :: a -> Q a -> Q a insertQ y (Q xs ys) = Q xs (y:ys) -- |'pushQ' inserts a high priority item into a Q. pushQ :: a -> Q a -> Q a pushQ x (Q xs ys) = Q (x:xs) ys -- |'deleteQ' removes any instances of a given element from the Q. deleteQ :: Eq a => a -> Q a -> Q a deleteQ x (Q xs ys) = Q (delete x xs) (delete x ys) -- |'deleteQ' checks for membership in a Q. elemQ :: Eq a => a -> Q a -> Bool elemQ x (Q xs ys) = x `elem` xs || x `elem` ys -- |'emptyQ' is an empty Q. emptyQ :: Q a emptyQ = Q [] [] -- |'nullQ' checks if the Q contains no items. nullQ :: Q a -> Bool nullQ (Q [] []) = True nullQ _ = False -- | Data type to represent a connection error. -- The following are the codes from libcurl -- which map to each of the constructors: -- * 6 -> CouldNotResolveHost : The remote host was not resolved. -- * 7 -> CouldNotConnectToServer : Failed to connect() to host or proxy. -- * 28 -> OperationTimeout: the specified time-out period was reached. data ConnectionError = CouldNotResolveHost | CouldNotConnectToServer | OperationTimeout deriving (Eq, Read, Show) darcs-2.14.5/src/Darcs/Util/Encoding.hs0000644000000000000000000000545007346545000015716 0ustar0000000000000000-- Copyright 2007-2009, Judah Jacobson. -- All Rights Reserved. -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- - Redistribution of source code must retain the above copyright notice, -- this list of conditions and the following disclaimer. -- - Redistribution in binary form must reproduce the above copyright notice, -- this list of conditions and the following disclaimer in the documentation -- and/or other materials provided with the distribution. -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -- DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTORS BE LIABLE -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -- SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -- USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. {-# LANGUAGE CPP #-} module Darcs.Util.Encoding ( encode, decode , encodeUtf8, decodeUtf8 ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString as B import GHC.IO.Encoding ( TextEncoding, mkTextEncoding ) import GHC.Foreign ( withCStringLen, peekCStringLen ) #ifdef WIN32 import Darcs.Util.Encoding.Win32 ( encode, decode ) #else import GHC.IO.Encoding ( getFileSystemEncoding ) -- | Encode a 'String' into a 'B.ByteString' according to the user's locale -- with the ghc specific //ROUNDTRIP feature added. This means the argument -- is allowed to contain non-Unicode 'Char's as produced by 'decode'. encode :: String -> IO B.ByteString encode s = getFileSystemEncoding >>= textEncode s -- | Decode a 'B.ByteString' into a 'String' according to the user's locale -- with the ghc specific //ROUNDTRIP feature added. This means the result -- may contain 'Char's that are not valid Unicode in case decoding with the -- user's locale fails. decode :: B.ByteString -> IO String decode bs = getFileSystemEncoding >>= textDecode bs #endif encodeUtf8 :: String -> IO B.ByteString encodeUtf8 s = mkTextEncoding "UTF-8//TRANSLIT" >>= textEncode s decodeUtf8 :: B.ByteString -> IO String decodeUtf8 bs = mkTextEncoding "UTF-8//TRANSLIT" >>= textDecode bs textEncode :: String -> TextEncoding -> IO B.ByteString textEncode s enc = withCStringLen enc s B.packCStringLen textDecode :: B.ByteString -> TextEncoding -> IO String textDecode bs enc = B.useAsCStringLen bs (peekCStringLen enc) darcs-2.14.5/src/Darcs/Util/Encoding/0000755000000000000000000000000007346545000015356 5ustar0000000000000000darcs-2.14.5/src/Darcs/Util/Encoding/Win32.hs0000644000000000000000000000722407346545000016621 0ustar0000000000000000-- Copyright 2007-2009, Judah Jacobson. -- All Rights Reserved. -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- - Redistribution of source code must retain the above copyright notice, -- this list of conditions and the following disclaimer. -- - Redistribution in binary form must reproduce the above copyright notice, -- this list of conditions and the following disclaimer in the documentation -- and/or other materials provided with the distribution. -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -- DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTORS BE LIABLE -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -- SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -- USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. {-# LANGUAGE ForeignFunctionInterface #-} module Darcs.Util.Encoding.Win32 ( encode, decode ) where import Prelude () import Darcs.Prelude import Data.ByteString.Internal ( createAndTrim ) import qualified Data.ByteString as B ( ByteString, useAsCStringLen ) import Foreign ( castPtr, allocaArray0 ) import Foreign.C ( CInt(..), peekCWStringLen, withCWStringLen ) import System.Win32 ( CodePage, nullPtr, getConsoleCP, getACP , LPCSTR, LPWSTR, LPCWSTR, LPBOOL, DWORD ) -- | Encode a Unicode 'String' into a 'ByteString' suitable for the current -- console. encode :: String -> IO B.ByteString encode str = getCodePage >>= flip unicodeToCodePage str -- | Convert a 'ByteString' from the console's encoding into a Unicode 'String'. decode :: B.ByteString -> IO String decode str = getCodePage >>= flip codePageToUnicode str ------------------------ -- Multi-byte conversion foreign import stdcall "WideCharToMultiByte" wideCharToMultiByte :: CodePage -> DWORD -> LPCWSTR -> CInt -> LPCSTR -> CInt -> LPCSTR -> LPBOOL -> IO CInt unicodeToCodePage :: CodePage -> String -> IO B.ByteString unicodeToCodePage cp wideStr = withCWStringLen wideStr $ \(wideBuff, wideLen) -> do -- first, ask for the length without filling the buffer. outSize <- wideCharToMultiByte cp 0 wideBuff (toEnum wideLen) nullPtr 0 nullPtr nullPtr -- then, actually perform the encoding. createAndTrim (fromEnum outSize) $ \outBuff -> fmap fromEnum $ wideCharToMultiByte cp 0 wideBuff (toEnum wideLen) (castPtr outBuff) outSize nullPtr nullPtr foreign import stdcall "MultiByteToWideChar" multiByteToWideChar :: CodePage -> DWORD -> LPCSTR -> CInt -> LPWSTR -> CInt -> IO CInt codePageToUnicode :: CodePage -> B.ByteString -> IO String codePageToUnicode cp bs = B.useAsCStringLen bs $ \(inBuff, inLen) -> do -- first ask for the size without filling the buffer. outSize <- multiByteToWideChar cp 0 inBuff (toEnum inLen) nullPtr 0 -- then, actually perform the decoding. allocaArray0 (fromEnum outSize) $ \outBuff -> do outSize' <- multiByteToWideChar cp 0 inBuff (toEnum inLen) outBuff outSize peekCWStringLen (outBuff, fromEnum outSize') getCodePage :: IO CodePage getCodePage = do conCP <- getConsoleCP if conCP > 0 then return conCP else getACP darcs-2.14.5/src/Darcs/Util/English.hs0000644000000000000000000000746007346545000015564 0ustar0000000000000000-- Copyright (C) 2008 Eric Kow -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | -- Copyright : 2008 Eric Kow -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable -- -- This modules provides rudimentary natural language generation -- (NLG) utilities. That is, generating natural language from a -- machine representation. Initially, only English is supported at -- all. Representations are implemented for: -- -- * countable nouns (plurality); and -- * lists of clauses (foo, bar and/or baz). module Darcs.Util.English where import Prelude () import Darcs.Prelude import Data.Char (toUpper) import Data.List (isSuffixOf) -- | > englishNum 0 (Noun "watch") "" == "watches" -- > englishNum 1 (Noun "watch") "" == "watch" -- > englishNum 2 (Noun "watch") "" == "watches" englishNum :: Countable n => Int -> n -> ShowS englishNum x = if x == 1 then singular else plural -- | Things that have a plural and singular spelling class Countable a where plural :: a -> ShowS singular :: a -> ShowS -- | This only distinguishes between nouns with a final -ch, -- and nouns which do not. -- More irregular nouns will just need to have their own type -- -- > plural (Noun "batch") "" == "batches" -- > plural (Noun "bat") "" == "bats" -- > plural (Noun "mouse") "" == "mouses" -- :-( newtype Noun = Noun String data Pronoun = It instance Countable Noun where -- more irregular nouns will just need to have their own type plural (Noun s) | "ch" `isSuffixOf` s = showString s . showString "es" plural (Noun s) | "y" `isSuffixOf` s && length s > 1 && last (init s) `notElem` "aeiou" = showString (init s) . showString "ies" plural (Noun s) = showString s . showChar 's' singular (Noun s) = showString s instance Countable Pronoun where plural It = showString "them" singular It = showString "it" -- | > singular This (Noun "batch") "" == "this batch" -- > plural This (Noun "batch") "" == "these batches" data This = This Noun instance Countable This where plural (This s) = showString "these " . plural s singular (This s) = showString "this " . singular s -- | Given a list of things, combine them thusly: -- -- > orClauses ["foo", "bar", "baz"] == "foo, bar or baz" andClauses, orClauses :: [String] -> String andClauses = itemize "and" orClauses = itemize "or" -- Should not be called with an empty list since this usually -- prints an extra space. We allow it for compatibility. itemize :: String -> [String] -> String itemize _ [] = "" -- error "precondition in Darcs.Util.English.itemize" itemize _ [x] = x itemize sep [x,x'] = unwords [x, sep, x'] itemize sep (x:x':xs) = itemize' x x' xs where itemize' y y' [] = unwords [y ++ ",", sep, y'] itemize' y y' (y'':ys) = unwords [y ++ ",", itemize' y' y'' ys] presentParticiple :: String -> String presentParticiple v | last v == 'e' = init v ++ "ing" | otherwise = v ++ "ing" -- | Capitalize the first letter of a word capitalize :: String -> String capitalize [] = [] capitalize (x:xs) = toUpper x : xs darcs-2.14.5/src/Darcs/Util/Exception.hs0000644000000000000000000000444507346545000016131 0ustar0000000000000000{-# Language MultiParamTypeClasses #-} module Darcs.Util.Exception ( firstJustIO , catchall , clarifyErrors , prettyException , prettyError , die ) where import Prelude () import Darcs.Prelude import Control.Exception ( SomeException, Exception(fromException), catch ) import Data.Maybe ( isJust ) import System.Exit ( exitFailure ) import System.IO ( stderr, hPutStrLn ) import System.IO.Error ( isUserError, ioeGetErrorString , isDoesNotExistError, ioeGetFileName ) import Darcs.Util.SignalHandler ( catchNonSignal ) catchall :: IO a -> IO a -> IO a a `catchall` b = a `catchNonSignal` (\_ -> b) -- | The firstJustM returns the first Just entry in a list of monadic -- operations. This is close to `listToMaybe `fmap` sequence`, but the sequence -- operator evaluates all monadic members of the list before passing it along -- (i.e. sequence is strict). The firstJustM is lazy in that list member monads -- are only evaluated up to the point where the first Just entry is obtained. firstJustM :: Monad m => [m (Maybe a)] -> m (Maybe a) firstJustM [] = return Nothing firstJustM (e:es) = e >>= (\v -> if isJust v then return v else firstJustM es) -- | The firstJustIO is a slight modification to firstJustM: the entries in the -- list must be IO monad operations and the firstJustIO will silently turn any -- monad call that throws an exception into Nothing, basically causing it to be -- ignored. firstJustIO :: [IO (Maybe a)] -> IO (Maybe a) firstJustIO = firstJustM . map (`catchall` return Nothing) clarifyErrors :: IO a -> String -> IO a clarifyErrors a e = a `catch` (\x -> die $ unlines [prettyException x,e]) prettyException :: SomeException -> String prettyException e | Just ioe <- fromException e, isUserError ioe = ioeGetErrorString ioe prettyException e | Just ioe <- fromException e, isDoesNotExistError ioe = case ioeGetFileName ioe of Just f -> f ++ " does not exist" Nothing -> show e prettyException e = show e prettyError :: IOError -> String prettyError e | isUserError e = ioeGetErrorString e | otherwise = show e -- | Terminate the program with an error message. die :: String -> IO a die msg = hPutStrLn stderr msg >> exitFailure darcs-2.14.5/src/Darcs/Util/Exec.hs0000644000000000000000000002040107346545000015045 0ustar0000000000000000-- Copyright (C) 2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE CPP, DeriveDataTypeable #-} -- | -- Module : Darcs.Util.Exec -- Copyright : 2003 David Roundy -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.Util.Exec ( exec , execInteractive , readInteractiveProcess , renderExecException , withoutNonBlock , Redirects , Redirect(..) , ExecException(..) ) where import Prelude () import Darcs.Prelude #ifndef WIN32 import Control.Exception ( bracket ) import System.Posix.Env ( setEnv, getEnv, unsetEnv ) import System.Posix.IO ( queryFdOption, setFdOption, FdOption(..), stdInput ) #else import Control.Exception ( catchJust, IOException ) import Data.List ( isInfixOf ) #endif import GHC.IO.Handle ( hDuplicate ) import Control.Concurrent ( forkIO ) import Control.Concurrent.MVar ( newEmptyMVar, takeMVar, putMVar ) import Control.Exception ( evaluate, bracketOnError, Exception(..), SomeException(..) ) import Data.Typeable ( Typeable, cast ) import System.Process ( system ) import qualified System.Process as P import System.Exit ( ExitCode (..) ) import System.IO ( IOMode(..), openBinaryFile, stdin, stdout, hGetContents, hClose ) import System.Process ( runProcess, terminateProcess, waitForProcess ) import Darcs.Util.Global ( whenDebugMode ) import Darcs.Util.Progress ( withoutProgress ) {- A redirection is a three-tuple of values (in, out, err). The most common values are: AsIs don't change it Null /dev/null on Unix, NUL on Windows File open a file for reading or writing There is also the value Stdout, which is only meaningful for redirection of errors, and is performed AFTER stdout is redirected so that output and errors mix together. StdIn and StdErr could be added as well if they are useful. NOTE: Lots of care must be taken when redirecting stdin, stdout and stderr to one of EACH OTHER, since the ORDER in which they are changed have a significant effect on the result. -} type Redirects = (Redirect, Redirect, Redirect) data Redirect = AsIs | Null | File FilePath | Stdout deriving Show {- ExecException is thrown by exec if any system call fails, for example because the executable we're trying to run doesn't exist. -} -- ExecException cmd args redirecs errorDesc data ExecException = ExecException String -- cmd [String] -- args Redirects -- redirects String -- errorDesc deriving (Typeable) instance Exception ExecException where toException = SomeException fromException (SomeException e) = cast e renderExecException :: ExecException -> String renderExecException (ExecException cmd args _ msg) = concat [ "The program \"", unwords (cmd:args), "\" failed with error: \"",msg,"\"."] instance Show ExecException where show = renderExecException _devNull :: FilePath #ifdef WIN32 _devNull = "NUL" #else _devNull = "/dev/null" #endif {- We use System.Process, which does the necessary quoting and redirection for us behind the scenes. -} exec :: String -> [String] -> Redirects -> IO ExitCode exec cmd args (inp,out,err) = withoutProgress $ do h_stdin <- redirect inp ReadMode h_stdout <- redirect out WriteMode h_stderr <- redirect err WriteMode withExit127 $ bracketOnError (do doOptionalDebug runProcess cmd args Nothing Nothing h_stdin h_stdout h_stderr) terminateProcess waitForProcess where doOptionalDebug = whenDebugMode . putStrLn . unwords $ cmd : args ++ ["; #"] ++ map show [inp, out, err] redirect AsIs _ = return Nothing redirect Null mode = Just `fmap` openBinaryFile _devNull mode redirect (File "/dev/null") mode = redirect Null mode redirect (File f) mode = Just `fmap` openBinaryFile f mode -- hDuplicate stdout rather than passing stdout itself, -- because runProcess closes the Handles we pass it. redirect Stdout _ = Just `fmap` hDuplicate stdout execInteractive :: String -> String -> IO ExitCode #ifndef WIN32 {- This should handle arbitrary commands interpreted by the shell on Unix since that's what people expect. But we don't want to allow the shell to interpret the argument in any way, so we set an environment variable and call cmd "$DARCS_ARGUMENT" -} execInteractive cmd arg = withoutProgress $ do let var = "DARCS_ARGUMENT" stdin `seq` return () withoutNonBlock $ bracket (do oldval <- getEnv var setEnv var arg True return oldval) (\oldval -> case oldval of Nothing -> unsetEnv var Just val -> setEnv var val True) (\_ -> withExit127 $ system $ cmd++" \"$"++var++"\"") #else -- The `system' function passes commands to execute via cmd.exe (or -- command.com) it's return value is equivalent to the one returned by the -- shell. For regular applications - this works correctly resulting in the -- exit code of the program. However in case of a command/file which can't be -- found - cmd.exe will return 1 instead of propagating the ExitFailure 9009 -- which on windows is equivalent to ExitFailure 127 from *nix machines. -- -- Here we force return the exit code of the last cmd.exe action by appending -- & exit !errorlevel! to the command being executed that way chaining with -- ortryrunning works correctly. -- -- SETLOCAL EnableDelayedExpansion makes sure that !variable! expansion is done -- correctly on systems where that function is not enabled by default. -- execInteractive cmd arg = withoutProgress $ withExit127 $ system $ "SETLOCAL EnableDelayedExpansion & " ++ cmd ++ " " ++ arg ++ " & exit !errorlevel!" #endif withoutNonBlock :: IO a -> IO a #ifndef WIN32 {- Do IO without NonBlockingRead on stdInput. This is needed when running unsuspecting external commands with interactive mode - if read from terminal is non-blocking also write to terminal is non-blocking. -} withoutNonBlock x = do nb <- queryFdOption stdInput NonBlockingRead if nb then bracket (setFdOption stdInput NonBlockingRead False) (\_ -> setFdOption stdInput NonBlockingRead True) (\_ -> x) else x #else withoutNonBlock x = x #endif readInteractiveProcess :: FilePath -- ^ command to run -> [String] -- ^ any arguments -> IO (ExitCode,String) -- ^ exitcode, stderr readInteractiveProcess cmd args = do inh' <- hDuplicate stdin outh <- hDuplicate stdout (_, _, Just errh, pid) <- P.createProcess (P.proc cmd args){ P.std_in = P.UseHandle inh', P.std_out = P.UseHandle outh, P.std_err = P.CreatePipe } errMVar <- newEmptyMVar errors <- hGetContents errh _ <- forkIO $ do _ <- evaluate (length errors) putMVar errMVar errors err <- takeMVar errMVar hClose errh ex <- waitForProcess pid return (ex, err) {- Ensure that we exit 127 if the thing we are trying to run does not exist (Only needed under Windows) -} withExit127 :: IO ExitCode -> IO ExitCode #ifdef WIN32 withExit127 a = catchJust notFoundError a (const $ return $ ExitFailure 127) notFoundError :: IOException -> Maybe () notFoundError e | "runProcess: does not exist" `isInfixOf` show e = Just () notFoundError _ = Nothing #else withExit127 = id #endif darcs-2.14.5/src/Darcs/Util/External.hs0000644000000000000000000001476507346545000015763 0ustar0000000000000000module Darcs.Util.External ( cloneTree , cloneFile , fetchFilePS , fetchFileLazyPS , gzFetchFilePS , speculateFileOrUrl , copyFileOrUrl , Cachable(..) , backupByRenaming , backupByCopying ) where import Control.Exception ( catch, IOException ) import System.Posix.Files ( getSymbolicLinkStatus , isRegularFile , isDirectory , createLink ) import System.Directory ( createDirectory , getDirectoryContents , doesDirectoryExist , doesFileExist , renameFile , renameDirectory , copyFile ) import System.FilePath.Posix ( (), normalise ) import System.IO.Error ( isDoesNotExistError ) import Control.Monad ( unless , when , zipWithM_ ) import Darcs.Util.Global ( defaultRemoteDarcsCmd ) import Darcs.Util.Download ( copyUrl , copyUrlFirst , waitUrl , Cachable(..) ) import Darcs.Util.URL ( isValidLocalPath , isHttpUrl , isSshUrl , splitSshUrl ) import Darcs.Util.Exception ( catchall ) import Darcs.Util.Lock ( withTemp ) import Darcs.Util.Ssh ( copySSH ) import Darcs.Util.ByteString ( gzReadFilePS ) import qualified Data.ByteString as B (ByteString, readFile ) import qualified Data.ByteString.Lazy as BL import Network.Browser ( browse , request , setErrHandler , setOutHandler , setAllowRedirects ) import Network.HTTP ( RequestMethod(GET) , rspCode , rspBody , rspReason , mkRequest ) import Network.URI ( parseURI , uriScheme ) copyFileOrUrl :: String -- ^ remote darcs executable -> FilePath -- ^ path representing the origin file or URL -> FilePath -- ^ destination path -> Cachable -- ^ tell whether file to copy is cachable -> IO () copyFileOrUrl _ fou out _ | isValidLocalPath fou = copyLocal fou out copyFileOrUrl _ fou out cache | isHttpUrl fou = copyRemote fou out cache copyFileOrUrl rd fou out _ | isSshUrl fou = copySSH rd (splitSshUrl fou) out copyFileOrUrl _ fou _ _ = fail $ "unknown transport protocol: " ++ fou copyLocal :: String -> FilePath -> IO () copyLocal fou out = createLink fou out `catchall` cloneFile fou out cloneTree :: FilePath -> FilePath -> IO () cloneTree = cloneTreeExcept [] cloneTreeExcept :: [FilePath] -> FilePath -> FilePath -> IO () cloneTreeExcept except source dest = do fs <- getSymbolicLinkStatus source if isDirectory fs then do fps <- getDirectoryContents source let fps' = filter (`notElem` (".":"..":except)) fps mk_source fp = source fp mk_dest fp = dest fp zipWithM_ cloneSubTree (map mk_source fps') (map mk_dest fps') else fail ("cloneTreeExcept: Bad source " ++ source) `catch` \(_ :: IOException) -> fail ("cloneTreeExcept: Bad source " ++ source) cloneSubTree :: FilePath -> FilePath -> IO () cloneSubTree source dest = do fs <- getSymbolicLinkStatus source if isDirectory fs then do createDirectory dest fps <- getDirectoryContents source let fps' = filter (`notElem` [".", ".."]) fps mk_source fp = source fp mk_dest fp = dest fp zipWithM_ cloneSubTree (map mk_source fps') (map mk_dest fps') else if isRegularFile fs then cloneFile source dest else fail ("cloneSubTree: Bad source "++ source) `catch` (\e -> unless (isDoesNotExistError e) $ ioError e) cloneFile :: FilePath -> FilePath -> IO () cloneFile = copyFile backupByRenaming :: FilePath -> IO () backupByRenaming = backupBy rename where rename x y = do isD <- doesDirectoryExist x if isD then renameDirectory x y else renameFile x y backupByCopying :: FilePath -> IO () backupByCopying = backupBy copy where copy x y = do isD <- doesDirectoryExist x if isD then do createDirectory y cloneTree (normalise x) (normalise y) else copyFile x y backupBy :: (FilePath -> FilePath -> IO ()) -> FilePath -> IO () backupBy backup f = do hasBF <- doesFileExist f hasBD <- doesDirectoryExist f when (hasBF || hasBD) $ helper 0 where helper :: Int -> IO () helper i = do existsF <- doesFileExist next existsD <- doesDirectoryExist next if existsF || existsD then helper (i + 1) else do putStrLn $ "Backing up " ++ f ++ "(" ++ suffix ++ ")" backup f next where next = f ++ suffix suffix = ".~" ++ show i ++ "~" copyAndReadFile :: (FilePath -> IO a) -> String -> Cachable -> IO a copyAndReadFile readfn fou _ | isValidLocalPath fou = readfn fou copyAndReadFile readfn fou cache = withTemp $ \t -> do copyFileOrUrl defaultRemoteDarcsCmd fou t cache readfn t -- | @fetchFile fileOrUrl cache@ returns the content of its argument (either a -- file or an URL). If it has to download an url, then it will use a cache as -- required by its second argument. -- -- We always use default remote darcs, since it is not fatal if the remote -- darcs does not exist or is too old -- anything that supports transfer-mode -- should do, and if not, we will fall back to SFTP or SCP. fetchFilePS :: String -> Cachable -> IO B.ByteString fetchFilePS = copyAndReadFile (B.readFile) -- | @fetchFileLazyPS fileOrUrl cache@ lazily reads the content of its argument -- (either a file or an URL). Warning: this function may constitute a fd leak; -- make sure to force consumption of file contents to avoid that. See -- "fetchFilePS" for details. fetchFileLazyPS :: String -> Cachable -> IO BL.ByteString fetchFileLazyPS x c = case parseURI x of Just x' | uriScheme x' == "http:" -> do rsp <- fmap snd . browse $ do setErrHandler . const $ return () setOutHandler . const $ return () setAllowRedirects True request $ mkRequest GET x' if rspCode rsp /= (2, 0, 0) then fail $ "fetchFileLazyPS: " ++ rspReason rsp else return $ rspBody rsp _ -> copyAndReadFile BL.readFile x c gzFetchFilePS :: String -> Cachable -> IO B.ByteString gzFetchFilePS = copyAndReadFile gzReadFilePS copyRemote :: String -> FilePath -> Cachable -> IO () copyRemote u v cache = copyUrlFirst u v cache >> waitUrl u speculateFileOrUrl :: String -> FilePath -> IO () speculateFileOrUrl fou out | isHttpUrl fou = speculateRemote fou out | otherwise = return () speculateRemote :: String -> FilePath -> IO () -- speculations are always Cachable speculateRemote u v = copyUrl u v Cachable darcs-2.14.5/src/Darcs/Util/File.hs0000644000000000000000000001011107346545000015035 0ustar0000000000000000{-# LANGUAGE CPP #-} module Darcs.Util.File ( -- * Files and directories getFileStatus , withCurrentDirectory , doesDirectoryReallyExist , removeFileMayNotExist -- * OS-dependent special directories , xdgCacheDir , osxCacheDir , getDirectoryContents , getRecursiveContents , getRecursiveContentsFullPath ) where import Prelude ( lookup ) import Darcs.Prelude import Control.Exception ( catch, bracket ) import Control.Monad ( when, unless, forM ) import System.Environment ( getEnvironment ) import System.Directory ( removeFile, getHomeDirectory, getAppUserDataDirectory, doesDirectoryExist, createDirectory, getDirectoryContents ) import System.IO.Error ( isDoesNotExistError, catchIOError ) import System.Posix.Files( getSymbolicLinkStatus, FileStatus, isDirectory ) #ifndef WIN32 import System.Posix.Files( setFileMode, ownerModes ) #endif import System.FilePath.Posix ( () ) import Darcs.Util.Exception ( catchall ) import Darcs.Util.Path( FilePathLike, getCurrentDirectory, setCurrentDirectory, toFilePath ) withCurrentDirectory :: FilePathLike p => p -> IO a -> IO a withCurrentDirectory name m = bracket (do cwd <- getCurrentDirectory when (toFilePath name /= "") (setCurrentDirectory name) return cwd) (\oldwd -> setCurrentDirectory oldwd `catchall` return ()) (const m) getFileStatus :: FilePath -> IO (Maybe FileStatus) getFileStatus f = Just `fmap` getSymbolicLinkStatus f `catchIOError` (\_-> return Nothing) doesDirectoryReallyExist :: FilePath -> IO Bool doesDirectoryReallyExist f = catchNonExistence (isDirectory `fmap` getSymbolicLinkStatus f) False removeFileMayNotExist :: FilePathLike p => p -> IO () removeFileMayNotExist f = catchNonExistence (removeFile $ toFilePath f) () catchNonExistence :: IO a -> a -> IO a catchNonExistence job nonexistval = catch job $ \e -> if isDoesNotExistError e then return nonexistval else ioError e -- |osxCacheDir assumes @~/Library/Caches/@ exists. osxCacheDir :: IO (Maybe FilePath) osxCacheDir = do home <- getHomeDirectory return $ Just $ home "Library" "Caches" `catchall` return Nothing -- |xdgCacheDir returns the $XDG_CACHE_HOME environment variable, -- or @~/.cache@ if undefined. See the FreeDesktop specification: -- http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html xdgCacheDir :: IO (Maybe FilePath) xdgCacheDir = do env <- getEnvironment d <- case lookup "XDG_CACHE_HOME" env of Just d -> return d Nothing -> getAppUserDataDirectory "cache" exists <- doesDirectoryExist d -- If directory does not exist, create it with permissions 0700 -- as specified by the FreeDesktop standard. unless exists $ do createDirectory d #ifndef WIN32 -- see http://bugs.darcs.net/issue2334 setFileMode d ownerModes #endif return $ Just d `catchall` return Nothing -- |getRecursiveContents returns all files under topdir that aren't -- directories. getRecursiveContents :: FilePath -> IO [FilePath] getRecursiveContents topdir = do names <- getDirectoryContents topdir let properNames = filter (`notElem` [".", ".."]) names paths <- forM properNames $ \name -> do let path = topdir name isDir <- doesDirectoryExist path if isDir then getRecursiveContents path else return [name] return (concat paths) -- |getRecursiveContentsFullPath returns all files under topdir -- that aren't directories. -- Unlike getRecursiveContents this function returns the full path. getRecursiveContentsFullPath :: FilePath -> IO [FilePath] getRecursiveContentsFullPath topdir = do names <- getDirectoryContents topdir let properNames = filter (`notElem` [".", ".."]) names paths <- forM properNames $ \name -> do let path = topdir name isDir <- doesDirectoryExist path if isDir then getRecursiveContentsFullPath path else return [path] return (concat paths) darcs-2.14.5/src/Darcs/Util/Global.hs0000644000000000000000000001153607346545000015372 0ustar0000000000000000-- Copyright (C) 2005 Tomasz Zielonka -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | -- Module : Darcs.Util.Global -- Copyright : 2005 Tomasz Zielonka -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable -- -- This was originally Tomasz Zielonka's AtExit module, slightly generalised -- to include global variables. Here, we attempt to cover broad, global -- features, such as exit handlers. These features slightly break the Haskellian -- purity of darcs, in favour of programming convenience. module Darcs.Util.Global ( timingsMode , setTimingsMode , whenDebugMode , withDebugMode , setDebugMode , debugMessage , debugFail , putTiming , addCRCWarning , getCRCWarnings , resetCRCWarnings , addBadSource , getBadSourcesList , isBadSource , darcsdir , darcsLastMessage , darcsSendMessage , darcsSendMessageFinal , defaultRemoteDarcsCmd , isReachableSource , addReachableSource ) where import Prelude () import Darcs.Prelude import Control.Monad ( when ) import Data.IORef ( modifyIORef, IORef, newIORef, readIORef, writeIORef ) import System.IO.Unsafe (unsafePerformIO) import System.IO ( hPutStrLn, hPutStr, stderr ) import System.Time ( calendarTimeToString, toCalendarTime, getClockTime ) import System.FilePath.Posix ( combine, (<.>) ) -- Write-once-read-many global variables make it easier to implement flags, such -- as --no-ssh-cm. Using global variables reduces the number of parameters that -- we have to pass around, but it is rather unsafe and should be used sparingly. _debugMode :: IORef Bool _debugMode = unsafePerformIO $ newIORef False {-# NOINLINE _debugMode #-} setDebugMode :: IO () setDebugMode = writeIORef _debugMode True whenDebugMode :: IO () -> IO () whenDebugMode j = do b <- readIORef _debugMode when b j withDebugMode :: (Bool -> IO a) -> IO a withDebugMode j = readIORef _debugMode >>= j debugMessage :: String -> IO () debugMessage m = whenDebugMode $ do putTiming; hPutStrLn stderr m debugFail :: String -> IO a debugFail m = debugMessage m >> fail m putTiming :: IO () putTiming = when timingsMode $ do t <- getClockTime >>= toCalendarTime hPutStr stderr (calendarTimeToString t++": ") _timingsMode :: IORef Bool _timingsMode = unsafePerformIO $ newIORef False {-# NOINLINE _timingsMode #-} setTimingsMode :: IO () setTimingsMode = writeIORef _timingsMode True timingsMode :: Bool timingsMode = unsafePerformIO $ readIORef _timingsMode {-# NOINLINE timingsMode #-} type CRCWarningList = [FilePath] _crcWarningList :: IORef CRCWarningList _crcWarningList = unsafePerformIO $ newIORef [] {-# NOINLINE _crcWarningList #-} addCRCWarning :: FilePath -> IO () addCRCWarning fp = modifyIORef _crcWarningList (fp:) getCRCWarnings :: IO [FilePath] getCRCWarnings = readIORef _crcWarningList resetCRCWarnings :: IO () resetCRCWarnings = writeIORef _crcWarningList [] _badSourcesList :: IORef [String] _badSourcesList = unsafePerformIO $ newIORef [] {-# NOINLINE _badSourcesList #-} addBadSource :: String -> IO () addBadSource cache = modifyIORef _badSourcesList (cache:) getBadSourcesList :: IO [String] getBadSourcesList = readIORef _badSourcesList isBadSource :: IO (String -> Bool) isBadSource = do badSources <- getBadSourcesList return (`elem` badSources) _reachableSourcesList :: IORef [String] _reachableSourcesList = unsafePerformIO $ newIORef [] {-# NOINLINE _reachableSourcesList #-} addReachableSource :: String -> IO () addReachableSource src = modifyIORef _reachableSourcesList (src:) getReachableSources :: IO [String] getReachableSources = readIORef _reachableSourcesList isReachableSource :: IO (String -> Bool) isReachableSource = do reachableSources <- getReachableSources return (`elem` reachableSources) darcsdir :: String darcsdir = "_darcs" defaultRemoteDarcsCmd :: String defaultRemoteDarcsCmd = "darcs" darcsLastMessage :: String darcsLastMessage = combine darcsdir "patch_description.txt" darcsSendMessage :: String darcsSendMessage = combine darcsdir "darcs-send" darcsSendMessageFinal :: String darcsSendMessageFinal = darcsSendMessage <.> "final" darcs-2.14.5/src/Darcs/Util/Hash.hs0000644000000000000000000002531407346545000015054 0ustar0000000000000000-- Copyright (C) 2009-2011 Petr Rockai BSD3 -- Copyright (C) 2001, 2004 Ian Lynagh {-# LANGUAGE CPP, DeriveDataTypeable #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-} -- TODO switch to cryptonite module Darcs.Util.Hash ( Hash(..) , encodeBase16, decodeBase16, sha256, sha256sum, rawHash , match -- SHA1 related (patch metadata hash) , sha1PS, SHA1, showAsHex, sha1Xor, sha1zero, sha1short ) where import qualified Crypto.Hash.SHA256 as SHA256 ( hashlazy, hash ) import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Internal as BI ( toForeignPtr ) import qualified Codec.Binary.Base16 as B16 import Data.Maybe( isJust, fromJust ) import Data.Char( toLower, toUpper, intToDigit ) import Data.Binary ( Binary(..) ) import Data.Bits (xor, (.&.), (.|.), complement, rotateL, shiftL, shiftR) import Data.Word (Word8, Word32) import Data.Data( Data ) import Data.Typeable( Typeable ) import Foreign.ForeignPtr ( withForeignPtr ) import Foreign.Ptr (Ptr, castPtr, plusPtr) import Foreign.Marshal.Array (advancePtr) import Foreign.Storable (peek, poke) import System.IO.Unsafe (unsafePerformIO) data Hash = SHA256 !B.ByteString | NoHash deriving (Show, Eq, Ord, Read, Typeable, Data) base16 :: B.ByteString -> B.ByteString debase16 :: B.ByteString -> Maybe B.ByteString base16 = BC.map toLower . B16.b16Enc debase16 bs = case B16.b16Dec $ BC.map toUpper bs of Right (s, _) -> Just s Left _ -> Nothing -- | Produce a base16 (ascii-hex) encoded string from a hash. This can be -- turned back into a Hash (see "decodeBase16". This is a loss-less process. encodeBase16 :: Hash -> B.ByteString encodeBase16 (SHA256 bs) = base16 bs encodeBase16 NoHash = B.empty -- | Take a base16-encoded string and decode it as a "Hash". If the string is -- malformed, yields NoHash. decodeBase16 :: B.ByteString -> Hash decodeBase16 bs | B.length bs == 64 && isJust (debase16 bs) = SHA256 (fromJust $ debase16 bs) | otherwise = NoHash -- | Compute a sha256 of a (lazy) ByteString. sha256 :: BL.ByteString -> Hash sha256 bits = SHA256 $ SHA256.hashlazy bits -- | Same as previous but general purpose. sha256sum :: B.ByteString -> String sha256sum = BC.unpack . base16 . SHA256.hash rawHash :: Hash -> B.ByteString rawHash NoHash = error "Cannot obtain raw hash from NoHash." rawHash (SHA256 s) = s match :: Hash -> Hash -> Bool NoHash `match` _ = False _ `match` NoHash = False x `match` y = x == y data SHA1 = SHA1 !Word32 !Word32 !Word32 !Word32 !Word32 deriving (Eq,Ord) data XYZ = XYZ !Word32 !Word32 !Word32 instance Show SHA1 where show (SHA1 a b c d e) = concatMap showAsHex [a, b, c, d, e] instance Binary SHA1 where put (SHA1 a b c d e) = put a >> put b >> put c >> put d >> put e get = do a <- get ; b <- get ; c <- get ; d <- get ; e <- get ; return (SHA1 a b c d e) sha1Xor :: SHA1 -> SHA1 -> SHA1 sha1Xor (SHA1 a1 b1 c1 d1 e1) (SHA1 a2 b2 c2 d2 e2) = SHA1 (a1 `xor` a2) (b1 `xor` b2) (c1 `xor` c2) (d1 `xor` d2) (e1 `xor` e2) sha1zero :: SHA1 sha1zero = SHA1 0 0 0 0 0 sha1short :: SHA1 -> Word32 sha1short (SHA1 a _ _ _ _) = a -- | Do something with the internals of a PackedString. Beware of -- altering the contents! unsafeWithInternals :: B.ByteString -> (Ptr Word8 -> Int -> IO a) -> IO a unsafeWithInternals ps f = case BI.toForeignPtr ps of (fp,s,l) -> withForeignPtr fp $ \p -> f (p `plusPtr` s) l sha1PS:: B.ByteString -> SHA1 sha1PS s = abcde' where s1_2 = sha1Step12PadLength s abcde = sha1Step3Init abcde' = unsafePerformIO $ unsafeWithInternals s1_2 (\ptr len -> do let ptr' = castPtr ptr #ifndef BIGENDIAN fiddleEndianness ptr' len #endif sha1Step4Main abcde ptr' len) fiddleEndianness :: Ptr Word32 -> Int -> IO () fiddleEndianness p 0 = p `seq` return () fiddleEndianness p n = do x <- peek p poke p $ shiftL x 24 .|. shiftL (x .&. 0xff00) 8 .|. (shiftR x 8 .&. 0xff00) .|. shiftR x 24 fiddleEndianness (p `advancePtr` 1) (n - 4) -- sha1Step12PadLength assumes the length is at most 2^61. -- This seems reasonable as the Int used to represent it is normally 32bit, -- but obviously could go wrong with large inputs on 64bit machines. -- The B.ByteString library should probably move to Word64s if this is an -- issue, though. sha1Step12PadLength :: B.ByteString -> B.ByteString sha1Step12PadLength s = let len = B.length s num_nuls = (55 - len) `mod` 64 padding = 128:replicate num_nuls 0 len_w8s = reverse $ sizeSplit 8 (fromIntegral len*8) in B.concat [s, B.pack padding, B.pack len_w8s] sizeSplit :: Int -> Integer -> [Word8] sizeSplit 0 _ = [] sizeSplit p n = fromIntegral d:sizeSplit (p-1) n' where (n', d) = divMod n 256 sha1Step3Init :: SHA1 sha1Step3Init = SHA1 0x67452301 0xefcdab89 0x98badcfe 0x10325476 0xc3d2e1f0 sha1Step4Main :: SHA1 -> Ptr Word32 -> Int -> IO SHA1 sha1Step4Main abcde _ 0 = return $! abcde sha1Step4Main (SHA1 a0@a b0@b c0@c d0@d e0@e) s len = do (e, b) <- doit f1 0x5a827999 (x 0) a b c d e (d, a) <- doit f1 0x5a827999 (x 1) e a b c d (c, e) <- doit f1 0x5a827999 (x 2) d e a b c (b, d) <- doit f1 0x5a827999 (x 3) c d e a b (a, c) <- doit f1 0x5a827999 (x 4) b c d e a (e, b) <- doit f1 0x5a827999 (x 5) a b c d e (d, a) <- doit f1 0x5a827999 (x 6) e a b c d (c, e) <- doit f1 0x5a827999 (x 7) d e a b c (b, d) <- doit f1 0x5a827999 (x 8) c d e a b (a, c) <- doit f1 0x5a827999 (x 9) b c d e a (e, b) <- doit f1 0x5a827999 (x 10) a b c d e (d, a) <- doit f1 0x5a827999 (x 11) e a b c d (c, e) <- doit f1 0x5a827999 (x 12) d e a b c (b, d) <- doit f1 0x5a827999 (x 13) c d e a b (a, c) <- doit f1 0x5a827999 (x 14) b c d e a (e, b) <- doit f1 0x5a827999 (x 15) a b c d e (d, a) <- doit f1 0x5a827999 (m 16) e a b c d (c, e) <- doit f1 0x5a827999 (m 17) d e a b c (b, d) <- doit f1 0x5a827999 (m 18) c d e a b (a, c) <- doit f1 0x5a827999 (m 19) b c d e a (e, b) <- doit f2 0x6ed9eba1 (m 20) a b c d e (d, a) <- doit f2 0x6ed9eba1 (m 21) e a b c d (c, e) <- doit f2 0x6ed9eba1 (m 22) d e a b c (b, d) <- doit f2 0x6ed9eba1 (m 23) c d e a b (a, c) <- doit f2 0x6ed9eba1 (m 24) b c d e a (e, b) <- doit f2 0x6ed9eba1 (m 25) a b c d e (d, a) <- doit f2 0x6ed9eba1 (m 26) e a b c d (c, e) <- doit f2 0x6ed9eba1 (m 27) d e a b c (b, d) <- doit f2 0x6ed9eba1 (m 28) c d e a b (a, c) <- doit f2 0x6ed9eba1 (m 29) b c d e a (e, b) <- doit f2 0x6ed9eba1 (m 30) a b c d e (d, a) <- doit f2 0x6ed9eba1 (m 31) e a b c d (c, e) <- doit f2 0x6ed9eba1 (m 32) d e a b c (b, d) <- doit f2 0x6ed9eba1 (m 33) c d e a b (a, c) <- doit f2 0x6ed9eba1 (m 34) b c d e a (e, b) <- doit f2 0x6ed9eba1 (m 35) a b c d e (d, a) <- doit f2 0x6ed9eba1 (m 36) e a b c d (c, e) <- doit f2 0x6ed9eba1 (m 37) d e a b c (b, d) <- doit f2 0x6ed9eba1 (m 38) c d e a b (a, c) <- doit f2 0x6ed9eba1 (m 39) b c d e a (e, b) <- doit f3 0x8f1bbcdc (m 40) a b c d e (d, a) <- doit f3 0x8f1bbcdc (m 41) e a b c d (c, e) <- doit f3 0x8f1bbcdc (m 42) d e a b c (b, d) <- doit f3 0x8f1bbcdc (m 43) c d e a b (a, c) <- doit f3 0x8f1bbcdc (m 44) b c d e a (e, b) <- doit f3 0x8f1bbcdc (m 45) a b c d e (d, a) <- doit f3 0x8f1bbcdc (m 46) e a b c d (c, e) <- doit f3 0x8f1bbcdc (m 47) d e a b c (b, d) <- doit f3 0x8f1bbcdc (m 48) c d e a b (a, c) <- doit f3 0x8f1bbcdc (m 49) b c d e a (e, b) <- doit f3 0x8f1bbcdc (m 50) a b c d e (d, a) <- doit f3 0x8f1bbcdc (m 51) e a b c d (c, e) <- doit f3 0x8f1bbcdc (m 52) d e a b c (b, d) <- doit f3 0x8f1bbcdc (m 53) c d e a b (a, c) <- doit f3 0x8f1bbcdc (m 54) b c d e a (e, b) <- doit f3 0x8f1bbcdc (m 55) a b c d e (d, a) <- doit f3 0x8f1bbcdc (m 56) e a b c d (c, e) <- doit f3 0x8f1bbcdc (m 57) d e a b c (b, d) <- doit f3 0x8f1bbcdc (m 58) c d e a b (a, c) <- doit f3 0x8f1bbcdc (m 59) b c d e a (e, b) <- doit f2 0xca62c1d6 (m 60) a b c d e (d, a) <- doit f2 0xca62c1d6 (m 61) e a b c d (c, e) <- doit f2 0xca62c1d6 (m 62) d e a b c (b, d) <- doit f2 0xca62c1d6 (m 63) c d e a b (a, c) <- doit f2 0xca62c1d6 (m 64) b c d e a (e, b) <- doit f2 0xca62c1d6 (m 65) a b c d e (d, a) <- doit f2 0xca62c1d6 (m 66) e a b c d (c, e) <- doit f2 0xca62c1d6 (m 67) d e a b c (b, d) <- doit f2 0xca62c1d6 (m 68) c d e a b (a, c) <- doit f2 0xca62c1d6 (m 69) b c d e a (e, b) <- doit f2 0xca62c1d6 (m 70) a b c d e (d, a) <- doit f2 0xca62c1d6 (m 71) e a b c d (c, e) <- doit f2 0xca62c1d6 (m 72) d e a b c (b, d) <- doit f2 0xca62c1d6 (m 73) c d e a b (a, c) <- doit f2 0xca62c1d6 (m 74) b c d e a (e, b) <- doit f2 0xca62c1d6 (m 75) a b c d e (d, a) <- doit f2 0xca62c1d6 (m 76) e a b c d (c, e) <- doit f2 0xca62c1d6 (m 77) d e a b c (b, d) <- doit f2 0xca62c1d6 (m 78) c d e a b (a, c) <- doit f2 0xca62c1d6 (m 79) b c d e a let abcde' = SHA1 (a0 + a) (b0 + b) (c0 + c) (d0 + d) (e0 + e) sha1Step4Main abcde' (s `advancePtr` 16) (len - 64) where {-# INLINE f1 #-} f1 (XYZ x y z) = (x .&. y) .|. (complement x .&. z) {-# INLINE f2 #-} f2 (XYZ x y z) = x `xor` y `xor` z {-# INLINE f3 #-} f3 (XYZ x y z) = (x .&. y) .|. (x .&. z) .|. (y .&. z) {-# INLINE x #-} x n = peek (s `advancePtr` n) {-# INLINE m #-} m n = do let base = s `advancePtr` (n .&. 15) x0 <- peek base x1 <- peek (s `advancePtr` ((n - 14) .&. 15)) x2 <- peek (s `advancePtr` ((n - 8) .&. 15)) x3 <- peek (s `advancePtr` ((n - 3) .&. 15)) let res = rotateL (x0 `xor` x1 `xor` x2 `xor` x3) 1 poke base res return res {-# INLINE doit #-} doit f k i a b c d e = a `seq` c `seq` do i' <- i return (rotateL a 5 + f (XYZ b c d) + e + i' + k, rotateL b 30) showAsHex :: Word32 -> String showAsHex n = showIt 8 n "" where showIt :: Int -> Word32 -> String -> String showIt 0 _ r = r showIt i x r = case quotRem x 16 of (y, z) -> let c = intToDigit (fromIntegral z) in c `seq` showIt (i-1) y (c:r) darcs-2.14.5/src/Darcs/Util/Index.hs0000644000000000000000000006444007346545000015243 0ustar0000000000000000-- Copyright (C) 2009-2011 Petr Rockai -- (C) 2013 Jose Neder -- BSD3 {-# LANGUAGE CPP, ScopedTypeVariables, MultiParamTypeClasses #-} -- | This module contains plain tree indexing code. The index itself is a -- CACHE: you should only ever use it as an optimisation and never as a primary -- storage. In practice, this means that when we change index format, the -- application is expected to throw the old index away and build a fresh -- index. Please note that tracking index validity is out of scope for this -- library: this is responsibility of your application. It is advisable that in -- your validity tracking code, you also check for format validity (see -- 'indexFormatValid') and scrap and re-create index when needed. -- -- The index is a binary file that overlays a hashed tree over the working -- copy. This means that every working file and directory has an entry in the -- index, that contains its path and hash and validity data. The validity data -- is a timestamp plus the file size. The file hashes are sha256's of the -- file's content. It also contains the fileid to track moved files. -- -- There are two entry types, a file entry and a directory entry. Both have a -- common binary format (see 'Item'). The on-disk format is best described by -- the section /Index format/ below. -- -- For each file, the index has a copy of the file's last modification -- timestamp taken at the instant when the hash has been computed. This means -- that when file size and timestamp of a file in working copy matches those in -- the index, we assume that the hash stored in the index for given file is -- valid. These hashes are then exposed in the resulting 'Tree' object, and can -- be leveraged by eg. 'diffTrees' to compare many files quickly. -- -- You may have noticed that we also keep hashes of directories. These are -- assumed to be valid whenever the complete subtree has been valid. At any -- point, as soon as a size or timestamp mismatch is found, the working file in -- question is opened, its hash (and timestamp and size) is recomputed and -- updated in-place in the index file (everything lives at a fixed offset and -- is fixed size, so this isn't an issue). This is also true of directories: -- when a file in a directory changes hash, this triggers recomputation of all -- of its parent directory hashes; moreover this is done efficiently -- each -- directory is updated at most once during an update run. -- -- /Index format/ -- -- The Index is organised into \"lines\" where each line describes a single -- indexed item. Cf. 'Item'. -- -- The first word on the index \"line\" is the length of the file path (which is -- the only variable-length part of the line). Then comes the path itself, then -- fixed-length hash (sha256) of the file in question, then three words, one for -- size, one for "aux", which is used differently for directories and for files, and -- one for the fileid (inode or fhandle) of the file. -- -- With directories, this aux holds the offset of the next sibling line in the -- index, so we can efficiently skip reading the whole subtree starting at a -- given directory (by just seeking aux bytes forward). The lines are -- pre-ordered with respect to directory structure -- the directory comes first -- and after it come all its items. Cf. 'readIndex''. -- -- For files, the aux field holds a timestamp. module Darcs.Util.Index( readIndex, updateIndexFrom, indexFormatValid , updateIndex, listFileIDs, Index, filter , getFileID -- for testing , align , xlate32 , xlate64 ) where import Prelude hiding ( lookup, readFile, writeFile, filter, (<$>) ) import Darcs.Util.ByteString ( readSegment, decodeLocale ) import Darcs.Util.File ( getFileStatus ) import Darcs.Util.Hash( sha256, rawHash ) import Darcs.Util.Tree import Darcs.Util.Path ( AnchoredPath(..) , anchorPath , anchoredRoot , unsafeMakeName , appendPath , flatten ) import Control.Monad( when ) import Control.Exception( catch, SomeException ) import Control.Applicative( (<$>) ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import Data.ByteString.Unsafe( unsafeHead, unsafeDrop ) import Data.ByteString.Internal( toForeignPtr, fromForeignPtr, memcpy , nullForeignPtr, c2w ) import Data.Bits( Bits ) #ifdef BIGENDIAN import Data.Bits( (.&.), (.|.), shift, shiftL, rotateR ) #endif import Data.Int( Int64, Int32 ) import Data.IORef( ) import Data.Maybe( fromJust, isJust, fromMaybe ) import Foreign.Storable import Foreign.ForeignPtr( ForeignPtr, withForeignPtr, castForeignPtr ) import Foreign.Ptr( Ptr, plusPtr ) import System.IO.MMap( mmapFileForeignPtr, mmapFileByteString, Mode(..) ) import System.Directory( doesFileExist, getCurrentDirectory, doesDirectoryExist ) #if mingw32_HOST_OS import System.Directory( renameFile ) import System.FilePath( (<.>) ) #else import System.Directory( removeFile ) #endif #ifdef WIN32 import System.Win32.File ( createFile, getFileInformationByHandle, BY_HANDLE_FILE_INFORMATION(..), fILE_SHARE_NONE, fILE_FLAG_BACKUP_SEMANTICS, gENERIC_NONE, oPEN_EXISTING, closeHandle ) #else import qualified System.Posix.Files as F ( getSymbolicLinkStatus, fileID ) #endif import System.FilePath ( () ) import qualified System.Posix.Files as F ( modificationTime, fileSize, isDirectory , FileStatus ) import System.Posix.Types ( FileID, EpochTime, FileOffset ) -------------------------- -- Indexed trees -- -- | Description of a a single indexed item. The structure itself does not -- contain any data, just pointers to the underlying mmap (bytestring is a -- pointer + offset + length). -- -- The structure is recursive-ish (as opposed to flat-ish structure, which is -- used by git...) It turns out that it's hard to efficiently read a flat index -- with our internal data structures -- we need to turn the flat index into a -- recursive Tree object, which is rather expensive... As a bonus, we can also -- efficiently implement subtree queries this way (cf. 'readIndex'). data Item = Item { iBase :: !(Ptr ()) , iHashAndDescriptor :: !B.ByteString } deriving Show size_magic :: Int size_magic = 4 -- the magic word, first 4 bytes of the index size_dsclen, size_hash, size_size, size_aux, size_fileid :: Int size_size = 8 -- file/directory size (Int64) size_aux = 8 -- aux (Int64) size_fileid = 8 -- fileid (inode or fhandle FileID) size_dsclen = 4 -- this many bytes store the length of the path size_hash = 32 -- hash representation off_size, off_aux, off_hash, off_dsc, off_dsclen, off_fileid :: Int off_size = 0 off_aux = off_size + size_size off_fileid = off_aux + size_aux off_dsclen = off_fileid + size_fileid off_hash = off_dsclen + size_dsclen off_dsc = off_hash + size_hash itemAllocSize :: AnchoredPath -> Int itemAllocSize apath = align 4 $ size_hash + size_size + size_aux + size_fileid + size_dsclen + 2 + B.length (flatten apath) itemSize, itemNext :: Item -> Int itemSize i = size_size + size_aux + size_fileid + size_dsclen + (B.length $ iHashAndDescriptor i) itemNext i = align 4 (itemSize i + 1) iHash, iDescriptor :: Item -> B.ByteString iDescriptor = unsafeDrop size_hash . iHashAndDescriptor iHash = B.take size_hash . iHashAndDescriptor iPath :: Item -> FilePath iPath = decodeLocale . unsafeDrop 1 . iDescriptor iSize, iAux :: Item -> Ptr Int64 iSize i = plusPtr (iBase i) off_size iAux i = plusPtr (iBase i) off_aux iFileID :: Item -> Ptr FileID iFileID i = plusPtr (iBase i) off_fileid itemIsDir :: Item -> Bool itemIsDir i = unsafeHead (iDescriptor i) == c2w 'D' -- xlatePeek32 = fmap xlate32 . peek xlatePeek64 :: (Storable a, Num a, Bits a) => Ptr a -> IO a xlatePeek64 = fmap xlate64 . peek -- xlatePoke32 ptr v = poke ptr (xlate32 v) xlatePoke64 :: (Storable a, Num a, Bits a) => Ptr a -> a -> IO () xlatePoke64 ptr v = poke ptr (xlate64 v) type FileStatus = Maybe F.FileStatus modificationTime :: FileStatus -> EpochTime modificationTime = maybe 0 F.modificationTime fileSize :: FileStatus -> FileOffset fileSize = maybe 0 F.fileSize fileExists :: FileStatus -> Bool fileExists = maybe False (const True) isDirectory :: FileStatus -> Bool isDirectory = maybe False F.isDirectory -- | Lay out the basic index item structure in memory. The memory location is -- given by a ForeignPointer () and an offset. The path and type given are -- written out, and a corresponding Item is given back. The remaining bits of -- the item can be filled out using 'update'. createItem :: ItemType -> AnchoredPath -> ForeignPtr () -> Int -> IO Item createItem typ apath fp off = do let dsc = B.concat [ BC.singleton $ if typ == TreeType then 'D' else 'F' , flatten apath , B.singleton 0 ] (dsc_fp, dsc_start, dsc_len) = toForeignPtr dsc withForeignPtr fp $ \p -> withForeignPtr dsc_fp $ \dsc_p -> do fileid <- fromMaybe 0 <$> getFileID apath pokeByteOff p (off + off_fileid) (xlate64 $ fromIntegral fileid :: Int64) pokeByteOff p (off + off_dsclen) (xlate32 $ fromIntegral dsc_len :: Int32) memcpy (plusPtr p $ off + off_dsc) (plusPtr dsc_p dsc_start) (fromIntegral dsc_len) peekItem fp off -- | Read the on-disk representation into internal data structure. -- -- See the module-level section /Index format/ for details on how the index -- is structured. peekItem :: ForeignPtr () -> Int -> IO Item peekItem fp off = withForeignPtr fp $ \p -> do nl' :: Int32 <- xlate32 `fmap` peekByteOff p (off + off_dsclen) when (nl' <= 2) $ fail "Descriptor too short in peekItem!" let nl = fromIntegral nl' dsc = fromForeignPtr (castForeignPtr fp) (off + off_hash) (size_hash + nl - 1) return $! Item { iBase = plusPtr p off , iHashAndDescriptor = dsc } -- | Update an existing item with new hash and optionally mtime (give Nothing -- when updating directory entries). updateItem :: Item -> Int64 -> Hash -> IO () updateItem item _ NoHash = fail $ "Index.update NoHash: " ++ iPath item updateItem item size hash = do xlatePoke64 (iSize item) size unsafePokeBS (iHash item) (rawHash hash) updateFileID :: Item -> FileID -> IO () updateFileID item fileid = xlatePoke64 (iFileID item) $ fromIntegral fileid updateAux :: Item -> Int64 -> IO () updateAux item aux = xlatePoke64 (iAux item) $ aux updateTime :: forall a.(Enum a) => Item -> a -> IO () updateTime item mtime = updateAux item (fromIntegral $ fromEnum mtime) iHash' :: Item -> Hash iHash' i = SHA256 (iHash i) -- | Gives a ForeignPtr to mmapped index, which can be used for reading and -- updates. The req_size parameter, if non-0, expresses the requested size of -- the index file. mmapIndex will grow the index if it is smaller than this. mmapIndex :: forall a. FilePath -> Int -> IO (ForeignPtr a, Int) mmapIndex indexpath req_size = do act_size <- fromIntegral . fileSize <$> getFileStatus indexpath let size = case req_size > 0 of True -> req_size False | act_size >= size_magic -> act_size - size_magic | otherwise -> 0 case size of 0 -> return (castForeignPtr nullForeignPtr, size) _ -> do (x, _, _) <- mmapFileForeignPtr indexpath ReadWriteEx (Just (0, size + size_magic)) return (x, size) data IndexM m = Index { mmap :: (ForeignPtr ()) , basedir :: FilePath , hashtree :: Tree m -> Hash , predicate :: AnchoredPath -> TreeItem m -> Bool } | EmptyIndex type Index = IndexM IO data State = State { dirlength :: !Int , path :: !AnchoredPath , start :: !Int } data Result = Result { -- | marks if the item has changed since the last update to the index changed :: !Bool -- | next is the position of the next item, in bytes. , next :: !Int -- | treeitem is Nothing in case of the item doesn't exist in the tree -- or is filtered by a FilterTree. Or a TreeItem otherwise. , treeitem :: !(Maybe (TreeItem IO)) -- | resitem is the item extracted. , resitem :: !Item } data ResultF = ResultF { -- | nextF is the position of the next item, in bytes. nextF :: !Int -- | resitemF is the item extracted. , resitemF :: !Item -- | _fileIDs contains the fileids of the files and folders inside, -- in a folder item and its own fileid for file item). , _fileIDs :: [((AnchoredPath, ItemType), FileID)] } readItem :: Index -> State -> IO Result readItem index state = do item <- peekItem (mmap index) (start state) res' <- if itemIsDir item then readDir index state item else readFile index state item return res' readDir :: Index -> State -> Item -> IO Result readDir index state item = do following <- fromIntegral <$> xlatePeek64 (iAux item) st <- getFileStatus (iPath item) let exists = fileExists st && isDirectory st fileid <- fromIntegral <$> (xlatePeek64 $ iFileID item) fileid' <- fromMaybe fileid <$> (getFileID' $ iPath item) when (fileid == 0) $ updateFileID item fileid' let name it dirlen = unsafeMakeName $ (B.drop (dirlen + 1) $ iDescriptor it) -- FIXME MAGIC namelength = (B.length $ iDescriptor item) - (dirlength state) myname = name item (dirlength state) substate = state { start = start state + itemNext item , path = path state `appendPath` myname , dirlength = if myname == unsafeMakeName (BC.singleton '.') then dirlength state else dirlength state + namelength } want = exists && (predicate index) (path substate) (Stub undefined NoHash) oldhash = iHash' item subs off | off < following = do result <- readItem index $ substate { start = off } rest <- subs $ next result return $! (name (resitem result) $ dirlength substate, result) : rest subs coff | coff == following = return [] | otherwise = fail $ "Offset mismatch at " ++ show coff ++ " (ends at " ++ show following ++ ")" inferiors <- if want then subs $ start substate else return [] let we_changed = or [ changed x | (_, x) <- inferiors ] || nullleaf nullleaf = null inferiors && oldhash == nullsha nullsha = SHA256 (B.replicate 32 0) tree' = makeTree [ (n, fromJust $ treeitem s) | (n, s) <- inferiors, isJust $ treeitem s ] treehash = if we_changed then hashtree index tree' else oldhash tree = tree' { treeHash = treehash } when (exists && we_changed) $ updateItem item 0 treehash return $ Result { changed = not exists || we_changed , next = following , treeitem = if want then Just $ SubTree tree else Nothing , resitem = item } readFile :: Index -> State -> Item -> IO Result readFile index state item = do st <- getFileStatus (iPath item) mtime <- fromIntegral <$> (xlatePeek64 $ iAux item) size <- xlatePeek64 $ iSize item fileid <- fromIntegral <$> (xlatePeek64 $ iFileID item) fileid' <- fromMaybe fileid <$> (getFileID' $ iPath item) let mtime' = modificationTime st size' = fromIntegral $ fileSize st readblob = readSegment (basedir index (iPath item), Nothing) exists = fileExists st && not (isDirectory st) we_changed = mtime /= mtime' || size /= size' hash = iHash' item when (exists && we_changed) $ do hash' <- sha256 `fmap` readblob updateItem item size' hash' updateTime item mtime' when (fileid == 0) $ updateFileID item fileid' return $ Result { changed = not exists || we_changed , next = start state + itemNext item , treeitem = if exists then Just $ File $ Blob readblob hash else Nothing , resitem = item } updateIndex :: Index -> IO (Tree IO) updateIndex EmptyIndex = return emptyTree updateIndex index = do let initial = State { start = size_magic , dirlength = 0 , path = AnchoredPath [] } res <- readItem index initial case treeitem res of Just (SubTree tree) -> return $ filter (predicate index) tree _ -> fail "Unexpected failure in updateIndex!" -- | Return a list containing all the file/folder names in an index, with -- their respective ItemType and FileID. listFileIDs :: Index -> IO ([((AnchoredPath, ItemType), FileID)]) listFileIDs EmptyIndex = return [] listFileIDs index = do let initial = State { start = size_magic , dirlength = 0 , path = AnchoredPath [] } res <- readItemFileIDs index initial return $ _fileIDs res readItemFileIDs :: Index -> State -> IO ResultF readItemFileIDs index state = do item <- peekItem (mmap index) (start state) res' <- if itemIsDir item then readDirFileIDs index state item else readFileFileID index state item return res' readDirFileIDs :: Index -> State -> Item -> IO ResultF readDirFileIDs index state item = do fileid <- fromIntegral <$> (xlatePeek64 $ iFileID item) following <- fromIntegral <$> xlatePeek64 (iAux item) let name it dirlen = unsafeMakeName $ (B.drop (dirlen + 1) $ iDescriptor it) -- FIXME MAGIC namelength = (B.length $ iDescriptor item) - (dirlength state) myname = name item (dirlength state) substate = state { start = start state + itemNext item , path = path state `appendPath` myname , dirlength = if myname == unsafeMakeName (BC.singleton '.') then dirlength state else dirlength state + namelength } subs off | off < following = do result <- readItemFileIDs index $ substate { start = off } rest <- subs $ nextF result return $! (name (resitemF result) $ dirlength substate, result) : rest subs coff | coff == following = return [] | otherwise = fail $ "Offset mismatch at " ++ show coff ++ " (ends at " ++ show following ++ ")" inferiors <- subs $ start substate return $ ResultF { nextF = following , resitemF = item , _fileIDs = (((path substate, TreeType), fileid):concatMap (_fileIDs . snd) inferiors) } readFileFileID :: Index -> State -> Item -> IO ResultF readFileFileID _ state item = do fileid' <- fromIntegral <$> (xlatePeek64 $ iFileID item) let name it dirlen = unsafeMakeName $ (B.drop (dirlen + 1) $ iDescriptor it) myname = name item (dirlength state) return $ ResultF { nextF = start state + itemNext item , resitemF = item , _fileIDs = [((path state `appendPath` myname, BlobType), fileid')] } -- | Read an index and build up a 'Tree' object from it, referring to current -- working directory. The initial Index object returned by readIndex is not -- directly useful. However, you can use 'Tree.filter' on it. Either way, to -- obtain the actual Tree object, call update. -- -- The usual use pattern is this: -- -- > do (idx, update) <- readIndex -- > tree <- update =<< filter predicate idx -- -- The resulting tree will be fully expanded. readIndex :: FilePath -> (Tree IO -> Hash) -> IO Index readIndex indexpath ht = do (mmap_ptr, mmap_size) <- mmapIndex indexpath 0 base <- getCurrentDirectory return $ if mmap_size == 0 then EmptyIndex else Index { mmap = mmap_ptr , basedir = base , hashtree = ht , predicate = \_ _ -> True } formatIndex :: ForeignPtr () -> Tree IO -> Tree IO -> IO () formatIndex mmap_ptr old reference = do _ <- create (SubTree reference) (AnchoredPath []) size_magic unsafePokeBS magic (BC.pack "HSI5") where magic = fromForeignPtr (castForeignPtr mmap_ptr) 0 4 create (File _) path' off = do i <- createItem BlobType path' mmap_ptr off let flatpath = anchorPath "" path' case find old path' of Nothing -> return () -- TODO calling getFileStatus here is both slightly -- inefficient and slightly race-prone Just ti -> do st <- getFileStatus flatpath let hash = itemHash ti mtime = modificationTime st size = fileSize st updateItem i (fromIntegral size) hash updateTime i mtime return $ off + itemNext i create (SubTree s) path' off = do i <- createItem TreeType path' mmap_ptr off case find old path' of Nothing -> return () Just ti | itemHash ti == NoHash -> return () | otherwise -> updateItem i 0 $ itemHash ti let subs [] = return $ off + itemNext i subs ((name,x):xs) = do let path'' = path' `appendPath` name noff <- subs xs create x path'' noff lastOff <- subs (listImmediate s) xlatePoke64 (iAux i) (fromIntegral lastOff) return lastOff create (Stub _ _) path' _ = fail $ "Cannot create index from stubbed Tree at " ++ show path' -- | Will add and remove files in index to make it match the 'Tree' object -- given (it is an error for the 'Tree' to contain a file or directory that -- does not exist in a plain form in current working directory). updateIndexFrom :: FilePath -> (Tree IO -> Hash) -> Tree IO -> IO Index updateIndexFrom indexpath hashtree' ref = do old_idx <- updateIndex =<< readIndex indexpath hashtree' reference <- expand ref let len_root = itemAllocSize anchoredRoot len = len_root + sum [ itemAllocSize p | (p, _) <- list reference ] exist <- doesFileExist indexpath -- TODO this conditional logic (rename or delete) is mirrored in -- Darcs.Repository.State.checkIndex and should be refactored #if mingw32_HOST_OS when exist $ renameFile indexpath (indexpath <.> "old") #else when exist $ removeFile indexpath -- to avoid clobbering oldidx #endif (mmap_ptr, _) <- mmapIndex indexpath len formatIndex mmap_ptr old_idx reference readIndex indexpath hashtree' -- | Check that a given file is an index file with a format we can handle. You -- should remove and re-create the index whenever this is not true. indexFormatValid :: FilePath -> IO Bool indexFormatValid path' = do v <- do magic <- mmapFileByteString path' (Just (0, size_magic)) return $ case BC.unpack magic of "HSI5" -> True _ -> False `catch` \(_::SomeException) -> return False return v instance FilterTree IndexM IO where filter _ EmptyIndex = EmptyIndex filter p index = index { predicate = \a b -> predicate index a b && p a b } -- | For a given file or folder path, get the corresponding fileID from the -- filesystem. getFileID :: AnchoredPath -> IO (Maybe FileID) getFileID = getFileID' . anchorPath "" getFileID' :: FilePath -> IO (Maybe FileID) getFileID' fp = do file_exists <- doesFileExist fp dir_exists <- doesDirectoryExist fp if file_exists || dir_exists #ifdef WIN32 then do h <- createFile fp gENERIC_NONE fILE_SHARE_NONE Nothing oPEN_EXISTING fILE_FLAG_BACKUP_SEMANTICS Nothing fhnumber <- (Just . fromIntegral . bhfiFileIndex) <$> getFileInformationByHandle h closeHandle h return fhnumber #else then (Just . F.fileID) <$> F.getSymbolicLinkStatus fp #endif else return Nothing -- Wow, unsafe. unsafePokeBS :: BC.ByteString -> BC.ByteString -> IO () unsafePokeBS to from = do let (fp_to, off_to, len_to) = toForeignPtr to (fp_from, off_from, len_from) = toForeignPtr from when (len_to /= len_from) $ fail $ "Length mismatch in unsafePokeBS: from = " ++ show len_from ++ " /= to = " ++ show len_to withForeignPtr fp_from $ \p_from -> withForeignPtr fp_to $ \p_to -> memcpy (plusPtr p_to off_to) (plusPtr p_from off_from) (fromIntegral len_to) align :: Integral a => a -> a -> a align boundary i = case i `rem` boundary of 0 -> i x -> i + boundary - x {-# INLINE align #-} xlate32 :: (Num a, Bits a) => a -> a xlate64 :: (Num a, Bits a) => a -> a #ifdef LITTLEENDIAN xlate32 = id xlate64 = id #endif #ifdef BIGENDIAN bytemask :: (Num a, Bits a) => a bytemask = 255 xlate32 a = ((a .&. (bytemask `shift` 0)) `shiftL` 24) .|. ((a .&. (bytemask `shift` 8)) `shiftL` 8) .|. ((a .&. (bytemask `shift` 16)) `rotateR` 8) .|. ((a .&. (bytemask `shift` 24)) `rotateR` 24) xlate64 a = ((a .&. (bytemask `shift` 0)) `shiftL` 56) .|. ((a .&. (bytemask `shift` 8)) `shiftL` 40) .|. ((a .&. (bytemask `shift` 16)) `shiftL` 24) .|. ((a .&. (bytemask `shift` 24)) `shiftL` 8) .|. ((a .&. (bytemask `shift` 32)) `rotateR` 8) .|. ((a .&. (bytemask `shift` 40)) `rotateR` 24) .|. ((a .&. (bytemask `shift` 48)) `rotateR` 40) .|. ((a .&. (bytemask `shift` 56)) `rotateR` 56) #endif darcs-2.14.5/src/Darcs/Util/IsoDate.hs0000644000000000000000000010205107346545000015513 0ustar0000000000000000-- Copyright (C) 2003 Peter Simons -- Copyright (C) 2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. -- | -- Module : Darcs.Util.IsoDate -- Copyright : 2003 Peter Simons -- 2003 David Roundy -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.Util.IsoDate ( getIsoDateTime, readUTCDate, readUTCDateOldFashioned , parseDate, getLocalTz , englishDateTime, englishInterval, englishLast , iso8601Interval, iso8601Duration , cleanLocalDate, resetCalendar , MCalendarTime(..), subtractFromMCal, addToMCal , toMCalendarTime, unsafeToCalendarTime , unsetTime, TimeInterval , showIsoDateTime ) where import Prelude ( (^) ) import Darcs.Prelude import Text.ParserCombinators.Parsec import System.Time import System.IO.Unsafe ( unsafePerformIO ) import Data.Char ( toUpper, isDigit ) import Data.Maybe ( fromMaybe ) import Control.Monad ( liftM, liftM2 ) import qualified Data.ByteString.Char8 as BC type TimeInterval = (Maybe CalendarTime, Maybe CalendarTime) -- | Read/interpret a date string, assuming UTC if timezone -- is not specified in the string (see 'readDate') -- Warning! This errors out if we fail to interpret the -- date readUTCDate :: String -> CalendarTime readUTCDate = readDate 0 -- | Convert a date string into ISO 8601 format (yyyymmdd variant) -- assuming local timezone if not specified in the string -- Warning! This errors out if we fail to interpret the date cleanLocalDate :: String -> IO String cleanLocalDate str = do tz <- getLocalTz return . showIsoDateTime . resetCalendar . readDate tz $ str -- | Return the local timezone offset from UTC in seconds getLocalTz :: IO Int getLocalTz = ctTZ `liftM` (getClockTime >>= toCalendarTime) -- | Parse a date string with 'parseDate' -- Warning! This errors out if we fail to interpret the date -- Uses its first argument as the default time zone. readDate :: Int -> String -> CalendarTime readDate tz d = case parseDate tz d of Left e -> error $ "bad date: "++d++" - "++show e Right ct -> resetCalendar $ unsafeToCalendarTime ct -- | Similar to 'readUTCDate', except we /ignore/ timezone info -- in the input string. This is incorrect and ugly. The only reason -- it still exists is so we can generate file names for old-fashioned -- repositories in the same way that old darcs versions expected them. -- You should not use this function except for the above stated purpose. readUTCDateOldFashioned :: String -> CalendarTime readUTCDateOldFashioned d = case parseDate 0 d of Left e -> error $ "bad date: "++d++" - "++show e Right ct -> (unsafeToCalendarTime ct) { ctTZ = 0 } -- | Parse a date string, assuming a default timezone if -- the date string does not specify one. The date formats -- understood are those of 'showIsoDateTime' and 'dateTime' parseDate :: Int -> String -> Either ParseError MCalendarTime parseDate tz d = if length d >= 14 && BC.all isDigit bd then Right $ toMCalendarTime $ CalendarTime (readI $ BC.take 4 bd) (toEnum $ (+ (-1)) $ readI $ BC.take 2 $ BC.drop 4 bd) (readI $ BC.take 2 $ BC.drop 6 bd) -- Day (readI $ BC.take 2 $ BC.drop 8 bd) -- Hour (readI $ BC.take 2 $ BC.drop 10 bd) -- Minute (readI $ BC.take 2 $ BC.drop 12 bd) -- Second 0 Sunday 0 -- Picosecond, weekday and day of year unknown "GMT" 0 False else let dt = do { x <- dateTime tz; eof; return x } in parse dt "" d where bd = BC.pack (take 14 d) readI s = fst $ fromMaybe (error "parseDate: invalid date") (BC.readInt s) -- | Display a 'CalendarTime' in the ISO 8601 format without any -- separators, e.g. 20080825142503 showIsoDateTime :: CalendarTime -> String showIsoDateTime ct = concat [ show $ ctYear ct , twoDigit . show . (+1) . fromEnum $ ctMonth ct , twoDigit . show $ ctDay ct , twoDigit . show $ ctHour ct , twoDigit . show $ ctMin ct , twoDigit . show $ ctSec ct ] where twoDigit [] = undefined twoDigit x@(_:[]) = '0' : x twoDigit x@(_:_:[]) = x twoDigit _ = undefined -- | The current time in the format returned by 'showIsoDateTime' getIsoDateTime :: IO String getIsoDateTime = (showIsoDateTime . toUTCTime) `liftM` getClockTime ----- Parser Combinators --------------------------------------------- -- | Case-insensitive variant of Parsec's 'char' function. caseChar :: Char -> GenParser Char a Char caseChar c = satisfy (\x -> toUpper x == toUpper c) -- | Case-insensitive variant of Parsec's 'string' function. caseString :: String -> GenParser Char a () caseString cs = mapM_ caseChar cs cs -- [x,y] => x <|> y caseStrings :: [String] -> GenParser Char a () caseStrings xs = foldl1 (<|>) $ map caseString xs -- | Match a parser at least @n@ times. manyN :: Int -> GenParser a b c -> GenParser a b [c] manyN n p | n <= 0 = return [] | otherwise = liftM2 (++) (count n p) (many p) -- | Match a parser at least @n@ times, but no more than @m@ times. manyNtoM :: Int -> Int -> GenParser a b c -> GenParser a b [c] manyNtoM n m p | n < 0 = return [] | n > m = return [] | n == m = count n p | n == 0 = foldr ((<|>) . (\x -> try $ count x p)) (return []) (reverse [1..m]) | otherwise = liftM2 (++) (count n p) (manyNtoM 0 (m-n) p) ----- Date/Time Parser ----------------------------------------------- -- | Try each of these date parsers in the following order -- -- (1) 'cvsDateTime' -- -- (2) 'iso8601DateTime' -- -- (3) 'oldDateTime' -- -- (4) 'rfc2822DateTime' dateTime :: Int -> CharParser a MCalendarTime dateTime tz = choice [try $ toMCalendarTime `fmap` cvsDateTime tz, try $ iso8601DateTime tz, try $ toMCalendarTime `fmap` oldDateTime, toMCalendarTime `fmap` rfc2822DateTime] parseDHMS :: CharParser a (Int, Int, Int, Int) parseDHMS = do d <- day _ <- mySpaces (h, m, s) <- parseHMS return (d, h, m, s) parseHMS :: CharParser a (Int, Int, Int) parseHMS = do h <- hour _ <- char ':' m <- minute _ <- char ':' s <- second return (h, m, s) parseSpacesMonthName :: CharParser a Month parseSpacesMonthName = do _ <- mySpaces mon <- monthName _ <- mySpaces return mon -- | CVS-style date/times, e.g. -- 2007/08/25 14:25:39 GMT -- Note that time-zones are optional here. cvsDateTime :: Int -> CharParser a CalendarTime cvsDateTime tz = do y <- year _ <- char '/' mon <- monthNum _ <- char '/' (d, h, m, s) <- parseDHMS z <- option tz $ mySpaces >> zone return (CalendarTime y mon d h m s 0 Monday 0 "" z False) -- | \"Old\"-style dates, e.g. -- Tue Jan 3 14:08:07 EST 1999 -- darcs-doc: Question (what does the "old" stand for really?) oldDateTime :: CharParser a CalendarTime oldDateTime = do wd <- dayName mon <- parseSpacesMonthName (d, h, m , s) <- parseDHMS _ <- mySpaces z <- zone _ <- mySpaces y <- year return (CalendarTime y mon d h m s 0 wd 0 "" z False) rfc2822DateTime :: CharParser a CalendarTime rfc2822DateTime = do wd <- dayName _ <- char ',' _ <- mySpaces d <- day mon <- parseSpacesMonthName y <- year _ <- mySpaces (h, m, s) <- parseHMS _ <- mySpaces z <- zone return (CalendarTime y mon d h m s 0 wd 0 "" z False) -- | ISO 8601 dates and times. Please note the following flaws: -- -- I am reluctant to implement: -- -- * years > 9999 -- -- * truncated representations with implied century (89 for 1989) -- -- I have not implemented: -- -- * repeated durations (not relevant) -- -- * lowest order component fractions in intervals -- -- * negative dates (BC) -- -- I have not verified or have left too relaxed: -- -- * the difference between 24h and 0h -- -- * allows stuff like 2005-1212; either you use the hyphen all the way -- (2005-12-12) or you don't use it at all (20051212), but you don't use -- it halfway, likewise with time -- -- * No bounds checking whatsoever on intervals! -- (next action: read iso doc to see if bounds-checking required?) -} iso8601DateTime :: Int -> CharParser a MCalendarTime iso8601DateTime localTz = try $ do d <- iso8601Date t <- option id $ try $ do optional $ oneOf " T" iso8601Time return $ t $ d { mctTZ = Just localTz } -- | Three types of ISO 8601 date: -- -- * calendar date, e.g., 1997-07-17, 1997-07, 199707, 1997 -- -- * week+day in year, e.g., 1997-W32-4 -- -- * day in year, e.g, 1997-273 iso8601Date :: CharParser a MCalendarTime iso8601Date = do d <- calendar_date <|> week_date <|> ordinal_date return $ foldr ($) nullMCalendar d where calendar_date = -- yyyy-mm-dd try $ do d <- optchain year_ [ (dash, month_), (dash, day_) ] -- allow other variants to be parsed correctly notFollowedBy (digit <|> char 'W') return d week_date = --yyyy-Www-d try $ do yfn <- year_ optional dash _ <- char 'W' -- offset human 'week 1' -> computer 'week 0' w' <- (\x -> x-1) `liftM` twoDigits mwd <- option Nothing $ do { optional dash; Just `fmap` nDigits 1 } let y = resetCalendar . unsafeToCalendarTime . yfn $ nullMCalendar { mctDay = Just 1 } firstDay = ctWDay y -- things that make this complicated -- 1. iso8601 weeks start from Monday; Haskell weeks start from Sunday -- 2. the first week is the one that contains at least Thursday -- if the year starts after Thursday, then some days of the year -- will have already passed before the first week let afterThursday = firstDay == Sunday || firstDay > Thursday w = if afterThursday then w'+1 else w' yday = (7 * w) + fromMaybe 1 mwd diff c = c { mctWeek = True , mctWDay = toEnum `fmap` mwd , mctDay = Just yday } return [diff.yfn] ordinal_date = -- yyyy-ddd try $ optchain year_ [ (dash, yearDay_) ] -- year_ = try $ do y <- fourDigits "year (0000-9999)" return $ \c -> c { mctYear = Just y } month_ = try $ do m <- twoDigits "month (1 to 12)" return $ \c -> c { mctMonth = Just $ intToMonth m } day_ = try $ do d <- twoDigits "day in month (1 to 31)" return $ \c -> c { mctDay = Just d } yearDay_ = try $ do d <- nDigits 3 "day in year (001 to 366)" return $ \c -> c { mctDay = Just d , mctYDay = Just (d - 1) } dash = char '-' -- | Note that this returns a function which sets the time on -- another calendar (see 'iso8601DateTime' for a list of -- flaws iso8601Time :: CharParser a (MCalendarTime -> MCalendarTime) iso8601Time = try $ do ts <- optchain hour_ [ (colon , min_) , (colon , sec_) , (oneOf ",.", pico_) ] z <- option id $ choice [ zulu , offset ] return $ foldr (.) id (z:ts) where hour_ = do h <- twoDigits return $ \c -> c { mctHour = Just h } min_ = do m <- twoDigits return $ \c -> c { mctMin = Just m } sec_ = do s <- twoDigits return $ \c -> c { mctSec = Just s } pico_ = do digs <- many digit let picoExp = 12 digsExp = length digs let frac | null digs = 0 | digsExp > picoExp = read $ take picoExp digs | otherwise = 10 ^ (picoExp - digsExp) * read digs return $ \c -> c { mctPicosec = Just frac } zulu = do { _ <- char 'Z'; return (\c -> c { mctTZ = Just 0 }) } offset = do sign <- choice [ char '+' >> return 1 , char '-' >> return (-1) ] h <- twoDigits m <- option 0 $ do { optional colon; twoDigits } return $ \c -> c { mctTZ = Just $ sign * 60 * ((h*60)+m) } colon = char ':' -- | Intervals in ISO 8601, e.g., -- -- * 2008-09/2012-08-17T16:30 -- -- * 2008-09/P2Y11MT16H30M -- -- * P2Y11MT16H30M/2012-08-17T16:30 -- -- See 'iso8601Duration' iso8601Interval :: Int -> CharParser a (Either TimeDiff (MCalendarTime, MCalendarTime)) iso8601Interval localTz = leftDur <|> rightDur where leftDur = do dur <- iso8601Duration end <- option Nothing $ do { _ <- char '/'; Just `liftM` isoDt } return $ case end of Nothing -> Left dur Just e -> Right (dur `subtractFromMCal` e, e) rightDur = do start <- isoDt _ <- char '/' durOrEnd <- Left `liftM` iso8601Duration <|> Right `liftM` isoDt return $ case durOrEnd of Left dur -> Right (start, dur `addToMCal` start) Right end -> Right (start, end) isoDt = iso8601DateTime localTz -- | Durations in ISO 8601, e.g., -- -- * P4Y (four years) -- -- * P5M (five months) -- -- * P4Y5M (four years and five months) -- -- * P4YT3H6S (four years, three hours and six seconds) iso8601Duration :: CharParser a TimeDiff iso8601Duration = do _ <- char 'P' y <- block 0 'Y' mon <- block 0 'M' d <- block 0 'D' (h,m,s) <- option (0,0,0) $ do _ <- char 'T' h' <- block (-1) 'H' m' <- block (-1) 'M' s' <- block (-1) 'S' let unset = (== (-1)) if all unset [h',m',s'] then fail "T should be omitted if time is unspecified" else let clear x = if unset x then 0 else x in return (clear h', clear m', clear s') -- return $ TimeDiff y mon d h m s 0 where block d c = option d $ try $ do n <- many1 digit _ <- char c return $ read n -- | 'optchain' @p xs@ parses a string with the obligatory -- parser @p@. If this suceeds, it continues on to the -- rest of the input using the next parsers down the -- chain. Each part of the chain consists of a parser -- for a separator and for the content itself. The -- separator is optional. -- -- A good use of this function is to help in parsing ISO -- ISO 8601 dates and times. For example, the parser -- @optchain year [(dash, month), (dash, day)]@ accepts -- dates like 2007 (only the year is used), 2007-07 (only -- the year and month), 200707 (only the year and month -- with no separator), 2007-07-19 (year, month and day). optchain :: CharParser a b -> [(CharParser a c, CharParser a b)] -> CharParser a [b] optchain p next = try $ do r1 <- p r2 <- case next of [] -> return [] ((sep,p2):next2) -> option [] $ do { optional sep; optchain p2 next2 } return (r1:r2) nDigits :: Int -> CharParser a Int nDigits n = read `liftM` count n digit twoDigits, fourDigits :: CharParser a Int twoDigits = nDigits 2 fourDigits = nDigits 4 -- | One or more space. -- WARNING! This only matches on the space character, not on -- whitespace in general mySpaces :: CharParser a String mySpaces = manyN 1 $ char ' ' -- | English three-letter day abbreviations (e.g. Mon, Tue, Wed) dayName :: CharParser a Day dayName = choice [ caseString "Mon" >> return Monday , try (caseString "Tue") >> return Tuesday , caseString "Wed" >> return Wednesday , caseString "Thu" >> return Thursday , caseString "Fri" >> return Friday , try (caseString "Sat") >> return Saturday , caseString "Sun" >> return Sunday ] -- | Four-digit year year :: CharParser a Int year = fourDigits -- | One or two digit month (e.g. 3 for March, 11 for November) monthNum :: CharParser a Month monthNum = do mn <- manyNtoM 1 2 digit return $ intToMonth (read mn :: Int) -- | January is 1, February is 2, etc intToMonth :: Int -> Month intToMonth 1 = January intToMonth 2 = February intToMonth 3 = March intToMonth 4 = April intToMonth 5 = May intToMonth 6 = June intToMonth 7 = July intToMonth 8 = August intToMonth 9 = September intToMonth 10 = October intToMonth 11 = November intToMonth 12 = December intToMonth _ = error "invalid month!" -- | English three-letter month abbreviations (e.g. Jan, Feb, Mar) monthName :: CharParser a Month monthName = choice [ try (caseString "Jan") >> return January , caseString "Feb" >> return February , try (caseString "Mar") >> return March , try (caseString "Apr") >> return April , caseString "May" >> return May , try (caseString "Jun") >> return June , caseString "Jul" >> return July , caseString "Aug" >> return August , caseString "Sep" >> return September , caseString "Oct" >> return October , caseString "Nov" >> return November , caseString "Dec" >> return December ] -- | day in one or two digit notation day :: CharParser a Int day = do d <- manyNtoM 1 2 digit return (read d :: Int) -- | hour in two-digit notation hour :: CharParser a Int hour = twoDigits -- | minute in two-digit notation minute :: CharParser a Int minute = twoDigits -- | second in two-digit notation second :: CharParser a Int second = twoDigits -- | limited timezone support -- -- * +HHMM or -HHMM -- -- * Universal timezones: UTC, UT -- -- * Zones from GNU coreutils/lib/getdate.y, less half-hour ones -- -- sorry Newfies. -- -- * any sequence of alphabetic characters (WARNING! treated as 0!) zone :: CharParser a Int zone = choice [ do { _ <- char '+'; h <- hour; m <- minute; return (((h*60)+m)*60) } , do { _ <- char '-'; h <- hour; m <- minute; return (-((h*60)+m)*60) } , mkZone "UTC" 0 , mkZone "UT" 0 , mkZone "GMT" 0 , mkZone "WET" 0 , mkZone "WEST" 1 , mkZone "BST" 1 , mkZone "ART" (-3) , mkZone "BRT" (-3) , mkZone "BRST" (-2) , mkZone "AST" (-4) , mkZone "ADT" (-3) , mkZone "CLT" (-4) , mkZone "CLST" (-3) , mkZone "EST" (-5) , mkZone "EDT" (-4) , mkZone "CST" (-6) , mkZone "CDT" (-5) , mkZone "MST" (-7) , mkZone "MDT" (-6) , mkZone "PST" (-8) , mkZone "PDT" (-7) , mkZone "AKST" (-9) , mkZone "AKDT" (-8) , mkZone "HST" (-10) , mkZone "HAST" (-10) , mkZone "HADT" (-9) , mkZone "SST" (-12) , mkZone "WAT" 1 , mkZone "CET" 1 , mkZone "CEST" 2 , mkZone "MET" 1 , mkZone "MEZ" 1 , mkZone "MEST" 2 , mkZone "MESZ" 2 , mkZone "EET" 2 , mkZone "EEST" 3 , mkZone "CAT" 2 , mkZone "SAST" 2 , mkZone "EAT" 3 , mkZone "MSK" 3 , mkZone "MSD" 4 , mkZone "SGT" 8 , mkZone "KST" 9 , mkZone "JST" 9 , mkZone "GST" 10 , mkZone "NZST" 12 , mkZone "NZDT" 13 -- if we don't understand it, just give a GMT answer... , do { _ <- manyTill (oneOf $ ' ' : ['a'..'z']++['A'..'Z']) (lookAhead space_digit); return 0 } ] where mkZone n o = try $ do { caseString n; return (o*60*60) } space_digit = try $ do { _ <- char ' '; oneOf ['0'..'9'] } ----- English dates and intervals ----------------------------------------------- -- | In English, either a date followed by a time, or vice-versa, e.g, -- -- * yesterday at noon -- -- * yesterday tea time -- -- * 12:00 yesterday -- -- See 'englishDate' and 'englishTime' -- Uses its first argument as "now", i.e. the time relative to which -- "yesterday", "today" etc are to be interpreted englishDateTime :: CalendarTime -> CharParser a CalendarTime englishDateTime now = try $ dateMaybeAtTime <|> timeThenDate where -- yesterday (at) noon dateMaybeAtTime = try $ do ed <- englishDate now t <- option Nothing $ try $ do { _ <- space; optional $ caseString "at "; Just `liftM` englishTime } return $ fromMaybe id t ed -- tea time 2005-12-04 timeThenDate = try $ do t <- englishTime optional $ char ',' _ <- space ed <- englishDate now return $ t $ unsetTime ed -- | Specific dates in English as specific points of time, e.g, -- -- * today -- -- * yesterday -- -- * last week (i.e. the beginning of that interval) -- -- * 4 months ago (via 'englishAgo') -- -- The first argument is "now". englishDate :: CalendarTime -> CharParser a CalendarTime englishDate now = try $ (caseString "today" >> return (resetCalendar now)) <|> (caseString "yesterday" >> return (oneDay `subtractFromCal` now)) <|> fst `fmap` englishLast now <|> englishAgo now where oneDay = TimeDiff 0 0 1 0 0 0 0 -- | English expressions for points in the past, e.g. -- -- * 4 months ago -- -- * 1 day ago -- -- * day before yesterday -- -- See 'englishDuration' englishAgo :: CalendarTime -> CharParser a CalendarTime englishAgo now = try $ do p <- englishDuration _ <- try space (m,ref) <- try (caseString "ago" >> return (-1, now)) <|> do m <- beforeMod <|> afterMod _ <- space d <- englishDate now <|> fst `fmap` englishLast now <|> unsafeToCalendarTime `fmap` iso8601DateTime (ctTZ now) return (m,d) return $ multiplyDiff m p `addToCal` ref where beforeMod = try $ caseString "before" >> return (-1) afterMod = try $ caseStrings ["after","since"] >> return 1 -- | English expressions for intervals of time, -- -- * before tea time (i.e. from the beginning of time) -- -- * after 14:00 last month (i.e. till now) -- -- * between last year and last month -- -- * in the last three months (i.e. from then till now) -- -- * 4 months ago (i.e. till now; see 'englishAgo') englishInterval :: CalendarTime -> CharParser a TimeInterval englishInterval now = twixt <|> before <|> after <|> inTheLast <|> lastetc where englishDT = unsafeToCalendarTime `fmap` iso8601DateTime (ctTZ now) <|> englishDateTime now before = try $ do caseString "before" _ <- space end <- englishDT return (Just theBeginning, Just end) after = try $ do caseStrings ["after","since"] _ <- space start <- englishDT return (Just start, Nothing) twixt = try $ do caseString "between" _ <- space start <- englishDT _ <- space caseString "and" _ <- space end <- englishDT return (Just start, Just end) inTheLast = try $ do caseString "in the last" _ <- space dur <- englishDuration return (Just $ dur `subtractFromCal` now, Just now) lastetc = do l <- englishAgo now return (Just l, Just now) -- | Durations in English that begin with the word \"last\", -- E.g. \"last 4 months\" is treated as the duration between -- 4 months ago and now englishLast :: CalendarTime -> CharParser a (CalendarTime, CalendarTime) englishLast now = -- last year, last week, last 3 years, etc try $ do caseString "last" _ <- space d <- englishDuration return (d `subtractFromCal` now, now) -- | Either an 'iso8601Time' or one of several common -- English time expressions like 'noon' or 'tea time' englishTime :: CharParser a (CalendarTime->CalendarTime) englishTime = try $ choice [ wrapM `fmap` iso8601Time , namedTime "noon" 12 0 , namedTime "midnight" 0 0 , namedTime "tea time" 16 30 , namedTime "bed time" 2 30 , namedTime "proper bed time" 21 30 ] where namedTime name h m = try $ do caseString name return $ \c -> c { ctHour = h, ctMin = m } wrapM f = unsafeToCalendarTime . f . toMCalendarTime -- | Some English durations, e.g. -- -- * day -- -- * 4 score -- -- * 7 years -- -- * 12 months -- -- This is not particularly strict about what it accepts. -- For example, "7 yeares", "4 scores" or "1 days" are -- just fine. englishDuration :: CharParser a TimeDiff englishDuration = try $ do n <- option 1 $ do x <- many1 digit _ <- space return $ read x b <- base optional (caseStrings ["es","s"]) let current = multiplyDiff n b next <- option noTimeDiff $ try $ do { optional space; _ <- char ',' ; optional space ; englishDuration } return $ addDiff current next where base = choice [ try $ caseString "score" >> return (TimeDiff 20 0 0 0 0 0 0) -- why not? , caseString "year" >> return (TimeDiff 1 0 0 0 0 0 0) , try $ caseString "month" >> return (TimeDiff 0 1 0 0 0 0 0) , caseString "fortnight" >> return (TimeDiff 0 0 14 0 0 0 0) , caseString "week" >> return (TimeDiff 0 0 7 0 0 0 0) , caseString "day" >> return (TimeDiff 0 0 1 0 0 0 0) , caseString "hour" >> return (TimeDiff 0 0 0 1 0 0 0) , caseString "minute" >> return (TimeDiff 0 0 0 0 1 0 0) , caseString "second" >> return (TimeDiff 0 0 0 0 0 1 0) ] ----- Calendar and TimeDiff manipulation --------------------------------------------- -- | The very beginning of time, i.e. 1970-01-01 theBeginning :: CalendarTime theBeginning = unsafePerformIO $ toCalendarTime $ TOD 0 0 -- | An 'MCalenderTime' is an underspecified 'CalendarTime' -- It is used for parsing dates. For example, if you want to parse -- the date '4 January', it may be useful to underspecify the year -- by setting it to 'Nothing'. This uses almost the same fields as -- 'System.Time.CalendarTime', a notable exception being that we -- introduce 'mctWeek' to indicate if a weekday was specified or not data MCalendarTime = MCalendarTime { mctYear :: Maybe Int , mctMonth :: Maybe Month , mctDay :: Maybe Int , mctHour :: Maybe Int , mctMin :: Maybe Int , mctSec :: Maybe Int , mctPicosec :: Maybe Integer , mctWDay :: Maybe Day , mctYDay :: Maybe Int , mctTZName :: Maybe String , mctTZ :: Maybe Int , mctIsDST :: Maybe Bool , mctWeek :: Bool -- is set or not } deriving Show -- | Trivially convert a 'CalendarTime' to a fully specified -- 'MCalendarTime' (note that this sets the 'mctWeek' flag to -- @False@ toMCalendarTime :: CalendarTime -> MCalendarTime toMCalendarTime (CalendarTime a b c d e f g h i j k l) = MCalendarTime (Just a) (Just b) (Just c) (Just d) (Just e) (Just f) (Just g) (Just h) (Just i) (Just j) (Just k) (Just l) False -- | Returns the first 'CalendarTime' that falls within a 'MCalendarTime' -- This is only unsafe in the sense that it plugs in default values -- for fields that have not been set, e.g. @January@ for the month -- or @0@ for the seconds field. -- Maybe we should rename it something happier. -- See also 'resetCalendar' unsafeToCalendarTime :: MCalendarTime -> CalendarTime unsafeToCalendarTime m = CalendarTime { ctYear = fromMaybe 0 $ mctYear m , ctMonth = fromMaybe January $ mctMonth m , ctDay = fromMaybe 1 $ mctDay m , ctHour = fromMaybe 0 $ mctHour m , ctMin = fromMaybe 0 $ mctMin m , ctSec = fromMaybe 0 $ mctSec m , ctPicosec = fromMaybe 0 $ mctPicosec m , ctWDay = fromMaybe Sunday $ mctWDay m , ctYDay = fromMaybe 0 $ mctYDay m , ctTZName = fromMaybe "" $ mctTZName m , ctTZ = fromMaybe 0 $ mctTZ m , ctIsDST = fromMaybe False $ mctIsDST m } addToCal :: TimeDiff -> CalendarTime -> CalendarTime addToCal td = toUTCTime . addToClockTime td . toClockTime subtractFromCal :: TimeDiff -> CalendarTime -> CalendarTime subtractFromCal = addToCal . multiplyDiff (-1) addToMCal :: TimeDiff -> MCalendarTime -> MCalendarTime addToMCal td mc = copyCalendar (addToCal td $ unsafeToCalendarTime mc) mc subtractFromMCal :: TimeDiff -> MCalendarTime -> MCalendarTime subtractFromMCal = addToMCal . multiplyDiff (-1) -- surely there is a more concise way to express these addDiff :: TimeDiff -> TimeDiff -> TimeDiff addDiff (TimeDiff a1 a2 a3 a4 a5 a6 a7) (TimeDiff b1 b2 b3 b4 b5 b6 b7) = TimeDiff (a1+b1) (a2+b2) (a3+b3) (a4+b4) (a5+b5) (a6+b6) (a7 + b7) -- | 'multiplyDiff' @i d@ multiplies every field in @d@ with @i@ -- -- FIXME; this seems like a terrible idea! it seems like -- we should get rid of it if at all possible, maybe adding an -- invertDiff function multiplyDiff :: Int -> TimeDiff -> TimeDiff multiplyDiff m (TimeDiff a1 a2 a3 a4 a5 a6 a7) = TimeDiff (a1*m) (a2*m) (a3*m) (a4*m) (a5*m) (a6*m) (a7 * toInteger m) nullMCalendar :: MCalendarTime nullMCalendar = MCalendarTime Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing False -- | Set a calendar to UTC time any eliminate any inconsistencies within -- (for example, where the weekday is given as @Thursday@, but this does not -- match what the numerical date would lead one to expect) resetCalendar :: CalendarTime -> CalendarTime resetCalendar = toUTCTime . toClockTime -- | 'copyCalendar' @c mc@ replaces any field which is -- specified in @mc@ with the equivalent field in @c@ -- @copyCalendar c nullMCalendar == nullMCalendar@ copyCalendar :: CalendarTime -> MCalendarTime -> MCalendarTime copyCalendar c mc = mc { mctYear = mctYear mc >> Just (ctYear c) , mctMonth = mctMonth mc >> Just (ctMonth c) , mctDay = mctDay mc >> Just (ctDay c) , mctHour = mctHour mc >> Just (ctHour c) , mctMin = mctMin mc >> Just (ctMin c) , mctSec = mctSec mc >> Just (ctSec c) , mctPicosec = mctPicosec mc >> Just (ctPicosec c) , mctWDay = mctWDay mc >> Just (ctWDay c) , mctYDay = mctYDay mc >> Just (ctYDay c) , mctTZName = mctTZName mc >> Just (ctTZName c) , mctTZ = mctTZ mc >> Just (ctTZ c) , mctIsDST = mctIsDST mc >> Just (ctIsDST c) } -- | Zero the time fields of a 'CalendarTime' unsetTime :: CalendarTime -> CalendarTime unsetTime mc = mc { ctHour = 0 , ctMin = 0 , ctSec = 0 , ctPicosec = 0 } darcs-2.14.5/src/Darcs/Util/Lock.hs0000644000000000000000000004015607346545000015062 0ustar0000000000000000-- Copyright (C) 2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Util.Lock ( withLock , withLockCanFail , environmentHelpLocks , withTemp , withOpenTemp , withStdoutTemp , withTempDir , withPermDir , withDelayedDir , withNamedTemp , writeBinFile , writeTextFile , writeDocBinFile , appendBinFile , appendTextFile , appendDocBinFile , readBinFile , readTextFile , readDocBinFile , writeAtomicFilePS , gzWriteAtomicFilePS , gzWriteAtomicFilePSs , gzWriteDocFile , rmRecursive , removeFileMayNotExist , canonFilename , maybeRelink , tempdirLoc , environmentHelpTmpdir , environmentHelpKeepTmpdir , addToErrorLoc , withNewDirectory ) where import Prelude () import Darcs.Prelude import Data.List ( inits ) import Data.Maybe ( fromJust, isJust, listToMaybe ) import System.Exit ( exitWith, ExitCode(..) ) import System.IO ( withFile, withBinaryFile, openBinaryTempFile , hClose, Handle, hPutStr, hSetEncoding , IOMode(WriteMode, AppendMode), hFlush, stdout ) import System.IO.Error ( isAlreadyExistsError , annotateIOError , catchIOError ) import Control.Exception ( IOException , bracket , throwIO , catch , try , SomeException ) import System.Directory ( removeFile , removeDirectory , doesFileExist , doesDirectoryExist , getDirectoryContents , createDirectory , getTemporaryDirectory , removeDirectoryRecursive ) import System.FilePath.Posix ( splitDirectories ) import System.Environment ( lookupEnv ) import Control.Concurrent ( threadDelay ) import Control.Monad ( unless, when, liftM ) import System.Posix.Files ( fileMode, getFileStatus, setFileMode ) import GHC.IO.Encoding ( getFileSystemEncoding ) import Darcs.Util.URL ( isRelative ) import Darcs.Util.Exception ( firstJustIO , catchall ) import Darcs.Util.File ( withCurrentDirectory , doesDirectoryReallyExist, removeFileMayNotExist ) import Darcs.Util.Path ( AbsolutePath, FilePathLike, toFilePath, getCurrentDirectory, setCurrentDirectory ) import Darcs.Util.ByteString ( gzWriteFilePSs ) import qualified Data.ByteString as B (null, readFile, hPut, ByteString) import Darcs.Util.SignalHandler ( withSignalsBlocked ) import Darcs.Util.Printer ( Doc, hPutDoc, packedString, empty, renderPSs ) import Darcs.Util.AtExit ( atexit ) import Darcs.Util.Global ( darcsdir ) import Darcs.Util.Workaround ( renameFile ) import Darcs.Util.Compat ( mkStdoutTemp , canonFilename , maybeRelink , atomicCreate , sloppyAtomicCreate ) import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Prompt ( askUser ) withLock :: String -> IO a -> IO a withLock s job = bracket (getlock s 30) releaseLock (\_ -> job) releaseLock :: String -> IO () releaseLock = removeFileMayNotExist -- | Tries to perform some task if it can obtain the lock, -- Otherwise, just gives up without doing the task withLockCanFail :: String -> IO a -> IO (Either () a) withLockCanFail s job = bracket (takeLock s) (\l -> when l $ releaseLock s) (\l -> if l then liftM Right job else return $ Left ()) getlock :: String -> Int -> IO String getlock l 0 = do yorn <- askUser $ "Couldn't get lock "++l++". Abort (yes or anything else)? " case yorn of ('y':_) -> exitWith $ ExitFailure 1 _ -> getlock l 30 getlock lbad tl = do l <- canonFilename lbad gotit <- takeLock l if gotit then return l else do putStrLn $ "Waiting for lock "++l hFlush stdout -- for Windows threadDelay 2000000 getlock l (tl - 1) takeLock :: FilePathLike p => p -> IO Bool takeLock fp = do atomicCreate $ toFilePath fp return True `catch` \e -> if isAlreadyExistsError e then return False else do pwd <- getCurrentDirectory throwIO $ addToErrorLoc e ("takeLock "++toFilePath fp++" in "++toFilePath pwd) takeFile :: FilePath -> IO Bool takeFile fp = do sloppyAtomicCreate fp return True `catch` \e -> if isAlreadyExistsError e then return False else do pwd <- getCurrentDirectory throwIO $ addToErrorLoc e ("takeFile "++fp++" in "++toFilePath pwd) environmentHelpLocks :: ([String],[String]) environmentHelpLocks = (["DARCS_SLOPPY_LOCKS"],[ "If on some filesystems you get an error of the kind:", "", " darcs: takeLock [...]: atomic_create [...]: unsupported operation", "", "you may want to try to export DARCS_SLOPPY_LOCKS=True."]) -- |'withTemp' safely creates an empty file (not open for writing) and -- returns its name. -- -- The temp file operations are rather similar to the locking operations, in -- that they both should always try to clean up, so exitWith causes trouble. withTemp :: (FilePath -> IO a) -> IO a withTemp = bracket get_empty_file removeFileMayNotExist where get_empty_file = do (f,h) <- openBinaryTempFile "." "darcs" hClose h return f -- |'withOpenTemp' creates a temporary file, and opens it. -- Both of them run their argument and then delete the file. Also, -- both of them (to my knowledge) are not susceptible to race conditions on -- the temporary file (as long as you never delete the temporary file; that -- would reintroduce a race condition). withOpenTemp :: ((Handle, FilePath) -> IO a) -> IO a withOpenTemp = bracket get_empty_file cleanup where cleanup (h,f) = do _ <- try (hClose h) :: IO (Either SomeException ()) removeFileMayNotExist f get_empty_file = invert `fmap` openBinaryTempFile "." "darcs" invert (a,b) = (b,a) withStdoutTemp :: (FilePath -> IO a) -> IO a withStdoutTemp = bracket (mkStdoutTemp "stdout_") removeFileMayNotExist tempdirLoc :: IO FilePath tempdirLoc = liftM fromJust $ firstJustIO [ liftM (Just . head . words) (readFile (darcsdir++"/prefs/tmpdir")) >>= chkdir, lookupEnv "DARCS_TMPDIR" >>= chkdir, getTemporaryDirectory >>= chkdir . Just, getCurrentDirectorySansDarcs, return $ Just "." -- always returns a Just ] where chkdir Nothing = return Nothing chkdir (Just d) = liftM (\e -> if e then Just (d++"/") else Nothing) $ doesDirectoryExist d environmentHelpTmpdir :: ([String], [String]) environmentHelpTmpdir = (["DARCS_TMPDIR", "TMPDIR"], [ "Darcs often creates temporary directories. For example, the `darcs", "diff` command creates two for the working trees to be diffed. By", "default temporary directories are created in /tmp, or if that doesn't", "exist, in _darcs (within the current repo). This can be overridden by", "specifying some other directory in the file _darcs/prefs/tmpdir or the", "environment variable $DARCS_TMPDIR or $TMPDIR."]) getCurrentDirectorySansDarcs :: IO (Maybe FilePath) getCurrentDirectorySansDarcs = do c <- getCurrentDirectory return $ listToMaybe $ drop 5 $ reverse $ takeWhile no_darcs $ inits $ toFilePath c where no_darcs x = darcsdir `notElem` splitDirectories x data WithDirKind = Perm | Temp | Delayed -- | Creates a directory based on the path parameter; -- if a relative path is given the dir is created in the darcs temp dir. -- If an absolute path is given this dir will be created if it doesn't exist. -- If it is specified as a temporary dir, it is deleted after finishing the job. withDir :: WithDirKind -- specifies if and when directory will be deleted -> FilePath -- path parameter -> (AbsolutePath -> IO a) -> IO a withDir _ "" _ = bug "withDir called with empty directory name" withDir kind absoluteOrRelativeName job = do absoluteName <- if isRelative absoluteOrRelativeName then fmap (++ absoluteOrRelativeName) tempdirLoc else return absoluteOrRelativeName formerdir <- getCurrentDirectory bracket (createDir absoluteName 0) (\dir -> do setCurrentDirectory formerdir k <- keepTempDir unless k $ case kind of Perm -> return () Temp -> rmRecursive (toFilePath dir) Delayed -> atexit $ rmRecursive (toFilePath dir)) job where newname name 0 = name newname name n = name ++ "-" ++ show n createDir :: FilePath -> Int -> IO AbsolutePath createDir name n = do createDirectory $ newname name n setCurrentDirectory $ newname name n getCurrentDirectory `catch` (\e -> if isAlreadyExistsError e then createDir name (n+1) else throwIO e) keepTempDir = isJust `fmap` lookupEnv "DARCS_KEEP_TMPDIR" environmentHelpKeepTmpdir :: ([String], [String]) environmentHelpKeepTmpdir = (["DARCS_KEEP_TMPDIR"],[ "If the environment variable DARCS_KEEP_TMPDIR is defined, darcs will", "not remove the temporary directories it creates. This is intended", "primarily for debugging Darcs itself, but it can also be useful, for", "example, to determine why your test preference (see `darcs setpref`)", "is failing when you run `darcs record`, but working when run manually."]) -- |'withPermDir' is like 'withTempDir', except that it doesn't -- delete the directory afterwards. withPermDir :: FilePath -> (AbsolutePath -> IO a) -> IO a withPermDir = withDir Perm -- |'withTempDir' creates a temporary directory, runs the action and then -- removes the directory. The -- location of that directory is determined by the contents of -- _darcs/prefs/tmpdir, if it exists, otherwise by @$DARCS_TMPDIR@, and if -- that doesn't exist then whatever your operating system considers to be a -- a temporary directory (e.g. @$TMPDIR@ under Unix, @$TEMP@ under -- Windows). -- -- If none of those exist it creates the temporary directory -- in the current directory, unless the current directory is under a _darcs -- directory, in which case the temporary directory in the parent of the highest -- _darcs directory to avoid accidentally corrupting darcs's internals. -- This should not fail, but if it does indeed fail, we go ahead and use the -- current directory anyway. If @$DARCS_KEEP_TMPDIR@ variable is set -- temporary directory is not removed, this can be useful for debugging. withTempDir :: FilePath -> (AbsolutePath -> IO a) -> IO a withTempDir = withDir Temp withDelayedDir :: FilePath -> (AbsolutePath -> IO a) -> IO a withDelayedDir = withDir Delayed rmRecursive :: FilePath -> IO () rmRecursive d = do isd <- doesDirectoryReallyExist d if not isd then removeFile d else do conts <- actual_dir_contents withCurrentDirectory d $ mapM_ rmRecursive conts removeDirectory d where actual_dir_contents = -- doesn't include . or .. do c <- getDirectoryContents d return $ filter (/=".") $ filter (/="..") c worldReadableTemp :: FilePath -> IO FilePath worldReadableTemp f = wrt 0 where wrt :: Int -> IO FilePath wrt 100 = fail $ "Failure creating temp named "++f wrt n = let f_new = f++"-"++show n in do ok <- takeFile f_new if ok then return f_new else wrt (n+1) withNamedTemp :: FilePath -> (FilePath -> IO a) -> IO a withNamedTemp n f = do debugMessage $ "withNamedTemp: " ++ show n bracket (worldReadableTemp n) removeFileMayNotExist f readBinFile :: FilePathLike p => p -> IO B.ByteString readBinFile = B.readFile . toFilePath -- NOTE using 'seq' on the last element of the result causes the content to be -- fully evaluated, so the file is read strictly; this is more efficient than -- counting the number of characters; and in the (few) places where we use this -- function we need the lines anyway. readTextFile :: FilePathLike p => p -> IO [String] readTextFile f = do result <- lines <$> readFile (toFilePath f) case result of [] -> return result xs -> last xs `seq` return result readDocBinFile :: FilePathLike p => p -> IO Doc readDocBinFile fp = do ps <- B.readFile $ toFilePath fp return $ if B.null ps then empty else packedString ps appendBinFile :: FilePathLike p => p -> B.ByteString -> IO () appendBinFile f s = appendToFile Binary f $ \h -> B.hPut h s appendTextFile :: FilePathLike p => p -> String -> IO () appendTextFile f s = appendToFile Text f $ \h -> hPutStr h s appendDocBinFile :: FilePathLike p => p -> Doc -> IO () appendDocBinFile f d = appendToFile Binary f $ \h -> hPutDoc h d data FileType = Text | Binary writeBinFile :: FilePathLike p => p -> B.ByteString -> IO () writeBinFile f s = writeToFile Binary f $ \h -> B.hPut h s writeTextFile :: FilePathLike p => p -> String -> IO () writeTextFile f s = writeToFile Text f $ \h -> do getFileSystemEncoding >>= hSetEncoding h hPutStr h s writeDocBinFile :: FilePathLike p => p -> Doc -> IO () writeDocBinFile f d = writeToFile Binary f $ \h -> hPutDoc h d writeAtomicFilePS :: FilePathLike p => p -> B.ByteString -> IO () writeAtomicFilePS f ps = writeToFile Binary f $ \h -> B.hPut h ps gzWriteAtomicFilePS :: FilePathLike p => p -> B.ByteString -> IO () gzWriteAtomicFilePS f ps = gzWriteAtomicFilePSs f [ps] gzWriteAtomicFilePSs :: FilePathLike p => p -> [B.ByteString] -> IO () gzWriteAtomicFilePSs f pss = withSignalsBlocked $ withNamedTemp (toFilePath f) $ \newf -> do gzWriteFilePSs newf pss already_exists <- doesFileExist $ toFilePath f when already_exists $ do mode <- fileMode `fmap` getFileStatus (toFilePath f) setFileMode newf mode `catchall` return () renameFile newf (toFilePath f) gzWriteDocFile :: FilePathLike p => p -> Doc -> IO () gzWriteDocFile f d = gzWriteAtomicFilePSs f $ renderPSs d writeToFile :: FilePathLike p => FileType -> p -> (Handle -> IO ()) -> IO () writeToFile t f job = withSignalsBlocked $ withNamedTemp (toFilePath f) $ \newf -> do (case t of Text -> withFile Binary -> withBinaryFile) newf WriteMode job already_exists <- doesFileExist (toFilePath f) when already_exists $ do mode <- fileMode `fmap` getFileStatus (toFilePath f) setFileMode newf mode `catchall` return () renameFile newf (toFilePath f) appendToFile :: FilePathLike p => FileType -> p -> (Handle -> IO ()) -> IO () appendToFile t f job = withSignalsBlocked $ (case t of Binary -> withBinaryFile Text -> withFile) (toFilePath f) AppendMode job addToErrorLoc :: IOException -> String -> IOException addToErrorLoc ioe s = annotateIOError ioe s Nothing Nothing -- | Do an action in a newly created directory of the given name. If the -- directory is successfully created but the action raises an exception, the -- directory and all its content is deleted. Caught exceptions are re-thrown. withNewDirectory :: FilePath -> IO () -> IO () withNewDirectory name action = do createDirectory name withCurrentDirectory name action `catch` \e -> do removeDirectoryRecursive name `catchIOError` (const $ return ()) throwIO (e :: SomeException) darcs-2.14.5/src/Darcs/Util/Path.hs0000644000000000000000000005736407346545000015077 0ustar0000000000000000-- Copyright (C) 2007 Eric Kow -- Copyright (C) 2010 Petr Rockai -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. {-# LANGUAGE CPP #-} module Darcs.Util.Path ( FileName( ) , fp2fn , fn2fp , fn2ps , ps2fn , breakOnDir , normPath , ownName , superName , movedirfilename , encodeWhite , decodeWhite , encodeWhiteName , decodeWhiteName , isParentOrEqOf -- * AbsolutePath , AbsolutePath , makeAbsolute , ioAbsolute , rootDirectory -- * AbsolutePathOrStd , AbsolutePathOrStd , makeAbsoluteOrStd , ioAbsoluteOrStd , useAbsoluteOrStd , stdOut -- * AbsoluteOrRemotePath , AbsoluteOrRemotePath , ioAbsoluteOrRemote , isRemote -- * SubPath , SubPath , makeSubPathOf , simpleSubPath , isSubPathOf , floatSubPath -- * Miscellaneous , sp2fn , FilePathOrURL(..) , FilePathLike(toFilePath) , getCurrentDirectory , setCurrentDirectory , getUniquePathName , doesPathExist -- * Check for malicious paths , isMaliciousPath , isMaliciousSubPath -- * Tree filtering. , filterFilePaths , filterPaths -- * AnchoredPaths: relative paths within a Tree. All paths are -- anchored at a certain root (this is usually the Tree root). They are -- represented by a list of Names (these are just strict bytestrings). , Name , unsafeMakeName , eqAnycase , AnchoredPath(..) , anchoredRoot , appendPath , anchorPath , isPrefix , parent, parents, catPaths, flatten, makeName, appendToName -- * Unsafe AnchoredPath functions. , floatPath, replacePrefixPath ) where import Prelude () import Darcs.Prelude import Data.List ( isPrefixOf , isSuffixOf , stripPrefix , intersect , inits ) import Data.Char ( isSpace, chr, ord, toLower ) import Control.Exception ( tryJust, bracket_ ) import Control.Monad ( when ) import System.IO.Error ( isDoesNotExistError ) import qualified Darcs.Util.Workaround as Workaround ( getCurrentDirectory ) import qualified System.Directory ( setCurrentDirectory ) import System.Directory ( doesDirectoryExist, doesFileExist ) import qualified System.FilePath.Posix as FilePath ( normalise, isRelative ) import qualified System.FilePath as NativeFilePath ( takeFileName, takeDirectory ) import System.FilePath( (), splitDirectories, normalise, dropTrailingPathSeparator ) import System.Posix.Files ( isDirectory, getSymbolicLinkStatus ) import Darcs.Util.ByteString ( encodeLocale, decodeLocale ) import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString as B import Data.Binary import Darcs.Util.Global ( darcsdir ) import Darcs.Util.URL ( isAbsolute, isRelative, isSshNopath ) -- | FileName is an abstract type intended to facilitate the input and output of -- unicode filenames. newtype FileName = FN FilePath deriving ( Eq, Ord ) instance Show FileName where showsPrec d (FN fp) = showParen (d > appPrec) $ showString "fp2fn " . showsPrec (appPrec + 1) fp where appPrec = 10 instance Binary FileName where put (FN h) = put h get = FN `fmap` get {-# INLINE fp2fn #-} fp2fn :: FilePath -> FileName fp2fn = FN {-# INLINE fn2fp #-} fn2fp :: FileName -> FilePath fn2fp (FN fp) = fp {-# INLINE fn2ps #-} fn2ps :: FileName -> B.ByteString fn2ps (FN fp) = encodeLocale $ encodeWhite fp {-# INLINE ps2fn #-} ps2fn :: B.ByteString -> FileName ps2fn ps = FN $ decodeWhite $ decodeLocale ps {-# INLINE sp2fn #-} sp2fn :: SubPath -> FileName sp2fn = fp2fn . toFilePath -- | 'encodeWhite' translates whitespace in filenames to a darcs-specific -- format (numerical representation according to 'ord' surrounded by -- backslashes). Note that backslashes are also escaped since they are used -- in the encoding. -- -- > encodeWhite "hello there" == "hello\32\there" -- > encodeWhite "hello\there" == "hello\92\there" encodeWhite :: FilePath -> String encodeWhite (c:cs) | isSpace c || c == '\\' = '\\' : show (ord c) ++ "\\" ++ encodeWhite cs encodeWhite (c:cs) = c : encodeWhite cs encodeWhite [] = [] -- | 'decodeWhite' interprets the Darcs-specific \"encoded\" filenames -- produced by 'encodeWhite' -- -- > decodeWhite "hello\32\there" == "hello there" -- > decodeWhite "hello\92\there" == "hello\there" -- > decodeWhite "hello\there" == error "malformed filename" decodeWhite :: String -> FilePath decodeWhite cs_ = go cs_ [] False where go "" acc True = reverse acc -- if there was a replace, use new string go "" _ False = cs_ -- if not, use input string go ('\\':cs) acc _ = case break (=='\\') cs of (theord, '\\':rest) -> go rest (chr (read theord) :acc) True _ -> error "malformed filename" go (c:cs) acc modified = go cs (c:acc) modified encodeWhiteName :: Name -> B.ByteString encodeWhiteName = encodeLocale . encodeWhite . decodeLocale . unName decodeWhiteName :: B.ByteString -> Name decodeWhiteName = Name . encodeLocale . decodeWhite . decodeLocale ownName :: FileName -> FileName ownName (FN f) = case breakLast '/' f of Nothing -> FN f Just (_,f') -> FN f' superName :: FileName -> FileName superName fn = case normPath fn of FN f -> case breakLast '/' f of Nothing -> FN "." Just (d,_) -> FN d breakOnDir :: FileName -> Maybe (FileName,FileName) breakOnDir (FN p) = case breakFirst '/' p of Nothing -> Nothing Just (d,f) | d == "." -> breakOnDir $ FN f | otherwise -> Just (FN d, FN f) -- | convert a path string into a sequence of directories strings -- "/", "." and ".." are generally interpreted as expected. -- Behaviour with too many '..' is to leave them. -- -- Examples: -- Splitting: -- "aa/bb/cc" -> ["aa","bb","cc"] -- Ignoring "." and extra "/": -- "aa/./bb" -> ["aa","bb"] -- "aa//bb" -> ["aa","bb"] -- "/aa/bb/" -> ["aa","bb"] -- Handling "..": -- "aa/../bb/cc" -> ["bb","cc"] -- "aa/bb/../../cc" -> ["cc"] -- "aa/../bb/../cc" -> ["cc"] -- "../cc" -> ["..","cc"] normPath :: FileName -> FileName normPath (FN p) = FN $ norm p norm :: String -> String norm ('.':'/':s) = norm s norm ('/':s) = norm s norm "." = "" norm s = go s [] False where go "" _ False = s -- no modification go "" acc True = reverse acc go ('/':r) acc _ | sep r = go r acc True go ('/':'.':r) acc _ | sep r = go r acc True go ('/':'.':'.':r) acc _ | sep r = go r (doDotDot acc) True go (c:s') acc changed = go s' (c:acc) changed -- remove last path or add "/.." if impossible doDotDot "" = ".." doDotDot acc@('.':'.':r) | sep r = '.':'.':'/':acc doDotDot acc = let a' = dropWhile (/='/') acc in -- eat dir if null a' then "" else tail a' -- check if is a path separator sep ('/':_) = True sep [] = True -- end of string is considered separator sep _ = False breakFirst :: Char -> String -> Maybe (String,String) breakFirst c = bf [] where bf a (r:rs) | r == c = Just (reverse a,rs) | otherwise = bf (r:a) rs bf _ [] = Nothing breakLast :: Char -> String -> Maybe (String,String) breakLast c l = case breakFirst c (reverse l) of Nothing -> Nothing Just (a,b) -> Just (reverse b, reverse a) isParentOrEqOf :: FileName -> FileName -> Bool isParentOrEqOf fn1 fn2 = case stripPrefix (fn2fp fn1) (fn2fp fn2) of Just ('/' : _) -> True Just [] -> True _ -> False movedirfilename :: FileName -> FileName -> FileName -> FileName movedirfilename old new name = if name' == old' then new else case stripPrefix old' name' of Just rest@('/':_) -> fp2fn $ "./" ++ new' ++ rest _ -> name where old' = fn2fp $ normPath old new' = fn2fp $ normPath new name' = fn2fp $ normPath name class FilePathOrURL a where toPath :: a -> String class FilePathOrURL a => FilePathLike a where toFilePath :: a -> FilePath -- | Paths which are relative to the local darcs repository and normalized. -- Note: These are understood not to have the dot in front. newtype SubPath = SubPath FilePath deriving (Eq, Ord) newtype AbsolutePath = AbsolutePath FilePath deriving (Eq, Ord) -- | This is for situations where a string (e.g. a command line argument) -- may take the value \"-\" to mean stdin or stdout (which one depends on -- context) instead of a normal file path. data AbsolutePathOrStd = AP AbsolutePath | APStd deriving (Eq, Ord) data AbsoluteOrRemotePath = AbsP AbsolutePath | RmtP String deriving (Eq, Ord) instance FilePathOrURL AbsolutePath where toPath (AbsolutePath x) = x instance FilePathOrURL SubPath where toPath (SubPath x) = x instance CharLike c => FilePathOrURL [c] where toPath = toFilePath instance FilePathOrURL AbsoluteOrRemotePath where toPath (AbsP a) = toPath a toPath (RmtP r) = r instance FilePathOrURL FileName where toPath = fn2fp instance FilePathLike FileName where toFilePath = fn2fp instance FilePathLike AbsolutePath where toFilePath (AbsolutePath x) = x instance FilePathLike SubPath where toFilePath (SubPath x) = x class CharLike c where toChar :: c -> Char instance CharLike Char where toChar = id instance CharLike c => FilePathLike [c] where toFilePath = map toChar -- | Make the second path relative to the first, if possible makeSubPathOf :: AbsolutePath -> AbsolutePath -> Maybe SubPath makeSubPathOf (AbsolutePath p1) (AbsolutePath p2) = -- The slash prevents "foobar" from being treated as relative to "foo" if p1 == p2 || (p1 ++ "/") `isPrefixOf` p2 then Just $ SubPath $ drop (length p1 + 1) p2 else Nothing simpleSubPath :: FilePath -> Maybe SubPath simpleSubPath x | null x = bug "simpleSubPath called with empty path" | isRelative x = Just $ SubPath $ FilePath.normalise $ pathToPosix x | otherwise = Nothing isSubPathOf :: SubPath -> SubPath -> Bool isSubPathOf (SubPath p1) (SubPath p2) = p1 == "" || p1 == p2 || (p1 ++ "/") `isPrefixOf` p2 -- | Ensure directory exists and is not a symbolic link. doesDirectoryReallyExist :: FilePath -> IO Bool doesDirectoryReallyExist f = do x <- tryJust (\x -> if isDoesNotExistError x then Just () else Nothing) $ isDirectory <$> getSymbolicLinkStatus f return $ case x of Left () -> False Right y -> y doesPathExist :: FilePath -> IO Bool doesPathExist p = do dir_exists <- doesDirectoryExist p file_exists <- doesFileExist p return $ dir_exists || file_exists -- | Interpret a possibly relative path wrt the current working directory. ioAbsolute :: FilePath -> IO AbsolutePath ioAbsolute dir = do isdir <- doesDirectoryReallyExist dir here <- getCurrentDirectory if isdir then bracket_ (setCurrentDirectory dir) (setCurrentDirectory $ toFilePath here) getCurrentDirectory else let super_dir = case NativeFilePath.takeDirectory dir of "" -> "." d -> d file = NativeFilePath.takeFileName dir in do abs_dir <- if dir == super_dir then return $ AbsolutePath dir else ioAbsolute super_dir return $ makeAbsolute abs_dir file -- | Take an absolute path and a string representing a (possibly relative) -- path and combine them into an absolute path. If the second argument is -- already absolute, then the first argument gets ignored. This function also -- takes care that the result is converted to Posix convention and -- normalized. Also, parent directories (\"..\") at the front of the string -- argument get canceled out against trailing directory parts of the -- absolute path argument. -- -- Regarding the last point, someone more familiar with how these functions -- are used should verify that this is indeed necessary or at least useful. makeAbsolute :: AbsolutePath -> FilePath -> AbsolutePath makeAbsolute a dir = if not (null dir) && isAbsolute dir then AbsolutePath (normSlashes dir') else ma a dir' where dir' = FilePath.normalise $ pathToPosix dir -- Why do we care to reduce ".." here? -- Why not do this throughout the whole path, i.e. "x/y/../z" -> "x/z" ? ma here ('.':'.':'/':r) = ma (takeDirectory here) r ma here ".." = takeDirectory here ma here "." = here ma here "" = here ma here r = here /- ('/':r) (/-) :: AbsolutePath -> String -> AbsolutePath x /- ('/':r) = x /- r (AbsolutePath "/") /- r = AbsolutePath ('/':simpleClean r) (AbsolutePath x) /- r = AbsolutePath (x++'/':simpleClean r) -- | Convert to posix, remove trailing slashes, and (under Posix) -- reduce multiple leading slashes to one. simpleClean :: String -> String simpleClean = normSlashes . reverse . dropWhile (=='/') . reverse . pathToPosix -- | The root directory as an absolute path. rootDirectory :: AbsolutePath rootDirectory = AbsolutePath "/" makeAbsoluteOrStd :: AbsolutePath -> String -> AbsolutePathOrStd makeAbsoluteOrStd _ "-" = APStd makeAbsoluteOrStd a p = AP $ makeAbsolute a p stdOut :: AbsolutePathOrStd stdOut = APStd ioAbsoluteOrStd :: String -> IO AbsolutePathOrStd ioAbsoluteOrStd "-" = return APStd ioAbsoluteOrStd p = AP `fmap` ioAbsolute p -- | Execute either the first or the second argument action, depending on -- whether the given path is an 'AbsolutePath' or stdin/stdout. useAbsoluteOrStd :: (AbsolutePath -> a) -> a -> AbsolutePathOrStd -> a useAbsoluteOrStd _ f APStd = f useAbsoluteOrStd f _ (AP x) = f x ioAbsoluteOrRemote :: String -> IO AbsoluteOrRemotePath ioAbsoluteOrRemote p = do isdir <- doesDirectoryExist p if not isdir then return $ RmtP $ case () of _ | isSshNopath p -> p++"." | "/" `isSuffixOf` p -> init p | otherwise -> p else AbsP `fmap` ioAbsolute p isRemote :: AbsoluteOrRemotePath -> Bool isRemote (RmtP _) = True isRemote _ = False takeDirectory :: AbsolutePath -> AbsolutePath takeDirectory (AbsolutePath x) = case reverse $ drop 1 $ dropWhile (/='/') $ reverse x of "" -> AbsolutePath "/" x' -> AbsolutePath x' instance Show AbsolutePath where show = show . toFilePath instance Show SubPath where show = show . toFilePath instance Show AbsolutePathOrStd where show (AP a) = show a show APStd = "standard input/output" instance Show AbsoluteOrRemotePath where show (AbsP a) = show a show (RmtP r) = show r -- | Normalize the path separator to Posix style (slash, not backslash). -- This only affects Windows systems. pathToPosix :: FilePath -> FilePath pathToPosix = map convert where #ifdef WIN32 convert '\\' = '/' #endif convert c = c -- | Reduce multiple leading slashes to one. This only affects Posix systems. normSlashes :: FilePath -> FilePath #ifndef WIN32 -- multiple slashes in front are ignored under Posix normSlashes ('/':p) = '/' : dropWhile (== '/') p #endif normSlashes p = p getCurrentDirectory :: IO AbsolutePath getCurrentDirectory = AbsolutePath `fmap` Workaround.getCurrentDirectory setCurrentDirectory :: FilePathLike p => p -> IO () setCurrentDirectory = System.Directory.setCurrentDirectory . toFilePath {-| What is a malicious path? A spoofed path is a malicious path. 1. Darcs only creates explicitly relative paths (beginning with @\".\/\"@), so any not explicitly relative path is surely spoofed. 2. Darcs normalizes paths so they never contain @\"\/..\/\"@, so paths with @\"\/..\/\"@ are surely spoofed. A path to a darcs repository's meta data can modify \"trusted\" patches or change safety defaults in that repository, so we check for paths containing @\"\/_darcs\/\"@ which is the entry to darcs meta data. To do? * How about get repositories? * Would it be worth adding a --semi-safe-paths option for allowing changes to certain preference files (_darcs\/prefs\/) in sub repositories'? TODO: Properly review the way we handle paths on Windows - it's not enough to just use the OS native concept of path separator. Windows often accepts both path separators, and repositories always use the UNIX separator anyway. -} isMaliciousPath :: String -> Bool isMaliciousPath fp = not (isExplicitlyRelative fp) || isGenerallyMalicious fp -- | Warning : this is less rigorous than isMaliciousPath -- but it's to allow for subpath representations that -- don't start with ./ isMaliciousSubPath :: String -> Bool isMaliciousSubPath fp = not (FilePath.isRelative fp) || isGenerallyMalicious fp isGenerallyMalicious :: String -> Bool isGenerallyMalicious fp = splitDirectories fp `contains_any` [ "..", darcsdir ] where contains_any a b = not . null $ intersect a b isExplicitlyRelative :: String -> Bool isExplicitlyRelative ('.':'/':_) = True -- begins with "./" isExplicitlyRelative _ = False -- | Construct a filter from a list of AnchoredPaths, that will accept any path -- that is either a parent or a child of any of the listed paths, and discard -- everything else. filterPaths :: [AnchoredPath] -> AnchoredPath -> t -> Bool filterPaths files p _ = any (\x -> x `isPrefix` p || p `isPrefix` x) files -- | Same as 'filterPath', but for ordinary 'FilePath's (as opposed to -- AnchoredPath). filterFilePaths :: [FilePath] -> AnchoredPath -> t -> Bool filterFilePaths = filterPaths . map floatPath -- | Iteratively tries find first non-existing path generated by -- buildName, it feeds to buildName the number starting with -1. When -- it generates non-existing path and it isn't first, it displays the -- message created with buildMsg. Usually used for generation of the -- name like _ when already exist -- (e.g. darcs.net_0). getUniquePathName :: Bool -> (FilePath -> String) -> (Int -> FilePath) -> IO FilePath getUniquePathName talkative buildMsg buildName = go (-1) where go :: Int -> IO FilePath go i = do exists <- doesPathExist thename if not exists then do when (i /= -1 && talkative) $ putStrLn $ buildMsg thename return thename else go $ i+1 where thename = buildName i -- | Transform a SubPath into an AnchoredPath. floatSubPath :: SubPath -> AnchoredPath floatSubPath = floatPath . fn2fp . sp2fn ------------------------------- -- AnchoredPath utilities -- newtype Name = Name { unName :: B.ByteString } deriving (Eq, Show, Ord) -- | This is a type of "sane" file paths. These are always canonic in the sense -- that there are no stray slashes, no ".." components and similar. They are -- usually used to refer to a location within a Tree, but a relative filesystem -- path works just as well. These are either constructed from individual name -- components (using "appendPath", "catPaths" and "makeName"), or converted -- from a FilePath ("floatPath" -- but take care when doing that) or . newtype AnchoredPath = AnchoredPath [Name] deriving (Eq, Show, Ord) -- | Check whether a path is a prefix of another path. isPrefix :: AnchoredPath -> AnchoredPath -> Bool (AnchoredPath a) `isPrefix` (AnchoredPath b) = a `isPrefixOf` b -- | Append an element to the end of a path. appendPath :: AnchoredPath -> Name -> AnchoredPath appendPath (AnchoredPath p) n = case n of (Name s) | B.null s -> AnchoredPath p | s == BC.pack "." -> AnchoredPath p | otherwise -> AnchoredPath $ p ++ [n] -- | Catenate two paths together. Not very safe, but sometimes useful -- (e.g. when you are representing paths relative to a different point than a -- Tree root). catPaths :: AnchoredPath -> AnchoredPath -> AnchoredPath catPaths (AnchoredPath p) (AnchoredPath n) = AnchoredPath $ p ++ n -- | Get parent (path) of a given path. foo/bar/baz -> foo/bar parent :: AnchoredPath -> AnchoredPath parent (AnchoredPath x) = AnchoredPath (init x) -- | List all parents of a given path. foo/bar/baz -> [foo, foo/bar] parents :: AnchoredPath -> [AnchoredPath] parents (AnchoredPath x) = map AnchoredPath . init . inits $ x -- | Take a "root" directory and an anchored path and produce a full -- 'FilePath'. Moreover, you can use @anchorPath \"\"@ to get a relative -- 'FilePath'. anchorPath :: FilePath -> AnchoredPath -> FilePath anchorPath dir p = dir decodeLocale (flatten p) {-# INLINE anchorPath #-} flatten :: AnchoredPath -> BC.ByteString flatten (AnchoredPath []) = BC.singleton '.' flatten (AnchoredPath p) = BC.intercalate (BC.singleton '/') [ n | (Name n) <- p ] makeName :: String -> Name makeName ".." = error ".. is not a valid AnchoredPath component name" makeName n | '/' `elem` n = error "/ may not occur in a valid AnchoredPath component name" | otherwise = Name $ encodeLocale n -- | Take a relative FilePath and turn it into an AnchoredPath. The operation -- is (relatively) unsafe. Basically, by using floatPath, you are testifying -- that the argument is a path relative to some common root -- i.e. the root of -- the associated "Tree" object. Also, there are certain invariants about -- AnchoredPath that this function tries hard to preserve, but probably cannot -- guarantee (i.e. this is a best-effort thing). You should sanitize any -- FilePaths before you declare them "good" by converting into AnchoredPath -- (using this function). floatPath :: FilePath -> AnchoredPath floatPath = make . splitDirectories . normalise . dropTrailingPathSeparator where make ["."] = AnchoredPath [] make x = AnchoredPath $ map (Name . encodeLocale) x anchoredRoot :: AnchoredPath anchoredRoot = AnchoredPath [] -- | Take a prefix path, the changed prefix path, and a path to change. -- Assumes the prefix path is a valid prefix. If prefix is wrong return -- AnchoredPath []. replacePrefixPath :: AnchoredPath -> AnchoredPath -> AnchoredPath -> AnchoredPath replacePrefixPath (AnchoredPath []) b c = catPaths b c replacePrefixPath (AnchoredPath (r:p)) b (AnchoredPath (r':p')) | r == r' = replacePrefixPath (AnchoredPath p) b (AnchoredPath p') | otherwise = AnchoredPath [] replacePrefixPath _ _ _ = AnchoredPath [] -- | Append a String to the last Name of an AnchoredPath. appendToName :: AnchoredPath -> String -> AnchoredPath appendToName (AnchoredPath p) s = AnchoredPath (init p++[Name finalname]) where suffix = encodeLocale s finalname | suffix `elem` (BC.tails lastname) = lastname | otherwise = BC.append lastname suffix lastname = case last p of Name name -> name unsafeMakeName :: B.ByteString -> Name unsafeMakeName = Name eqAnycase :: Name -> Name -> Bool eqAnycase (Name a) (Name b) = BC.map toLower a == BC.map toLower b darcs-2.14.5/src/Darcs/Util/Printer.hs0000644000000000000000000004670707346545000015625 0ustar0000000000000000-- | A 'Document' is at heart 'ShowS' from the prelude -- -- Essentially, if you give a Doc a string it'll print out whatever it -- wants followed by that string. So @text "foo"@ makes the Doc that -- prints @"foo"@ followed by its argument. The combinator names are taken -- from 'Text.PrettyPrint.HughesPJ', although the behaviour of the two libraries is -- slightly different. -- -- The advantage of Printer over simple string appending/concatenating is -- that the appends end up associating to the right, e.g.: -- -- > (text "foo" <> text "bar") <> (text "baz" <> text "quux") "" -- > = \s -> (text "foo" <> text "bar") ((text "baz" <> text "quux") s) "" -- > = (text "foo" <> text "bar") ((text "baz" <> text "quux") "") -- > = (\s -> (text "foo") (text "bar" s)) ((text "baz" <> text "quux") "") -- > = text "foo" (text "bar" ((text "baz" <> text "quux") "")) -- > = (\s -> "foo" ++ s) (text "bar" ((text "baz" <> text "quux") "")) -- > = "foo" ++ (text "bar" ((text "baz" <> text "quux") "")) -- > = "foo" ++ ("bar" ++ ((text "baz" <> text "quux") "")) -- > = "foo" ++ ("bar" ++ ((\s -> text "baz" (text "quux" s)) "")) -- > = "foo" ++ ("bar" ++ (text "baz" (text "quux" ""))) -- > = "foo" ++ ("bar" ++ ("baz" ++ (text "quux" ""))) -- > = "foo" ++ ("bar" ++ ("baz" ++ ("quux" ++ ""))) -- -- The Empty alternative comes in because you want -- -- > text "a" $$ vcat xs $$ text "b" -- -- '$$' means above, 'vcat' is the list version of '$$' -- (to be @\"a\\nb\"@ when @xs@ is @[]@), but without the concept of an -- Empty Document each @$$@ would add a @'\n'@ and you'd end up with -- @\"a\\n\\nb\"@. -- Note that @Empty \/= text \"\"@ (the latter would cause two -- @'\\n'@). -- -- This code was made generic in the element type by Juliusz Chroboczek. module Darcs.Util.Printer ( -- * 'Doc' type and structural combinators Doc(Doc,unDoc) , empty, (<>), (), (<+>), ($$), vcat, vsep, hcat, hsep , minus, newline, plus, space, backslash, lparen, rparen , parens -- * Constructing 'Doc's , text , hiddenText , invisibleText , wrapText, quoted , userchunk, packedString , prefix , hiddenPrefix , insertBeforeLastline , prefixLines , invisiblePS, userchunkPS -- * Rendering to 'String' , renderString, renderStringWith -- * Rendering to 'ByteString' , renderPS, renderPSWith , renderPSs, renderPSsWith -- * Printers , Printers , Printers'(..) , Printer , simplePrinters, invisiblePrinter, simplePrinter -- * Printables , Printable(..) , doc , printable, invisiblePrintable, hiddenPrintable, userchunkPrintable -- * Constructing colored 'Doc's , Color(..) , blueText, redText, greenText, magentaText, cyanText , colorText , lineColor -- * IO, uses 'Data.ByteString.hPut' for output , hPutDoc, hPutDocLn, putDoc, putDocLn , hPutDocWith, hPutDocLnWith, putDocWith, putDocLnWith , hPutDocCompr , debugDocLn , ePutDocLn , errorDoc -- * TODO: It is unclear what is unsafe about these constructors , unsafeText, unsafeBoth, unsafeBothText, unsafeChar , unsafePackedString ) where import Prelude () import Darcs.Prelude import Data.String ( IsString(..) ) import System.IO ( Handle, stdout, stderr ) import qualified Data.ByteString as B ( ByteString, hPut, concat ) import qualified Data.ByteString.Char8 as BC ( singleton ) import Darcs.Util.ByteString ( linesPS, decodeLocale, encodeLocale, gzWriteHandle ) import Darcs.Util.Global ( debugMessage ) -- | A 'Printable' is either a String, a packed string, or a chunk of -- text with both representations. data Printable = S !String | PS !B.ByteString | Both !String !B.ByteString -- | 'Printable' representation of a space spaceP :: Printable spaceP = Both " " (BC.singleton ' ') -- | 'Printable' representation of a newline. newlineP :: Printable newlineP = S "\n" -- | A 'Doc' representing a space (\" \") space :: Doc space = unsafeBoth " " (BC.singleton ' ') -- | A 'Doc' representing a newline newline :: Doc newline = unsafeChar '\n' -- | A 'Doc' representing a \"-\" minus :: Doc minus = unsafeBoth "-" (BC.singleton '-') -- | A 'Doc' representing a \"+\" plus :: Doc plus = unsafeBoth "+" (BC.singleton '+') -- | A 'Doc' representing a \"\\\" backslash :: Doc backslash = unsafeBoth "\\" (BC.singleton '\\') -- | A 'Doc' that represents @\"(\"@ lparen :: Doc lparen = unsafeBoth "(" (BC.singleton '(') -- | A 'Doc' that represents @\")\"@ rparen :: Doc rparen = unsafeBoth ")" (BC.singleton ')') -- | prop> parens d = lparen <> d <> rparen parens :: Doc -> Doc parens d = lparen <> d <> rparen -- | Fail with a stack trace and the given 'Doc' as error message. errorDoc :: Doc -> a errorDoc x = error $ renderString x -- | 'putDocWith' puts a 'Doc' on stdout using the given printer. putDocWith :: Printers -> Doc -> IO () putDocWith prs = hPutDocWith prs stdout -- | 'putDocLnWith' puts a 'Doc', followed by a newline on stdout using -- the given printer. putDocLnWith :: Printers -> Doc -> IO () putDocLnWith prs = hPutDocLnWith prs stdout -- | 'putDoc' puts a 'Doc' on stdout using the simple printer 'simplePrinters'. putDoc :: Doc -> IO () putDoc = hPutDoc stdout -- | 'putDocLn' puts a 'Doc', followed by a newline on stdout using -- 'simplePrinters' putDocLn :: Doc -> IO () putDocLn = hPutDocLn stdout -- | 'eputDocLn' puts a 'Doc', followed by a newline to stderr using -- 'simplePrinters'. Like putDocLn, it encodes with the user's locale. -- This function is the recommended way to output messages that should -- be visible to users on the console, but cannot (or should not) be -- silenced even when --quiet is in effect. ePutDocLn :: Doc -> IO () ePutDocLn = hPutDocLn stderr -- | 'hputDocWith' puts a 'Doc' on the given handle using the given printer. hPutDocWith :: Printers -> Handle -> Doc -> IO () hPutDocWith prs h d = hPrintPrintables h (renderWith (prs h) d) -- | 'hputDocLnWith' puts a 'Doc', followed by a newline on the given -- handle using the given printer. hPutDocLnWith :: Printers -> Handle -> Doc -> IO () hPutDocLnWith prs h d = hPutDocWith prs h (d newline) -- |'hputDoc' puts a 'Doc' on the given handle using 'simplePrinters' hPutDoc :: Handle -> Doc -> IO () hPutDoc = hPutDocWith simplePrinters -- | 'hputDocLn' puts a 'Doc', followed by a newline on the given handle using -- 'simplePrinters'. hPutDocLn :: Handle -> Doc -> IO () hPutDocLn = hPutDocLnWith simplePrinters -- | like 'hPutDoc' but with compress data before writing hPutDocCompr :: Handle -> Doc -> IO () hPutDocCompr h = gzWriteHandle h . renderPSs -- | Write a 'Doc' to stderr if debugging is turned on. debugDocLn :: Doc -> IO () debugDocLn = debugMessage . renderString -- | @'hPrintPrintables' h@ prints a list of 'Printable's to the handle @h@ -- It uses binary output of 'ByteString's. If these not available, -- converts according to locale. hPrintPrintables :: Handle -> [Printable] -> IO () hPrintPrintables h = mapM_ (hPrintPrintable h) -- | @'hPrintPrintable' h@ prints a 'Printable' to the handle @h@. hPrintPrintable :: Handle -> Printable -> IO () hPrintPrintable h (S ps) = B.hPut h (encodeLocale ps) hPrintPrintable h (PS ps) = B.hPut h ps hPrintPrintable h (Both _ ps) = B.hPut h ps -- | A 'Doc' is a bit of enriched text. 'Doc's are concatenated using -- '<>' from class 'Monoid', which is right-associative. newtype Doc = Doc { unDoc :: St -> Document } -- | Together with the language extension OverloadedStrings, this allows to -- use string literals where a 'Doc' is expected. instance IsString Doc where fromString = text -- | The State associated with a 'Doc'. Contains a set of printers for each -- hanlde, and the current prefix of the document. data St = St { printers :: !Printers', currentPrefix :: !([Printable] -> [Printable]) } type Printers = Handle -> Printers' -- | A set of printers to print different types of text to a handle. data Printers' = Printers {colorP :: !(Color -> Printer), invisibleP :: !Printer, hiddenP :: !Printer, userchunkP :: !Printer, defP :: !Printer, lineColorT :: !(Color -> Doc -> Doc), lineColorS :: !([Printable] -> [Printable]) } type Printer = Printable -> St -> Document data Color = Blue | Red | Green | Cyan | Magenta -- | 'Document' is a wrapper around '[Printable] -> [Printable]' which allows -- to handle the special case of an empty 'Document' in a non-uniform manner. -- The simplest 'Documents' are built from 'String's using 'text'. data Document = Document ([Printable] -> [Printable]) | Empty -- | renders a 'Doc' into a 'String' with control codes for the -- special features of the 'Doc'. renderString :: Doc -> String renderString = renderStringWith simplePrinters' -- | renders a 'Doc' into a 'String' using a given set of printers. -- If content is only available as 'ByteString', decode according to -- the current locale. renderStringWith :: Printers' -> Doc -> String renderStringWith prs d = concatMap (toString) $ renderWith prs d where toString (S s) = s toString (PS ps) = decodeLocale ps toString (Both s _) = s -- | renders a 'Doc' into 'B.ByteString' with control codes for the -- special features of the Doc. See also 'readerString'. renderPS :: Doc -> B.ByteString renderPS = renderPSWith simplePrinters' -- | renders a 'Doc' into a list of 'PackedStrings', one for each line. renderPSs :: Doc -> [B.ByteString] renderPSs = renderPSsWith simplePrinters' -- | renders a 'Doc' into a 'B.ByteString' using a given set of printers. renderPSWith :: Printers' -> Doc -> B.ByteString renderPSWith prs d = B.concat $ renderPSsWith prs d -- | renders a 'Doc' into a list of 'PackedStrings', one for each -- chunk of text that was added to the 'Doc', using the given set of -- printers. renderPSsWith :: Printers' -> Doc -> [B.ByteString] renderPSsWith prs d = map toPS $ renderWith prs d where toPS (S s) = encodeLocale s toPS (PS ps) = ps toPS (Both _ ps) = ps -- | renders a 'Doc' into a list of 'Printables' using a set of -- printers. Each item of the list corresponds to a string that was -- added to the 'Doc'. renderWith :: Printers' -> Doc -> [Printable] renderWith ps (Doc d) = case d (initState ps) of Empty -> [] Document f -> f [] initState :: Printers' -> St initState prs = St { printers = prs, currentPrefix = id } prefix :: String -> Doc -> Doc prefix s (Doc d) = Doc $ \st -> let p = S s st' = st { currentPrefix = currentPrefix st . (p:) } in case d st' of Document d'' -> Document $ (p:) . d'' Empty -> Empty -- TODO try to find another way to do this, it's rather a violation -- of the Doc abstraction prefixLines :: Doc -> Doc -> Doc prefixLines prefixer prefixee = vcat $ map (prefixer <+>) $ map packedString $ linesPS $ renderPS prefixee -- TODO try to find another way to do this, it's rather a violation -- of the Doc abstraction insertBeforeLastline :: Doc -> Doc -> Doc insertBeforeLastline a b = case reverse $ map packedString $ linesPS $ renderPS a of (ll:ls) -> vcat (reverse ls) $$ b $$ ll [] -> error "empty Doc given as first argument of Printer.insert_before_last_line" lineColor :: Color -> Doc -> Doc lineColor c d = Doc $ \st -> case lineColorT (printers st) c d of Doc d' -> d' st hiddenPrefix :: String -> Doc -> Doc hiddenPrefix s (Doc d) = Doc $ \st -> let pr = printers st p = S (renderStringWith pr $ hiddenText s) st' = st { currentPrefix = currentPrefix st . (p:) } in case d st' of Document d'' -> Document $ (p:) . d'' Empty -> Empty -- | 'unsafeBoth' builds a Doc from a 'String' and a 'B.ByteString' representing -- the same text, but does not check that they do. unsafeBoth :: String -> B.ByteString -> Doc unsafeBoth s ps = Doc $ simplePrinter (Both s ps) -- | 'unsafeBothText' builds a 'Doc' from a 'String'. The string is stored in the -- Doc as both a String and a 'B.ByteString'. unsafeBothText :: String -> Doc unsafeBothText s = Doc $ simplePrinter (Both s (encodeLocale s)) -- | 'packedString' builds a 'Doc' from a 'B.ByteString' using 'printable' packedString :: B.ByteString -> Doc packedString = printable . PS -- | 'unsafePackedString' builds a 'Doc' from a 'B.ByteString' using 'simplePrinter' unsafePackedString :: B.ByteString -> Doc unsafePackedString = Doc . simplePrinter . PS -- | 'invisiblePS' creates a 'Doc' with invisible text from a 'B.ByteString' invisiblePS :: B.ByteString -> Doc invisiblePS = invisiblePrintable . PS -- | 'userchunkPS' creates a 'Doc' representing a user chunk from a 'B.ByteString'. -- -- Rrrright. And what, please is that supposed to mean? userchunkPS :: B.ByteString -> Doc userchunkPS = userchunkPrintable . PS -- | 'unsafeChar' creates a Doc containing just one character. unsafeChar :: Char -> Doc unsafeChar = unsafeText . (:"") -- | 'text' creates a 'Doc' from a @String@, using 'printable'. text :: String -> Doc text = printable . S -- | 'unsafeText' creates a 'Doc' from a 'String', using 'simplePrinter' directly unsafeText :: String -> Doc unsafeText = Doc . simplePrinter . S -- | 'invisibleText' creates a 'Doc' containing invisible text from a @String@ invisibleText :: String -> Doc invisibleText = invisiblePrintable . S -- | 'hiddenText' creates a 'Doc' containing hidden text from a @String@ hiddenText :: String -> Doc hiddenText = hiddenPrintable . S -- | 'userchunk' creates a 'Doc' containing a user chunk from a @String@ userchunk :: String -> Doc userchunk = userchunkPrintable . S blueText, redText, greenText, magentaText, cyanText :: String -> Doc blueText = colorText Blue redText = colorText Red greenText = colorText Green magentaText = colorText Magenta cyanText = colorText Cyan -- | 'colorText' creates a 'Doc' containing colored text from a @String@ colorText :: Color -> String -> Doc colorText c = mkColorPrintable c . S -- | @'wrapText' n s@ is a 'Doc' representing @s@ line-wrapped at 'n' characters wrapText :: Int -> String -> Doc wrapText n s = vcat . map text . reverse $ "" : foldl add_to_line [] (words s) where add_to_line [] a = [a] add_to_line ("":d) a = a:d add_to_line (l:ls) new | length l + length new > n = new:l:ls add_to_line (l:ls) new = (l ++ " " ++ new):ls -- | Creates a 'Doc' from any 'Printable'. printable :: Printable -> Doc printable x = Doc $ \st -> defP (printers st) x st mkColorPrintable :: Color -> Printable -> Doc mkColorPrintable c x = Doc $ \st -> colorP (printers st) c x st -- | Creates an invisible 'Doc' from any 'Printable'. invisiblePrintable :: Printable -> Doc invisiblePrintable x = Doc $ \st -> invisibleP (printers st) x st -- | Creates a hidden 'Doc' from any 'Printable'. hiddenPrintable :: Printable -> Doc hiddenPrintable x = Doc $ \st -> hiddenP (printers st) x st -- | Creates... WTF is a userchunk??? userchunkPrintable :: Printable -> Doc userchunkPrintable x = Doc $ \st -> userchunkP (printers st) x st -- | 'simplePrinters' is a 'Printers' which uses the set 'simplePriners\'' on any -- handle. simplePrinters :: Printers simplePrinters _ = simplePrinters' -- | A set of default printers suitable for any handle. Does not use color. simplePrinters' :: Printers' simplePrinters' = Printers { colorP = const simplePrinter, invisibleP = simplePrinter, hiddenP = invisiblePrinter, userchunkP = simplePrinter, defP = simplePrinter, lineColorT = const id, lineColorS = id } -- | 'simplePrinter' is the simplest 'Printer': it just concatenates together -- the pieces of the 'Doc' simplePrinter :: Printer simplePrinter x = unDoc $ doc (\s -> x:s) -- | 'invisiblePrinter' is the 'Printer' for hidden text. It just replaces -- the document with 'empty'. It's useful to have a printer that doesn't -- actually do anything because this allows you to have tunable policies, -- for example, only printing some text if it's to the terminal, but not -- if it's to a file or vice-versa. invisiblePrinter :: Printer invisiblePrinter _ = unDoc empty infixr 6 `append` infixr 6 <+> infixr 5 `vplus` infixr 5 $$ -- | The empty 'Doc' empty :: Doc empty = Doc $ const Empty doc :: ([Printable] -> [Printable]) -> Doc doc f = Doc $ const $ Document f instance Semigroup Doc where (<>) = append -- | 'mappend' ('<>') is concatenation, 'mempty' is the 'empty' 'Doc' instance Monoid Doc where mempty = empty mappend = append -- | Concatenation of two 'Doc's append :: Doc -> Doc -> Doc Doc a `append` Doc b = Doc $ \st -> case a st of Empty -> b st Document af -> Document (\s -> af $ case b st of Empty -> s Document bf -> bf s) -- | @a '' b@ is @a '<>' b@ if @a@ is not empty, else empty () :: Doc -> Doc -> Doc Doc a Doc b = Doc $ \st -> case a st of Empty -> Empty Document af -> Document (\s -> af $ case b st of Empty -> s Document bf -> bf s) -- | @a '<+>' b@ is @a@ followed by @b@ with a space in between if both are non-empty (<+>) :: Doc -> Doc -> Doc Doc a <+> Doc b = Doc $ \st -> case a st of Empty -> b st Document af -> Document (\s -> af $ case b st of Empty -> s Document bf -> spaceP:bf s) -- | @a '$$' b@ is @a@ above @b@ ($$) :: Doc -> Doc -> Doc Doc a $$ Doc b = Doc $ \st -> case a st of Empty -> b st Document af -> Document (\s -> af $ case b st of Empty -> s Document bf -> sf (newlineP:pf (bf s))) where pf = currentPrefix st sf = lineColorS $ printers st -- | @vplus a b@ is @a@ above @b@ with an empty line in between if both are non-empty vplus :: Doc -> Doc -> Doc Doc a `vplus` Doc b = Doc $ \st -> case a st of Empty -> b st Document af -> Document (\s -> af $ case b st of Empty -> s Document bf -> sf (newlineP:newlineP:pf (bf s))) where pf = currentPrefix st sf = lineColorS $ printers st -- | Pile 'Doc's vertically vcat :: [Doc] -> Doc vcat = foldr ($$) empty -- | Pile 'Doc's vertically, with a blank line in between vsep :: [Doc] -> Doc vsep = foldr vplus empty -- | Concatenate 'Doc's horizontally hcat :: [Doc] -> Doc hcat = mconcat -- | Concatenate 'Doc's horizontally with a space as separator hsep :: [Doc] -> Doc hsep = foldr (<+>) empty -- | Quote a string for screen output quoted :: String -> Doc quoted s = text "\"" <> text (escape s) <> text "\"" where escape "" = "" escape (c:cs) = if c `elem` ['\\', '"'] then '\\' : c : escape cs else c : escape cs darcs-2.14.5/src/Darcs/Util/Printer/0000755000000000000000000000000007346545000015253 5ustar0000000000000000darcs-2.14.5/src/Darcs/Util/Printer/Color.hs0000644000000000000000000003700107346545000016666 0ustar0000000000000000{-# LANGUAGE CPP #-} module Darcs.Util.Printer.Color ( showDoc, errorDoc, traceDoc, assertDoc, fancyPrinters , environmentHelpColor, environmentHelpEscape, environmentHelpEscapeWhite ) where import Prelude () import Darcs.Prelude import Darcs.Util.Printer ( Printer, Printers, Printers'(..), Printable(..), Color(..) , invisiblePrinter, (), Doc(Doc,unDoc), unsafeBothText, simplePrinter, hcat , unsafeText, unsafePackedString , renderStringWith, prefix ) import Debug.Trace ( trace ) import Data.Char ( isAscii, isPrint, isSpace, isControl, ord, chr ) import Data.Bits ( bit, xor ) import System.Environment ( lookupEnv ) import qualified Data.ByteString.Char8 as BC (unpack, any, last, spanEnd) import qualified Data.ByteString as B (null, init) import System.IO.Unsafe ( unsafePerformIO ) import System.IO ( stderr, hIsTerminalDevice, Handle ) import Text.Printf ( printf ) #ifdef HAVE_TERMINFO import System.Console.Terminfo( tiGetNum, setupTermFromEnv, getCapability ) import Data.Maybe ( fromMaybe ) #endif dollar, cr :: Doc dollar = unsafeBothText "$" cr = unsafeBothText "\r" errorDoc :: Doc -> a errorDoc = error . showDoc traceDoc :: Doc -> a -> a traceDoc d = trace (showDoc d) assertDoc :: Maybe Doc -> a -> a assertDoc Nothing x = x assertDoc (Just e) _ = errorDoc e showDoc :: Doc -> String showDoc = renderStringWith (fancyPrinters stderr) -- | The 'Policy' type is a record containing the variables which control -- how 'Doc's will be rendered on some output. data Policy = Policy { poColor :: Bool -- ^ overall use of color , poEscape :: Bool -- ^ overall use of escaping , poLineColor :: Bool -- ^ overall use of colored lines (only hunks for now) , poAltColor :: Bool -- ^ alternative to color (bold, inverse) , poIsprint :: Bool -- ^ don't escape isprints , po8bit :: Bool -- ^ don't escape 8-bit chars , poNoEscX :: String -- ^ extra chars to never escape , poEscX :: String -- ^ extra chars to always escape , poTrailing :: Bool -- ^ escape trailing spaces , poCR :: Bool -- ^ ignore \r at end of lines , poSpace :: Bool -- ^ escape spaces (used with poTrailing) } {-# NOINLINE getPolicy #-} -- | 'getPolicy' returns a suitable policy for a given handle. -- The policy is chosen according to environment variables, and to the -- type of terminal which the handle represents getPolicy :: Handle -> Policy getPolicy handle = unsafePerformIO $ do isTerminal <- hIsTerminalDevice handle nColors <- if isTerminal then getTermNColors else return 0 envDontEscapeAnything <- getEnvBool "DARCS_DONT_ESCAPE_ANYTHING" envDontEscapeIsprint <- getEnvBool "DARCS_DONT_ESCAPE_ISPRINT" envUseIsprint <- getEnvBool "DARCS_USE_ISPRINT" envEscape8bit <- getEnvBool "DARCS_ESCAPE_8BIT" envDontEscapeExtra <- getEnvString "DARCS_DONT_ESCAPE_EXTRA" envEscapeExtra <- getEnvString "DARCS_ESCAPE_EXTRA" envDontEscapeTrailingSpace <- getEnvBool "DARCS_DONT_ESCAPE_TRAILING_SPACES" envDontEscapeTrailingCR <- getEnvBool "DARCS_DONT_ESCAPE_TRAILING_CR" envDontColor <- getEnvBool "DARCS_DONT_COLOR" envAlwaysColor <- getEnvBool "DARCS_ALWAYS_COLOR" envAlternativeColor <- getEnvBool "DARCS_ALTERNATIVE_COLOR" envDoColorLines <- getEnvBool "DARCS_DO_COLOR_LINES" let haveColor = envAlwaysColor || (isTerminal && (nColors > 4)) doColor = not envDontColor && haveColor return Policy { poColor = doColor, poEscape = not envDontEscapeAnything, poLineColor= doColor && envDoColorLines, poIsprint = envDontEscapeIsprint || envUseIsprint, po8bit = not envEscape8bit, poNoEscX = envDontEscapeExtra, poEscX = envEscapeExtra, poTrailing = not envDontEscapeTrailingSpace, poCR = envDontEscapeTrailingCR, poAltColor = haveColor && envAlternativeColor, poSpace = False } where getEnvBool s = maybe False (/= "0") <$> lookupEnv s getEnvString s = maybe "" id <$> lookupEnv s {- - This function returns number of colors supported by current terminal - or -1 if color output not supported or error occured. - Terminal type determined by TERM env. variable. -} getTermNColors :: IO Int #ifdef HAVE_TERMINFO getTermNColors = do t <- setupTermFromEnv return . fromMaybe (-1) . getCapability t . tiGetNum $ "colors" #else getTermNColors = return (-1) #endif -- printers -- | @'fancyPrinters' h@ returns a set of printers suitable for outputting -- to @h@ fancyPrinters :: Printers fancyPrinters h = let policy = getPolicy h in Printers { colorP = colorPrinter policy, invisibleP = invisiblePrinter, hiddenP = colorPrinter policy Green, userchunkP = userchunkPrinter policy, defP = escapePrinter policy, lineColorT = lineColorTrans policy, lineColorS = lineColorSuffix policy } -- | @'lineColorTrans' policy@ tries to color a Doc, according to policy po. -- That is, if @policy@ has @poLineColor@ set, then colors the line, otherwise -- does nothing. lineColorTrans :: Policy -> Color -> Doc -> Doc lineColorTrans po | poLineColor po = \c d -> prefix (setColor c) d unsafeBothText resetColor | otherwise = const id lineColorSuffix :: Policy -> [Printable] -> [Printable] lineColorSuffix po | poLineColor po = \d -> S resetColor : d | otherwise = id colorPrinter :: Policy -> Color -> Printer colorPrinter po | poColor po = \c -> unDoc . color po c . Doc . escapePrinter po{poColor=False} | otherwise = const $ escapePrinter po userchunkPrinter :: Policy -> Printer userchunkPrinter po p | not (poEscape po) = simplePrinter p | not (poTrailing po) = escapePrinter po p | otherwise = unDoc $ pr p where pr (S s) = prString s pr (Both _ ps) = prPS ps pr (PS ps) = prPS ps prPS ps = let (leadPS, trailPS) = BC.spanEnd isSpace ps in if B.null trailPS then Doc $ escapePrinter po p else Doc (escapePrinter po (PS leadPS)) <> Doc (escapePrinter po{poSpace=True} (PS trailPS)) <> markEscape po dollar prString s = let (trail',lead') = span isSpace (reverse s) lead = reverse lead' trail = reverse trail' in if (not.null) trail then Doc (escapePrinter po (S lead)) <> Doc (escapePrinter po{poSpace=True} (S trail)) <> markEscape po dollar else Doc (escapePrinter po p) escapePrinter :: Policy -> Printer escapePrinter po | (not.poEscape) po = simplePrinter | otherwise = unDoc . crepr where crepr p | poCR po && isEndCR p = epr (initPR p) <> cr | otherwise = epr p epr (S s) = escape po s epr (PS ps) = if BC.any (not.noEscape po) ps then escape po (BC.unpack ps) else unsafePackedString ps epr (Both s _) = escape po s isEndCR (S s) = not (null s) && last s == '\r' isEndCR (PS ps) = not (B.null ps) && BC.last ps == '\r' isEndCR (Both _ ps) = not (B.null ps) && BC.last ps == '\r' initPR (S s) = S $ init s initPR (PS ps) = PS $ B.init ps initPR (Both s ps) = Both (init s) (B.init ps) -- | @'escape' policy string@ escapes @string@ according to the rules -- defined in 'policy', turning it into a 'Doc'. escape :: Policy -> String -> Doc escape _ "" = unsafeText "" escape po s = hcat $ escape' s where escape' "" = [] escape' s'@(c:_) | mundane c = let (printables, rest) = span mundane s' in unsafeText printables:escape' rest escape' (c:rest) = (emph . unsafeText $ quoteChar c):escape' rest mundane c = noEscape po c || c == ' ' emph = markEscape po -- | @'noEscape' policy c@ tells wether @c@ will be left as-is -- when escaping according to @policy@ noEscape :: Policy -> Char -> Bool noEscape po c | poSpace po && isSpace c = False noEscape po c | c `elem` poEscX po = False noEscape po c | c `elem` poNoEscX po = True noEscape _ '\t' = True -- tabs will likely be converted to spaces noEscape _ '\n' = True noEscape po c = if poIsprint po then isPrint c else isPrintableAscii c || c >= '\x80' && po8bit po -- | 'isPrintableAscii' tells wether a character is a printable character -- of the ascii range. isPrintableAscii :: Char -> Bool isPrintableAscii c = isAscii c && isPrint c -- | 'quoteChar' represents a special character as a string. -- * @quoteChar '^c'@ (where @^c@ is a control character) is @"^c"@ -- * Otherwise, @quoteChar@ returns "\hex", where 'hex' is the -- hexadecimal number of the character. quoteChar :: Char -> String quoteChar c | isControl c && isPrintableAscii cHat = ['^', cHat] | otherwise = sHex where cHat = chr $ (bit 6 `xor`) $ ord c sHex = "" -- make colors and highlightings -- | @'markEscape' policy doc@ marks @doc@ with the appropriate -- marking for escaped characters according to @policy@ markEscape :: Policy -> Doc -> Doc markEscape po | poAltColor po = makeInvert | poColor po = makeColor Red | otherwise = makeAsciiart -- | @'color' policy color doc@ colors @doc@ with color @color@ if -- @policy@ is not set to use an alternative to color. In that case, -- it makes the text bold instead. color :: Policy -> Color -> Doc -> Doc color po | poAltColor po = \_ -> makeBold | otherwise = makeColor makeColor, makeColor' :: Color -> Doc -> Doc makeColor' = withColor . setColor -- memoized version of makeColor' makeColor Blue = makeColor' Blue makeColor Red = makeColor' Red makeColor Green = makeColor' Green makeColor Cyan = makeColor' Cyan makeColor Magenta = makeColor' Magenta setColor :: Color -> String setColor Blue = "\x1B[01;34m" -- bold blue setColor Red = "\x1B[01;31m" -- bold red setColor Green = "\x1B[01;32m" -- bold green setColor Cyan = "\x1B[36m" -- light cyan setColor Magenta = "\x1B[35m" -- light magenta -- | @'makeAsciiart' doc@ tries to make @doc@ (usually a -- single escaped char) stand out with the help of only plain -- ascii, i.e., no color or font style. makeAsciiart :: Doc -> Doc makeAsciiart x = unsafeBothText "[_" <> x <> unsafeBothText "_]" -- | the string to reset the terminal's color. resetColor :: String resetColor = "\x1B[00m" -- | @'withColor' color doc@ returns a colorized version of @doc@. -- @color@ is a string that represents a color, given by 'setColor' withColor :: String -> Doc -> Doc withColor c = let c' = unsafeBothText c r' = unsafeBothText resetColor in \x -> c' <> x <> r' -- | 'makeBold' boldens a doc. makeBold :: Doc -> Doc -- | 'makeInvert' returns an invert video version of a doc. makeInvert :: Doc -> Doc makeBold = withColor "\x1B[01m" makeInvert = withColor "\x1B[07m" environmentHelpColor :: ([String], [String]) environmentHelpColor = (["DARCS_DONT_COLOR", "DARCS_ALWAYS_COLOR", "DARCS_ALTERNATIVE_COLOR", "DARCS_DO_COLOR_LINES"],[ "If the terminal understands ANSI color escape sequences, darcs will", "highlight certain keywords and delimiters when printing patches. This", "can be turned off by setting the environment variable DARCS_DONT_COLOR", "to 1. If you use a pager that happens to understand ANSI colors, like", "`less -R`, darcs can be forced always to highlight the output by setting", "DARCS_ALWAYS_COLOR to 1. If you can't see colors you can set", "DARCS_ALTERNATIVE_COLOR to 1, and darcs will use ANSI codes for bold", "and reverse video instead of colors. In addition, there is an", "extra-colorful mode, which is not enabled by default, which can be", "activated with DARCS_DO_COLOR_LINES"]) environmentHelpEscapeWhite :: ([String], [String]) environmentHelpEscapeWhite = ([ "DARCS_DONT_ESCAPE_TRAILING_SPACES", "DARCS_DONT_ESCAPE_TRAILING_CR"],[ "By default darcs will escape (by highlighting if possible) any kind", "of spaces at the end of lines when showing patch contents.", "If you don't want this you can turn it off by setting", "DARCS_DONT_ESCAPE_TRAILING_SPACES to 1. A special case exists", "for only carriage returns: DARCS_DONT_ESCAPE_TRAILING_CR"]) environmentHelpEscape :: ([String], [String]) environmentHelpEscape = (["DARCS_DONT_ESCAPE_ANYTHING", "DARCS_DONT_ESCAPE_EXTRA", "DARCS_ESCAPE_EXTRA", "DARCS_DONT_ESCAPE_ISPRINT", "DARCS_ESCAPE_8BIT"],[ "Darcs needs to escape certain characters when printing patch contents to", "a terminal, depending on the encoding specified in your locale setting.", "", "By default, darcs assumes that your locale encoding is ASCII compatible.", "This includes UTF-8 and some 8-bit encodings like ISO/IEC-8859 (including", "its variants). Since ASCII contains control characters like backspace", "(which could hide patch content from the user when printed literally to", "the terminal), and even ones that may introduce security risks such as", "redirecting commands to the shell, darcs needs to escape such characters.", "They are printed as `^` or `\\`. Darcs also uses", "special markup for line endings that are preceeded by white space, since", "the white space would otherwise not be recognizable.", "", "If you use an encoding that is not ASCII compatible, things are somewhat", "less smooth. Such encodings include UTF-16 and UTF-32, as well as many of", "the encodings that became obsolete with unicode. In this case you have two", "options: you can set DARCS_DONT_ESCAPE_ANYTHING to 1. Then everything that", "doesn't flip code sets should work, and so will all the bells and whistles", "in your terminal. This environment variable can also be handy if you pipe", "the output to a pager or external filter that knows better than darcs how to", "handle your encoding. Note that all escaping, including the special escaping", "of any line ending spaces, will be turned off by this setting.", "", "Another possibility is to explicitly tell darcs to not escape or escape", "certain bytes, using DARCS_DONT_ESCAPE_EXTRA and DARCS_ESCAPE_EXTRA. Their", "values should be strings consisting of the verbatim bytes in question. The", "do-escapes take precedence over the dont-escapes. Space characters are still", "escaped at line endings though. The special environment variable", "DARCS_DONT_ESCAPE_TRAILING_CR turns off escaping of carriage return last on", "the line (DOS style).", "", "For historical reasons, darcs also supports DARCS_DONT_ESCAPE_ISPRINT and", "DARCS_USE_ISPRINT (which are synonyms). These make sense only for 8-bit", "encodings like ISO-8859 and are no longer needed since nowadays darcs does", "the right thing here by default.", "", "Finally, if you are in a highly security sensitive situation (or just", "paranoid for other reasons), you can set DARCS_ESCAPE_8BIT to 1. This will", "cause darcs to escape every non-ASCII byte in addition to ASCII control", "characters."]) darcs-2.14.5/src/Darcs/Util/Progress.hs0000644000000000000000000002042007346545000015766 0ustar0000000000000000-- | -- Module : Darcs.Util.Progress -- Copyright : 2008 David Roundy -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable -- -- Utility functions for tracking progress of long-running actions. module Darcs.Util.Progress ( beginTedious , endTedious , tediousSize , debugMessage , debugFail , withoutProgress , progress , progressKeepLatest , finishedOne , finishedOneIO , progressList , minlist , setProgressMode ) where import Prelude () import Darcs.Prelude import Prelude hiding (lookup) import Control.Arrow ( second ) import Control.Exception ( bracket ) import Control.Monad ( when, unless, void ) import Control.Concurrent ( forkIO, threadDelay ) import Data.Char ( toLower ) import Data.Map ( Map, empty, adjust, insert, delete, lookup ) import Data.Maybe ( isJust ) import Data.IORef ( IORef, newIORef, readIORef, writeIORef, modifyIORef ) import System.IO ( stdout, stderr, hFlush, hPutStr, hPutStrLn, hSetBuffering, hIsTerminalDevice, Handle, BufferMode(LineBuffering) ) import System.IO.Unsafe ( unsafePerformIO ) import Darcs.Util.Global ( withDebugMode, debugMessage, putTiming, debugFail ) data ProgressData = ProgressData { sofar :: !Int , latest :: !(Maybe String) , total :: !(Maybe Int) } handleProgress :: IO () handleProgress = do threadDelay 1000000 handleMoreProgress "" 0 handleMoreProgress :: String -> Int -> IO () handleMoreProgress k n = withProgressMode $ \m -> if m then do s <- getProgressLast mp <- getProgressData s case mp of Nothing -> do threadDelay 1000000 handleMoreProgress k n Just p -> do when (k /= s || n < sofar p) $ whenProgressMode $ printProgress s p threadDelay 1000000 handleMoreProgress s (sofar p) else do threadDelay 1000000 handleMoreProgress k n printProgress :: String -> ProgressData -> IO () printProgress k (ProgressData {sofar=s, total=Just t, latest=Just l}) = myput output output where output = k ++ " " ++ show s ++ " done, " ++ show (t - s) ++ " queued. " ++ l printProgress k (ProgressData {latest=Just l}) = myput (k ++ " " ++ l) k printProgress k (ProgressData {sofar=s, total=Just t}) | t >= s = myput (k ++ " " ++ show s ++ " done, " ++ show (t - s) ++ " queued") (k ++ " " ++ show s) printProgress k (ProgressData {sofar=s}) = myput (k ++ " " ++ show s) k myput :: String -> String -> IO () myput l s = withDebugMode $ \debugMode -> if debugMode then putTiming >> hPutStrLn stderr l else if '\n' `elem` l then myput (takeWhile (/= '\n') l) s else putTiming >> if length l < 80 then simpleput l else simpleput (take 80 s) simpleput :: String -> IO () simpleput = unsafePerformIO $ mkhPutCr stderr {-# NOINLINE simpleput #-} -- | @beginTedious k@ starts a tedious process and registers it in -- '_progressData' with the key @k@. A tedious process is one for which we want -- a progress indicator. -- -- Wouldn't it be safer if it had type String -> IO ProgressDataKey, so that we -- can ensure there is no collision? What happens if you call beginTedious twice -- with the same string, without calling endTedious in the meantime? beginTedious :: String -> IO () beginTedious k = do debugMessage $ "Beginning " ++ map toLower k setProgressData k ProgressData { sofar = 0 , latest = Nothing , total = Nothing } -- | @endTedious k@ unregisters the tedious process with key @k@, printing -- "Done" if such a tedious process exists. endTedious :: String -> IO () endTedious k = whenProgressMode $ do p <- getProgressData k modifyIORef _progressData (second $ delete k) when (isJust p) $ debugMessage $ "Done " ++ map toLower k tediousSize :: String -> Int -> IO () tediousSize k s = updateProgressData k uptot where uptot p = case total p of Just t -> seq ts $ p { total = Just ts } where ts = t + s Nothing -> p { total = Just s } -- | XXX: document this constant minlist :: Int minlist = 4 progressList :: String -> [a] -> [a] progressList _ [] = [] progressList k (x:xs) = if l < minlist then x:xs else startit x : pl xs where l = length (x:xs) startit y = unsafePerformIO $ do beginTedious k tediousSize k l return y pl [] = [] pl [y] = unsafePerformIO $ do endTedious k return [y] pl (y:ys) = progress k y : pl ys progress :: String -> a -> a progress k a = unsafePerformIO $ progressIO k >> return a progressIO :: String -> IO () progressIO "" = return () progressIO k = do updateProgressData k $ \p -> p { sofar = sofar p + 1, latest = Nothing } putDebug k "" progressKeepLatest :: String -> a -> a progressKeepLatest k a = unsafePerformIO $ progressKeepLatestIO k >> return a progressKeepLatestIO :: String -> IO () progressKeepLatestIO "" = return () progressKeepLatestIO k = do updateProgressData k (\p -> p {sofar = sofar p + 1}) putDebug k "" finishedOne :: String -> String -> a -> a finishedOne k l a = unsafePerformIO $ finishedOneIO k l >> return a finishedOneIO :: String -> String -> IO () finishedOneIO "" _ = return () finishedOneIO k l = do updateProgressData k (\p -> p { sofar = sofar p + 1, latest = Just l }) putDebug k l putDebug :: String -> String -> IO () putDebug _ _ = return () --putDebug k "" = when (False && debugMode) $ hPutStrLn stderr $ "P: "++k --putDebug k l = when (False && debugMode) $ hPutStrLn stderr $ "P: "++k++" : "++l _progressMode :: IORef Bool _progressMode = unsafePerformIO $ do hSetBuffering stderr LineBuffering newIORef True {-# NOINLINE _progressMode #-} _progressData :: IORef (String, Map String ProgressData) _progressData = unsafePerformIO $ do _ <- forkIO handleProgress newIORef ("", empty) {-# NOINLINE _progressData #-} mkhPutCr :: Handle -> IO (String -> IO ()) mkhPutCr fe = do isTerm <- hIsTerminalDevice fe stdoutIsTerm <- hIsTerminalDevice stdout return $ if isTerm then \s -> do hPutStr fe $ '\r':s ++ "\r" hFlush fe let spaces = '\r':replicate (length s) ' ' ++ "\r" hPutStr fe spaces when stdoutIsTerm $ putStr spaces else \s -> unless (null s) $ do hPutStrLn fe s hFlush fe setProgressMode :: Bool -> IO () setProgressMode = writeIORef _progressMode withoutProgress :: IO a -> IO a withoutProgress job = bracket off restore (const job) where off = withProgressMode $ \m -> do debugMessage "Disabling progress reports..." setProgressMode False return m restore m = do if m then debugMessage "Reenabling progress reports." else debugMessage "Leaving progress reports off." setProgressMode m updateProgressData :: String -> (ProgressData -> ProgressData) -> IO () updateProgressData k f = whenProgressMode $ modifyIORef _progressData (\(_,m) -> (k,adjust f k m)) setProgressData :: String -> ProgressData -> IO () setProgressData k p = whenProgressMode $ modifyIORef _progressData (second $ insert k p) getProgressData :: String -> IO (Maybe ProgressData) getProgressData k = withProgressMode $ \p -> if p then (lookup k . snd) `fmap` readIORef _progressData else return Nothing getProgressLast :: IO String getProgressLast = withProgressMode $ \p -> if p then fst `fmap` readIORef _progressData else return "" whenProgressMode :: IO a -> IO () whenProgressMode j = withProgressMode $ const $ void j withProgressMode :: (Bool -> IO a) -> IO a withProgressMode job = (readIORef _progressMode) >>= job darcs-2.14.5/src/Darcs/Util/Prompt.hs0000644000000000000000000000724207346545000015452 0ustar0000000000000000module Darcs.Util.Prompt ( -- * User prompts askEnter , askUser , askUserListItem , PromptConfig(..) , promptYorn , promptChar ) where import Prelude () import Darcs.Prelude import Control.Monad ( void ) import Data.Char ( toUpper, toLower, isSpace ) import System.Console.Haskeline ( runInputT, defaultSettings, getInputLine, getInputChar, outputStr, outputStrLn ) import Darcs.Util.Progress ( withoutProgress ) -- | Ask the user for a line of input. askUser :: String -- ^ The prompt to display -> IO String -- ^ The string the user entered. askUser prompt = withoutProgress $ runInputT defaultSettings $ getInputLine prompt >>= maybe (error "askUser: unexpected end of input") return -- | Ask the user to press Enter askEnter :: String -- ^ The prompt to display -> IO () askEnter prompt = void $ askUser prompt -- | @askUserListItem prompt xs@ enumerates @xs@ on the screen, allowing -- the user to choose one of the items askUserListItem :: String -> [String] -> IO String askUserListItem prompt xs = withoutProgress $ runInputT defaultSettings $ do outputStr . unlines $ zipWith (\n x -> show n ++ ". " ++ x) [1::Int ..] xs loop where loop = do answer <- getInputLine prompt >>= maybe (error "askUser: unexpected end of input") return case maybeRead answer of Just n | n > 0 && n <= length xs -> return (xs !! (n-1)) _ -> outputStrLn "Invalid response, try again!" >> loop maybeRead :: Read a => String -> Maybe a maybeRead s = case reads s of [(x, rest)] | all isSpace rest -> Just x _ -> Nothing data PromptConfig = PromptConfig { pPrompt :: String , pBasicCharacters :: [Char] , pAdvancedCharacters :: [Char] -- ^ only shown on help , pDefault :: Maybe Char , pHelp :: [Char] } -- | Prompt the user for a yes or no promptYorn :: String -> IO Bool promptYorn p = (== 'y') `fmap` promptChar (PromptConfig p "yn" [] Nothing []) -- | Prompt the user for a character, among a list of possible ones. -- Always returns a lowercase character. This is because the default -- character (ie, the character shown in uppercase, that is automatically -- selected when the user presses the space bar) is shown as uppercase, -- hence users may want to enter it as uppercase. promptChar :: PromptConfig -> IO Char promptChar (PromptConfig p basic_chs adv_chs md help_chs) = withoutProgress $ runInputT defaultSettings loopChar where chs = basic_chs ++ adv_chs loopChar = do let chars = setDefault (basic_chs ++ (if null adv_chs then "" else "...")) prompt = p ++ " [" ++ chars ++ "]" ++ helpStr a <- getInputChar prompt >>= maybe (error "promptChar: unexpected end of input") (return . toLower) case () of _ | a `elem` chs -> return a | a == ' ' -> maybe tryAgain return md | a `elem` help_chs -> return a | otherwise -> tryAgain helpStr = case help_chs of [] -> "" (h:_) | null adv_chs -> ", or " ++ (h:" for help: ") | otherwise -> ", or " ++ (h:" for more options: ") tryAgain = do outputStrLn "Invalid response, try again!" loopChar setDefault s = case md of Nothing -> s Just d -> map (setUpper d) s setUpper d c = if d == c then toUpper c else c darcs-2.14.5/src/Darcs/Util/Ratified.hs0000644000000000000000000000024307346545000015712 0ustar0000000000000000-- | XXX: Perhaps a word of explanation here [WL] module Darcs.Util.Ratified ( readFile , hGetContents ) where import System.IO( hGetContents ) darcs-2.14.5/src/Darcs/Util/Show.hs0000644000000000000000000000063007346545000015103 0ustar0000000000000000module Darcs.Util.Show ( appPrec, BSWrapper(..) ) where import Prelude () import Darcs.Prelude import qualified Data.ByteString as B appPrec :: Int appPrec = 10 newtype BSWrapper = BSWrapper B.ByteString instance Show BSWrapper where showsPrec d (BSWrapper bs) = showParen (d > appPrec) $ showString "Data.ByteString.Char8.pack " . showsPrec (appPrec + 1) bs darcs-2.14.5/src/Darcs/Util/SignalHandler.hs0000644000000000000000000001314307346545000016701 0ustar0000000000000000-- Copyright (C) 2003 David Roundy -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. {-# LANGUAGE CPP, DeriveDataTypeable #-} module Darcs.Util.SignalHandler ( withSignalsHandled, withSignalsBlocked, catchInterrupt, catchNonSignal, tryNonSignal, stdoutIsAPipe ) where import Prelude () import Darcs.Prelude import System.IO.Error ( isUserError, ioeGetErrorString, ioeGetFileName ) import System.Exit ( exitWith, ExitCode ( ExitFailure ) ) import Control.Concurrent ( ThreadId, myThreadId ) import Control.Exception ( catch, throw, throwTo, mask, Exception(..), SomeException(..), IOException ) import System.Posix.Files ( getFdStatus, isNamedPipe ) import System.Posix.IO ( stdOutput ) import Data.Typeable ( Typeable, cast ) import Data.List ( isPrefixOf ) import System.IO ( hPutStrLn, stderr ) import Control.Monad ( unless ) import Darcs.Util.Workaround ( installHandler, raiseSignal, Handler(..), Signal , sigINT, sigHUP, sigABRT, sigALRM, sigTERM, sigPIPE ) #ifdef WIN32 import Darcs.Util.CtrlC ( withCtrlCHandler ) #endif stdoutIsAPipe :: IO Bool stdoutIsAPipe = catch (do stat <- getFdStatus stdOutput return (isNamedPipe stat)) (\(_ :: IOException) -> return False) withSignalsHandled :: IO a -> IO a newtype SignalException = SignalException Signal deriving (Show, Typeable) instance Exception SignalException where toException = SomeException fromException (SomeException e) = cast e withSignalsHandled job = do thid <- myThreadId mapM_ (ih thid) [sigINT, sigHUP, sigABRT, sigTERM, sigPIPE] catchUserErrors (job' thid `catchSignal` defaults) die_with_string where defaults s | s == sigINT = ew s "Interrupted!" | s == sigHUP = ew s "HUP" | s == sigABRT = ew s "ABRT" | s == sigTERM = ew s "TERM" | s == sigPIPE = exitWith $ ExitFailure 1 | otherwise = ew s "Unhandled signal!" ew sig s = do hPutStrLn stderr $ "withSignalsHandled: " ++ s resethandler sig raiseSignal sig -- ensure that our caller knows how we died exitWith $ ExitFailure 1 die_with_string e | "STDOUT" `isPrefixOf` e = do is_pipe <- stdoutIsAPipe unless is_pipe $ hPutStrLn stderr $ "\ndarcs failed: "++drop 6 e exitWith $ ExitFailure 2 die_with_string e = do hPutStrLn stderr $ "\ndarcs failed: "++e exitWith $ ExitFailure 2 #ifdef WIN32 job' thid = withCtrlCHandler (throwTo thid $ SignalException sigINT) job #else job' _ = job #endif resethandler :: Signal -> IO () resethandler s = do _ <- installHandler s Default Nothing return () ih :: ThreadId -> Signal -> IO () ih thid s = do _ <- installHandler s (Catch $ throwTo thid $ SignalException s) Nothing return () catchSignal :: IO a -> (Signal -> IO a) -> IO a catchSignal job handler = job `catch` (\(SignalException sig) -> handler sig) -- | A drop-in replacement for 'Control.Exception.catch', which allows -- us to catch anything but a signal. Useful for situations where we -- don't want to inhibit ctrl-C. catchNonSignal :: IO a -> (SomeException -> IO a) -> IO a catchNonSignal comp handler = catch comp handler' where handler' se = case fromException se :: Maybe SignalException of Nothing -> handler se Just _ -> throw se catchInterrupt :: IO a -> IO a -> IO a catchInterrupt job handler = job `catchSignal` h where h s | s == sigINT = handler | otherwise = throw (SignalException s) tryNonSignal :: IO a -> IO (Either SomeException a) tryNonSignal j = (Right `fmap` j) `catchNonSignal` \e -> return (Left e) catchUserErrors :: IO a -> (String -> IO a) -> IO a catchUserErrors comp handler = catch comp handler' where handler' ioe | isUserError ioe = handler (ioeGetErrorString ioe) | ioeGetFileName ioe == Just "" = handler ("STDOUT" ++ ioeGetErrorString ioe) | otherwise = throw ioe withSignalsBlocked :: IO a -> IO a withSignalsBlocked job = mask (\unmask -> job >>= \r -> unmask (return r) `catchSignal` couldnt_do r) where couldnt_do r s | s == sigINT = oops "interrupt" r | s == sigHUP = oops "HUP" r | s == sigABRT = oops "ABRT" r | s == sigALRM = oops "ALRM" r | s == sigTERM = oops "TERM" r | s == sigPIPE = return r | otherwise = oops "unknown signal" r oops s r = do hPutStrLn stderr $ "Couldn't handle " ++ s ++ " since darcs was in a sensitive job." return r darcs-2.14.5/src/Darcs/Util/Ssh.hs0000644000000000000000000003111707346545000014724 0ustar0000000000000000-- -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; see the file COPYING. If not, write to -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. module Darcs.Util.Ssh ( SshSettings(..) , defaultSsh , windows , copySSH , SSHCmd(..) , getSSH , environmentHelpSsh , environmentHelpScp , environmentHelpSshPort , transferModeHeader ) where import Prelude () import Darcs.Prelude import Prelude hiding ( lookup ) import System.Environment ( getEnv ) import System.Exit ( ExitCode(..) ) import Control.Concurrent.MVar ( MVar, newMVar, withMVar, modifyMVar, modifyMVar_ ) import Control.Exception ( throwIO, catch, catchJust, SomeException ) import Control.Monad ( unless, (>=>) ) import qualified Data.ByteString as B (ByteString, hGet, writeFile ) import Data.Map ( Map, empty, insert, lookup ) import System.IO ( Handle, hSetBinaryMode, hPutStrLn, hGetLine, hFlush ) import System.IO.Unsafe ( unsafePerformIO ) import System.Process ( runInteractiveProcess, readProcessWithExitCode ) import Darcs.Util.SignalHandler ( catchNonSignal ) import Darcs.Util.URL ( SshFilePath, sshFilePathOf, sshUhost, sshRepo, sshFile ) import Darcs.Util.Text ( breakCommand, showCommandLine ) import Darcs.Util.Exception ( prettyException, catchall ) import Darcs.Util.Exec ( readInteractiveProcess, ExecException(..), Redirect(AsIs) ) import Darcs.Util.Progress ( withoutProgress, debugMessage, debugFail ) import qualified Darcs.Util.Ratified as Ratified ( hGetContents ) import Data.IORef ( IORef, newIORef, readIORef ) import Data.List ( isPrefixOf ) import System.Info ( os ) import System.IO.Error ( ioeGetErrorType, isDoesNotExistErrorType ) import Darcs.Util.Global ( whenDebugMode ) windows :: Bool windows = "mingw" `isPrefixOf` os data SshSettings = SshSettings { ssh :: String , scp :: String , sftp :: String } deriving (Show, Eq) _defaultSsh :: IORef SshSettings _defaultSsh = unsafePerformIO $ newIORef =<< detectSsh {-# NOINLINE _defaultSsh #-} -- | Expected properties: -- -- * only ever runs once in the lifetime of the program -- * environment variables override all -- * tries Putty first on Windows -- * falls back to plain old ssh detectSsh :: IO SshSettings detectSsh = do whenDebugMode (putStrLn "Detecting SSH settings") vanilla <- if windows then do plinkStr <- (snd3 <$> readProcessWithExitCode "plink" [] "") `catch` \(e :: SomeException) -> return (show e) whenDebugMode $ putStrLn $ "SSH settings (plink): " ++ (concat . take 1 . lines $ plinkStr) if "PuTTY" `isPrefixOf` plinkStr then return (SshSettings "plink" "pscp -q" "psftp") else return rawVanilla else return rawVanilla settings <- SshSettings <$> fromEnv (ssh vanilla) "DARCS_SSH" <*> fromEnv (scp vanilla) "DARCS_SCP" <*> fromEnv (sftp vanilla) "DARCS_SFTP" whenDebugMode (putStrLn $ "SSH settings: " ++ show settings) return settings where snd3 (_, x, _) = x rawVanilla = SshSettings "ssh" "scp -q" "sftp" fromEnv :: String -> String -> IO String fromEnv d v = catchJust notFound (getEnv v) (const (return d)) notFound e = if isDoesNotExistErrorType (ioeGetErrorType e) then Just () else Nothing defaultSsh :: SshSettings defaultSsh = unsafePerformIO $ readIORef _defaultSsh {-# NOINLINE defaultSsh #-} -- | A re-usable connection to a remote darcs in transfer-mode. -- It contains the three standard handles. data Connection = C { inp :: !Handle , out :: !Handle , err :: !Handle } -- | Identifier (key) for a connection. type RepoId = (String, String) -- (user@host,repodir) -- | Global mutable variable that contains open connections, -- identified by the repoid part of the ssh file name. -- Only one thread can use a connection at a time, which is why -- we stuff them behind their own 'MVar's. -- -- We distinguish between a failed connection (represented by a -- 'Nothing' entry in the map) and one that was never established -- (the repoid is not in the map). Once a connection fails, -- either when trying to establish it or during usage, it will not -- be tried again. sshConnections :: MVar (Map RepoId (Maybe (MVar Connection))) sshConnections = unsafePerformIO $ newMVar empty {-# NOINLINE sshConnections #-} -- | Wait for an existing connection to become available or, if none -- is available, try to create a new one and cache it. getSshConnection :: String -- ^ remote darcs command -> SshFilePath -- ^ destination -> IO (Maybe (MVar Connection)) -- ^ wrapper for the action getSshConnection rdarcs sshfp = modifyMVar sshConnections $ \cmap -> do let key = repoid sshfp case lookup key cmap of Nothing -> do -- we have not yet tried with this key, do it now mc <- newSshConnection rdarcs sshfp case mc of Nothing -> -- failed, remember it, so we don't try again return (insert key Nothing cmap, Nothing) Just c -> do -- success, remember and use v <- newMVar c return (insert key (Just v) cmap, Just v) Just Nothing -> -- we have tried to connect before, don't do it again return (cmap, Nothing) Just (Just v) -> -- we do have a connection, return an action that -- waits until it is available return (cmap, Just v) -- | Try to create a new ssh connection to a remote darcs that runs the -- transfer-mode command. This is tried only once per repoid. newSshConnection :: String -> SshFilePath -> IO (Maybe Connection) newSshConnection rdarcs sshfp = do (sshcmd,sshargs_) <- getSSH SSH debugMessage $ "Starting new ssh connection to " ++ sshUhost sshfp let sshargs = sshargs_ ++ ["--", sshUhost sshfp, rdarcs, "transfer-mode", "--repodir", sshRepo sshfp] debugMessage $ "Exec: " ++ showCommandLine (sshcmd:sshargs) (i,o,e,_) <- runInteractiveProcess sshcmd sshargs Nothing Nothing do hSetBinaryMode i True hSetBinaryMode o True l <- hGetLine o unless (l == transferModeHeader) $ debugFail "Couldn't start darcs transfer-mode on server" return $ Just C { inp = i, out = o, err = e } `catchNonSignal` \exn -> do debugMessage $ "Failed to start ssh connection: " ++ prettyException exn debugMessage $ unlines [ "NOTE: the server may be running a version of darcs prior to 2.0.0." , "" , "Installing darcs 2 on the server will speed up ssh-based commands." ] return Nothing -- | Mark any connection associated with the given ssh file path -- as failed, so it won't be tried again. dropSshConnection :: RepoId -> IO () dropSshConnection key = do debugMessage $ "Dropping ssh failed connection to " ++ fst key ++ ":" ++ snd key modifyMVar_ sshConnections (return . insert key Nothing) repoid :: SshFilePath -> RepoId repoid sshfp = (sshUhost sshfp, sshRepo sshfp) grabSSH :: SshFilePath -> Connection -> IO B.ByteString grabSSH src c = do debugMessage $ "grabSSH src=" ++ sshFilePathOf src let failwith e = do dropSshConnection (repoid src) -- hGetContents is ok here because we're -- only grabbing stderr, and we're also -- about to throw the contents. eee <- Ratified.hGetContents (err c) debugFail $ e ++ " grabbing ssh file " ++ sshFilePathOf src ++"\n" ++ eee file = sshFile src hPutStrLn (inp c) $ "get " ++ file hFlush (inp c) l2 <- hGetLine (out c) if l2 == "got "++file then do showlen <- hGetLine (out c) case reads showlen of [(len,"")] -> B.hGet (out c) len _ -> failwith "Couldn't get length" else if l2 == "error "++file then do e <- hGetLine (out c) case reads e of (msg,_):_ -> debugFail $ "Error reading file remotely:\n"++msg [] -> failwith "An error occurred" else failwith "Error" copySSH :: String -> SshFilePath -> FilePath -> IO () copySSH rdarcs src dest = do debugMessage $ "copySSH file: " ++ sshFilePathOf src -- TODO why do we disable progress reporting here? withoutProgress $ do mc <- getSshConnection rdarcs src case mc of Just v -> withMVar v (grabSSH src >=> B.writeFile dest) Nothing -> do -- remote 'darcs transfer-mode' does not work => use scp let u = escape_dollar $ sshFilePathOf src (scpcmd, args) <- getSSH SCP let scp_args = filter (/="-q") args ++ ["--", u, dest] debugMessage $ "Exec: " ++ showCommandLine (scpcmd:scp_args) (r, scp_err) <- readInteractiveProcess scpcmd scp_args unless (r == ExitSuccess) $ throwIO $ ExecException scpcmd scp_args (AsIs,AsIs,AsIs) scp_err where -- '$' in filenames is troublesome for scp, for some reason. escape_dollar :: String -> String escape_dollar = concatMap tr where tr '$' = "\\$" tr c = [c] transferModeHeader :: String transferModeHeader = "Hello user, I am darcs transfer mode" -- --------------------------------------------------------------------- -- older ssh helper functions -- --------------------------------------------------------------------- data SSHCmd = SSH | SCP | SFTP fromSshCmd :: SshSettings -> SSHCmd -> String fromSshCmd s SSH = ssh s fromSshCmd s SCP = scp s fromSshCmd s SFTP = sftp s -- | Return the command and arguments needed to run an ssh command -- First try the appropriate darcs environment variable and SSH_PORT -- defaulting to "ssh" and no specified port. getSSH :: SSHCmd -> IO (String, [String]) getSSH cmd = do port <- (portFlag cmd `fmap` getEnv "SSH_PORT") `catchall` return [] let (sshcmd, ssh_args) = breakCommand command return (sshcmd, ssh_args ++ port) where command = fromSshCmd defaultSsh cmd portFlag SSH x = ["-p", x] portFlag SCP x = ["-P", x] portFlag SFTP x = ["-oPort=" ++ x] environmentHelpSsh :: ([String], [String]) environmentHelpSsh = (["DARCS_SSH"], [ "Repositories of the form [user@]host:[dir] are taken to be remote", "repositories, which Darcs accesses with the external program ssh(1).", "", "The environment variable $DARCS_SSH can be used to specify an", "alternative SSH client. Arguments may be included, separated by", "whitespace. The value is not interpreted by a shell, so shell", "constructs cannot be used; in particular, it is not possible for the", "program name to contain whitespace by using quoting or escaping."]) environmentHelpScp :: ([String], [String]) environmentHelpScp = (["DARCS_SCP", "DARCS_SFTP"], [ "When reading from a remote repository, Darcs will attempt to run", "`darcs transfer-mode` on the remote host. This will fail if the", "remote host only has Darcs 1 installed, doesn't have Darcs installed", "at all, or only allows SFTP.", "", "If transfer-mode fails, Darcs will fall back on scp(1) and sftp(1).", "The commands invoked can be customized with the environment variables", "$DARCS_SCP and $DARCS_SFTP respectively, which behave like $DARCS_SSH.", "If the remote end allows only sftp, try setting DARCS_SCP=sftp."]) environmentHelpSshPort :: ([String], [String]) environmentHelpSshPort = (["SSH_PORT"], [ "If this environment variable is set, it will be used as the port", "number for all SSH calls made by Darcs (when accessing remote", "repositories over SSH). This is useful if your SSH server does not", "run on the default port, and your SSH client does not support", "ssh_config(5). OpenSSH users will probably prefer to put something", "like `Host *.example.net Port 443` into their ~/.ssh/config file."]) darcs-2.14.5/src/Darcs/Util/Text.hs0000644000000000000000000000446507346545000015121 0ustar0000000000000000{-# LANGUAGE OverloadedStrings #-} module Darcs.Util.Text ( -- * Text construction. sentence -- * Text formatting. , formatText , formatParas , formatPara , chompTrailingNewline -- * Text processing , breakCommand , quote , pathlist , showCommandLine ) where import Prelude () import Darcs.Prelude import Control.Arrow ( first ) import Data.List ( intercalate ) import Darcs.Util.Printer ( Doc, renderString, quoted, hsep ) sentence :: Doc -> Doc sentence = (<> ".") -- |Take a list of paragraphs and format them to the given line length, with -- a blank line between paragraphs. formatText :: Int -> [String] -> String formatText linelen = unlines . formatParas linelen formatParas :: Int -> [String] -> [String] formatParas linelen = intercalate [""] . map (map unwords . formatPara linelen . words) -- |Take a list of words and split it up so that each chunk fits into the specified width -- when spaces are included. Any words longer than the specified width end up in a chunk -- of their own. formatPara :: Int -> [[a]] -> [[[a]]] formatPara w = para' where para' [] = [] para' xs = uncurry (:) $ para'' w xs para'' r (x:xs) | w == r || length x < r = first (x:) $ para'' (r - length x - 1) xs para'' _ xs = ([], para' xs) breakCommand :: String -> (String, [String]) breakCommand s = case words s of (arg0:args) -> (arg0,args) [] -> (s,[]) chompTrailingNewline :: String -> String chompTrailingNewline "" = "" chompTrailingNewline s = if last s == '\n' then init s else s -- | Quote a string for screen output. quote :: String -> String quote = renderString . quoted -- | Format a list of 'FilePath's as quoted text. It deliberately refuses to -- use English.andClauses but rather separates the quoted strings only with a -- space, because this makes it usable for copy and paste e.g. as arguments to -- another shell command. pathlist :: [FilePath] -> Doc pathlist paths = hsep (map quoted paths) -- | Produce a String composed by the elements of [String] each enclosed in -- double quotes. showCommandLine :: [String] -> String showCommandLine strings = showCommandLine' ['"'] strings where showCommandLine' x xs = x ++ intercalate (x ++ " " ++ x) xs ++ x darcs-2.14.5/src/Darcs/Util/Tree.hs0000644000000000000000000005161707346545000015075 0ustar0000000000000000-- Copyright (C) 2009-2011 Petr Rockai -- -- BSD3 {-# LANGUAGE ScopedTypeVariables, MultiParamTypeClasses, FlexibleInstances, BangPatterns #-} -- | The abstract representation of a Tree and useful abstract utilities to -- handle those. module Darcs.Util.Tree ( Tree, Blob(..), TreeItem(..), ItemType(..), Hash(..) , makeTree, makeTreeWithHash, emptyTree, emptyBlob, makeBlob, makeBlobBS -- * Unfolding stubbed (lazy) Trees. -- -- | By default, Tree obtained by a read function is stubbed: it will -- contain Stub items that need to be executed in order to access the -- respective subtrees. 'expand' will produce an unstubbed Tree. , expandUpdate, expand, expandPath, checkExpand -- * Tree access and lookup. , items, list, listImmediate, treeHash , lookup, find, findFile, findTree, itemHash, itemType , zipCommonFiles, zipFiles, zipTrees, diffTrees -- * Files (Blobs). , readBlob -- * Filtering trees. , FilterTree(..), restrict -- * Manipulating trees. , modifyTree, updateTree, partiallyUpdateTree, updateSubtrees, overlay , addMissingHashes ) where import Prelude () import Darcs.Prelude hiding ( filter ) import Control.Exception( catch, IOException ) import Darcs.Util.Path import Darcs.Util.Hash import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString as B import qualified Data.Map as M import Data.Maybe( catMaybes, isNothing ) import Data.Either( lefts, rights ) import Data.List( union, sort ) import Control.Monad( filterM ) -------------------------------- -- Tree, Blob and friends -- data Blob m = Blob !(m BL.ByteString) !Hash data TreeItem m = File !(Blob m) | SubTree !(Tree m) | Stub !(m (Tree m)) !Hash data ItemType = TreeType | BlobType deriving (Show, Eq, Ord) -- | Abstraction of a filesystem tree. -- Please note that the Tree returned by the respective read operations will -- have TreeStub items in it. To obtain a Tree without such stubs, call -- expand on it, eg.: -- -- > tree <- readDarcsPristine "." >>= expand -- -- When a Tree is expanded, it becomes \"final\". All stubs are forced and the -- Tree can be traversed purely. Access to actual file contents stays in IO -- though. -- -- A Tree may have a Hash associated with it. A pair of Tree's is identical -- whenever their hashes are (the reverse need not hold, since not all Trees -- come equipped with a hash). data Tree m = Tree { items :: M.Map Name (TreeItem m) -- | Get hash of a Tree. This is guaranteed to uniquely -- identify the Tree (including any blob content), as far as -- cryptographic hashes are concerned. Sha256 is recommended. , treeHash :: !Hash } listImmediate :: Tree m -> [(Name, TreeItem m)] listImmediate = M.toList . items -- | Get a hash of a TreeItem. May be Nothing. itemHash :: TreeItem m -> Hash itemHash (File (Blob _ h)) = h itemHash (SubTree t) = treeHash t itemHash (Stub _ h) = h itemType :: TreeItem m -> ItemType itemType (File _) = BlobType itemType (SubTree _) = TreeType itemType (Stub _ _) = TreeType emptyTree :: Tree m emptyTree = Tree { items = M.empty , treeHash = NoHash } emptyBlob :: (Monad m) => Blob m emptyBlob = Blob (return BL.empty) NoHash makeBlob :: (Monad m) => BL.ByteString -> Blob m makeBlob str = Blob (return str) (sha256 str) makeBlobBS :: (Monad m) => B.ByteString -> Blob m makeBlobBS s' = let s = BL.fromChunks [s'] in Blob (return s) (sha256 s) makeTree :: [(Name,TreeItem m)] -> Tree m makeTree l = Tree { items = M.fromList l , treeHash = NoHash } makeTreeWithHash :: [(Name,TreeItem m)] -> Hash -> Tree m makeTreeWithHash l h = Tree { items = M.fromList l , treeHash = h } ----------------------------------- -- Tree access and lookup -- -- | Look up a 'Tree' item (an immediate subtree or blob). lookup :: Tree m -> Name -> Maybe (TreeItem m) lookup t n = M.lookup n (items t) find' :: TreeItem m -> AnchoredPath -> Maybe (TreeItem m) find' t (AnchoredPath []) = Just t find' (SubTree t) (AnchoredPath (d : rest)) = case lookup t d of Just sub -> find' sub (AnchoredPath rest) Nothing -> Nothing find' _ _ = Nothing -- | Find a 'TreeItem' by its path. Gives 'Nothing' if the path is invalid. find :: Tree m -> AnchoredPath -> Maybe (TreeItem m) find = find' . SubTree -- | Find a 'Blob' by its path. Gives 'Nothing' if the path is invalid, or does -- not point to a Blob. findFile :: Tree m -> AnchoredPath -> Maybe (Blob m) findFile t p = case find t p of Just (File x) -> Just x _ -> Nothing -- | Find a 'Tree' by its path. Gives 'Nothing' if the path is invalid, or does -- not point to a Tree. findTree :: Tree m -> AnchoredPath -> Maybe (Tree m) findTree t p = case find t p of Just (SubTree x) -> Just x _ -> Nothing -- | List all contents of a 'Tree'. list :: Tree m -> [(AnchoredPath, TreeItem m)] list t_ = paths t_ (AnchoredPath []) where paths t p = [ (appendPath p n, i) | (n,i) <- listImmediate t ] ++ concat [ paths subt (appendPath p subn) | (subn, SubTree subt) <- listImmediate t ] expandUpdate :: (Monad m) => (AnchoredPath -> Tree m -> m (Tree m)) -> Tree m -> m (Tree m) expandUpdate update t_ = go (AnchoredPath []) t_ where go path t = do let subtree (name, sub) = do tree <- go (path `appendPath` name) =<< unstub sub return (name, SubTree tree) expanded <- mapM subtree [ x | x@(_, item) <- listImmediate t, isSub item ] let orig_map = M.filter (not . isSub) (items t) expanded_map = M.fromList expanded tree = t { items = M.union orig_map expanded_map } update path tree -- | Expand a stubbed Tree into a one with no stubs in it. You might want to -- filter the tree before expanding to save IO. This is the basic -- implementation, which may be overriden by some Tree instances (this is -- especially true of the Index case). expand :: (Monad m) => Tree m -> m (Tree m) expand = expandUpdate $ const return -- | Unfold a path in a (stubbed) Tree, such that the leaf node of the path is -- reachable without crossing any stubs. Moreover, the leaf ought not be a Stub -- in the resulting Tree. A non-existent path is expanded as far as it can be. expandPath :: (Monad m) => Tree m -> AnchoredPath -> m (Tree m) expandPath t (AnchoredPath []) = return t expandPath t (AnchoredPath (n:rest)) = case lookup t n of (Just item) | isSub item -> amend t n rest =<< unstub item _ -> return t -- fail $ "Descent error in expandPath: " ++ show path_ where amend t' name rest' sub = do sub' <- expandPath sub (AnchoredPath rest') let tree = t' { items = M.insert name (SubTree sub') (items t') } return tree -- | Check the disk version of a Tree: expands it, and checks each -- hash. Returns either the expanded tree or a list of AnchoredPaths -- where there are problems. The first argument is the hashing function -- used to create the tree. checkExpand :: (TreeItem IO -> IO Hash) -> Tree IO -> IO (Either [(AnchoredPath, Hash, Maybe Hash)] (Tree IO)) checkExpand hashFunc t = go (AnchoredPath []) t where go path t_ = do let subtree (name, sub) = do let here = path `appendPath` name sub' <- (Just <$> unstub sub) `catch` \(_ :: IOException) -> return Nothing case sub' of Nothing -> return $ Left [(here, treeHash t_, Nothing)] Just sub'' -> do treeOrTrouble <- go (path `appendPath` name) sub'' return $ case treeOrTrouble of Left problems -> Left problems Right tree -> Right (name, SubTree tree) badBlob (_, f@(File (Blob _ h))) = fmap (/= h) (hashFunc f `catch` (\(_ :: IOException) -> return NoHash)) badBlob _ = return False render (name, f@(File (Blob _ h))) = do h' <- (Just <$> hashFunc f) `catch` \(_ :: IOException) -> return Nothing return (path `appendPath` name, h, h') render (name, _) = return (path `appendPath` name, NoHash, Nothing) subs <- mapM subtree [ x | x@(_, item) <- listImmediate t_, isSub item ] badBlobs <- filterM badBlob (listImmediate t) >>= mapM render let problems = badBlobs ++ concat (lefts subs) if null problems then do let orig_map = M.filter (not . isSub) (items t) expanded_map = M.fromList $ rights subs tree = t_ {items = orig_map `M.union` expanded_map} h' <- hashFunc (SubTree t_) if h' `match` treeHash t_ then return $ Right tree else return $ Left [(path, treeHash t_, Just h')] else return $ Left problems class (Monad m) => FilterTree a m where -- | Given @pred tree@, produce a 'Tree' that only has items for which -- @pred@ returns @True@. -- The tree might contain stubs. When expanded, these will be subject to -- filtering as well. filter :: (AnchoredPath -> TreeItem m -> Bool) -> a m -> a m instance (Monad m) => FilterTree Tree m where filter predicate t_ = filter' t_ (AnchoredPath []) where filter' t path = t { items = M.mapMaybeWithKey (wibble path) $ items t } wibble path name item = let npath = path `appendPath` name in if predicate npath item then Just $ filterSub npath item else Nothing filterSub npath (SubTree t) = SubTree $ filter' t npath filterSub npath (Stub stub h) = Stub (do x <- stub return $ filter' x npath) h filterSub _ x = x -- | Given two Trees, a @guide@ and a @tree@, produces a new Tree that is a -- identical to @tree@, but only has those items that are present in both -- @tree@ and @guide@. The @guide@ Tree may not contain any stubs. restrict :: (FilterTree t m) => Tree n -> t m -> t m restrict guide tree = filter accept tree where accept path item = case (find guide path, item) of (Just (SubTree _), SubTree _) -> True (Just (SubTree _), Stub _ _) -> True (Just (File _), File _) -> True (Just (Stub _ _), _) -> bug "*sulk* Go away, you, you precondition violator!" (_, _) -> False -- | Read a Blob into a Lazy ByteString. Might be backed by an mmap, use with -- care. readBlob :: Blob m -> m BL.ByteString readBlob (Blob r _) = r -- | For every pair of corresponding blobs from the two supplied trees, -- evaluate the supplied function and accumulate the results in a list. Hint: -- to get IO actions through, just use sequence on the resulting list. -- NB. This won't expand any stubs. zipCommonFiles :: (AnchoredPath -> Blob m -> Blob m -> a) -> Tree m -> Tree m -> [a] zipCommonFiles f a b = catMaybes [ flip (f p) x `fmap` findFile a p | (p, File x) <- list b ] -- | For each file in each of the two supplied trees, evaluate the supplied -- function (supplying the corresponding file from the other tree, or Nothing) -- and accumulate the results in a list. Hint: to get IO actions through, just -- use sequence on the resulting list. NB. This won't expand any stubs. zipFiles :: (AnchoredPath -> Maybe (Blob m) -> Maybe (Blob m) -> a) -> Tree m -> Tree m -> [a] zipFiles f a b = [ f p (findFile a p) (findFile b p) | p <- paths a `sortedUnion` paths b ] where paths t = sort [ p | (p, File _) <- list t ] zipTrees :: (AnchoredPath -> Maybe (TreeItem m) -> Maybe (TreeItem m) -> a) -> Tree m -> Tree m -> [a] zipTrees f a b = [ f p (find a p) (find b p) | p <- reverse (paths a `sortedUnion` paths b) ] where paths t = sort [ p | (p, _) <- list t ] -- | Helper function for taking the union of AnchoredPath lists that -- are already sorted. This function does not check the precondition -- so use it carefully. sortedUnion :: [AnchoredPath] -> [AnchoredPath] -> [AnchoredPath] sortedUnion [] ys = ys sortedUnion xs [] = xs sortedUnion a@(x:xs) b@(y:ys) = case compare x y of LT -> x : sortedUnion xs b EQ -> x : sortedUnion xs ys GT -> y : sortedUnion a ys -- | Cautiously extracts differing subtrees from a pair of Trees. It will never -- do any unneccessary expanding. Tree hashes are used to cut the comparison as -- high up the Tree branches as possible. The result is a pair of trees that do -- not share any identical subtrees. They are derived from the first and second -- parameters respectively and they are always fully expanded. It might be -- advantageous to feed the result into 'zipFiles' or 'zipTrees'. diffTrees :: forall m. (Monad m) => Tree m -> Tree m -> m (Tree m, Tree m) diffTrees left right = if treeHash left `match` treeHash right then return (emptyTree, emptyTree) else diff left right where isFile (File _) = True isFile _ = False notFile = not . isFile isEmpty = null . listImmediate subtree :: TreeItem m -> m (Tree m) subtree (Stub x _) = x subtree (SubTree x) = return x subtree (File _) = bug "diffTrees tried to descend a File as a subtree" maybeUnfold (Stub x _) = SubTree `fmap` (x >>= expand) maybeUnfold (SubTree x) = SubTree `fmap` expand x maybeUnfold i = return i immediateN t = [ n | (n, _) <- listImmediate t ] diff left' right' = do is <- sequence [ case (lookup left' n, lookup right' n) of (Just l, Nothing) -> do l' <- maybeUnfold l return (n, Just l', Nothing) (Nothing, Just r) -> do r' <- maybeUnfold r return (n, Nothing, Just r') (Just l, Just r) | itemHash l `match` itemHash r -> return (n, Nothing, Nothing) | notFile l && notFile r -> do x <- subtree l y <- subtree r (x', y') <- diffTrees x y if isEmpty x' && isEmpty y' then return (n, Nothing, Nothing) else return (n, Just $ SubTree x', Just $ SubTree y') | isFile l && isFile r -> return (n, Just l, Just r) | otherwise -> do l' <- maybeUnfold l r' <- maybeUnfold r return (n, Just l', Just r') _ -> bug "n lookups failed" | n <- immediateN left' `union` immediateN right' ] let is_l = [ (n, l) | (n, Just l, _) <- is ] is_r = [ (n, r) | (n, _, Just r) <- is ] return (makeTree is_l, makeTree is_r) -- | Modify a Tree (by replacing, or removing or adding items). modifyTree :: (Monad m) => Tree m -> AnchoredPath -> Maybe (TreeItem m) -> Tree m modifyTree t_ p_ i_ = snd $ go t_ p_ i_ where fix t unmod items' = (unmod, t { items = (countmap items':: Int) `seq` items' , treeHash = if unmod then treeHash t else NoHash }) go t (AnchoredPath []) (Just (SubTree sub)) = (treeHash t `match` treeHash sub, sub) go t (AnchoredPath [n]) (Just item) = fix t unmod items' where !items' = M.insert n item (items t) !unmod = itemHash item `match` case lookup t n of Nothing -> NoHash Just i -> itemHash i go t (AnchoredPath [n]) Nothing = fix t unmod items' where !items' = M.delete n (items t) !unmod = isNothing $ lookup t n go t path@(AnchoredPath (n:r)) item = fix t unmod items' where subtree s = go s (AnchoredPath r) item !items' = M.insert n sub (items t) !sub = snd sub' !unmod = fst sub' !sub' = case lookup t n of Just (SubTree s) -> let (mod', sub'') = subtree s in (mod', SubTree sub'') Just (Stub s _) -> (False, Stub (do x <- s return $! snd $! subtree x) NoHash) Nothing -> (False, SubTree $! snd $! subtree emptyTree) _ -> bug $ "Modify tree at " ++ show path go _ (AnchoredPath []) (Just (Stub _ _)) = bug $ "descending in modifyTree, case = (Just (Stub _ _)), path = " ++ show p_ go _ (AnchoredPath []) (Just (File _)) = bug $ "descending in modifyTree, case = (Just (File _)), path = " ++ show p_ go _ (AnchoredPath []) Nothing = bug $ "descending in modifyTree, case = Nothing, path = " ++ show p_ countmap :: forall a k. M.Map k a -> Int countmap = M.foldr (\_ i -> i + 1) 0 updateSubtrees :: (Tree m -> Tree m) -> Tree m -> Tree m updateSubtrees fun t = fun $ t { items = M.mapWithKey (curry $ snd . update) $ items t , treeHash = NoHash } where update (k, SubTree s) = (k, SubTree $ updateSubtrees fun s) update (k, File f) = (k, File f) update (_, Stub _ _) = bug "Stubs not supported in updateTreePostorder" -- | Does /not/ expand the tree. updateTree :: (Monad m) => (TreeItem m -> m (TreeItem m)) -> Tree m -> m (Tree m) updateTree fun t = partiallyUpdateTree fun (\_ _ -> True) t -- | Does /not/ expand the tree. partiallyUpdateTree :: (Monad m) => (TreeItem m -> m (TreeItem m)) -> (AnchoredPath -> TreeItem m -> Bool) -> Tree m -> m (Tree m) partiallyUpdateTree fun predi t' = go (AnchoredPath []) t' where go path t = do items' <- M.fromList <$> mapM (maybeupdate path) (listImmediate t) subtree <- fun . SubTree $ t { items = items' , treeHash = NoHash } case subtree of SubTree t'' -> return t'' _ -> bug "function passed to partiallyUpdateTree didn't changed SubTree to something else" maybeupdate path (k, item) = if predi (path `appendPath` k) item then update (path `appendPath` k) (k, item) else return (k, item) update path (k, SubTree tree) = (\new -> (k, SubTree new)) <$> go path tree update _ (k, item) = (\new -> (k, new)) <$> fun item -- | Lay one tree over another. The resulting Tree will look like the base (1st -- parameter) Tree, although any items also present in the overlay Tree will be -- taken from the overlay. It is not allowed to overlay a different kind of an -- object, nor it is allowed for the overlay to add new objects to base. This -- means that the overlay Tree should be a subset of the base Tree (although -- any extraneous items will be ignored by the implementation). overlay :: (Monad m) => Tree m -> Tree m -> Tree m overlay base over = Tree { items = M.fromList immediate , treeHash = NoHash } where immediate = [ (n, get n) | (n, _) <- listImmediate base ] get n = case (M.lookup n $ items base, M.lookup n $ items over) of (Just (File _), Just f@(File _)) -> f (Just (SubTree b), Just (SubTree o)) -> SubTree $ overlay b o (Just (Stub b _), Just (SubTree o)) -> Stub (flip overlay o `fmap` b) NoHash (Just (SubTree b), Just (Stub o _)) -> Stub (overlay b `fmap` o) NoHash (Just (Stub b _), Just (Stub o _)) -> Stub (do o' <- o b' <- b return $ overlay b' o') NoHash (Just x, _) -> x (_, _) -> bug $ "Unexpected case in overlay at get " ++ show n ++ "." addMissingHashes :: (Monad m) => (TreeItem m -> m Hash) -> Tree m -> m (Tree m) addMissingHashes make = updateTree update -- use partiallyUpdateTree here where update (SubTree t) = make (SubTree t) >>= \x -> return $ SubTree (t { treeHash = x }) update (File blob@(Blob con NoHash)) = do hash <- make $ File blob return $ File (Blob con hash) update (Stub s NoHash) = update . SubTree =<< s update x = return x ------ Private utilities shared among multiple functions. -------- unstub :: (Monad m) => TreeItem m -> m (Tree m) unstub (Stub s _) = s unstub (SubTree s) = return s unstub _ = return emptyTree isSub :: TreeItem m -> Bool isSub (File _) = False isSub _ = True darcs-2.14.5/src/Darcs/Util/Tree/0000755000000000000000000000000007346545000014527 5ustar0000000000000000darcs-2.14.5/src/Darcs/Util/Tree/Hashed.hs0000644000000000000000000002277407346545000016273 0ustar0000000000000000-- Copyright (C) 2009-2011 Petr Rockai -- -- BSD3 {-# LANGUAGE ScopedTypeVariables, BangPatterns #-} -- | A few darcs-specific utility functions. These are used for reading and -- writing darcs and darcs-compatible hashed trees. module Darcs.Util.Tree.Hashed ( -- * Obtaining Trees. -- -- | Please note that Trees obtained this way will contain Stub -- items. These need to be executed (they are IO actions) in order to be -- accessed. Use 'expand' to do this. However, many operations are -- perfectly fine to be used on a stubbed Tree (and it is often more -- efficient to do everything that can be done before expanding a Tree). readDarcsHashed -- * Writing trees. , writeDarcsHashed -- * Interact with hashed tree , hashedTreeIO -- * Other , readDarcsHashedDir , readDarcsHashedNosize , darcsAddMissingHashes , darcsLocation , darcsTreeHash , decodeDarcsHash , decodeDarcsSize , darcsUpdateHashes ) where import Prelude hiding ( lookup, (<$>) ) import System.FilePath ( () ) import System.Directory( doesFileExist ) import Codec.Compression.GZip( decompress, compress ) import Control.Applicative( (<$>) ) import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Lazy.Char8 as BLC import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString as B import Data.List( sortBy ) import Data.Maybe( fromJust, isJust ) import Control.Monad.State.Strict import Darcs.Util.Path import Darcs.Util.ByteString ( FileSegment, readSegment ) import Darcs.Util.Hash import Darcs.Util.Progress ( debugMessage ) import Darcs.Util.Tree import Darcs.Util.Tree.Monad --------------------------------------------------------------------- -- Utilities for coping with the darcs directory format. -- decodeDarcsHash :: BC.ByteString -> Hash decodeDarcsHash bs = case BC.split '-' bs of [s, h] | BC.length s == 10 -> decodeBase16 h _ -> decodeBase16 bs decodeDarcsSize :: BC.ByteString -> Maybe Int decodeDarcsSize bs = case BC.split '-' bs of [s, _] | BC.length s == 10 -> case reads (BC.unpack s) of [(x, _)] -> Just x _ -> Nothing _ -> Nothing darcsLocation :: FilePath -> (Maybe Int, Hash) -> FileSegment darcsLocation dir (s,h) = case hash of "" -> error "darcsLocation: invalid hash" _ -> (dir prefix s ++ hash, Nothing) where prefix Nothing = "" prefix (Just s') = formatSize s' ++ "-" formatSize s' = let n = show s' in replicate (10 - length n) '0' ++ n hash = BC.unpack (encodeBase16 h) ---------------------------------------------- -- Darcs directory format. -- darcsFormatDir :: Tree m -> Maybe BLC.ByteString darcsFormatDir t = BLC.fromChunks . concat <$> mapM string (sortBy cmp $ listImmediate t) where cmp (a, _) (b, _) = compare a b string (name, item) = do header <- case item of File _ -> Just $ BC.pack "file:\n" _ -> Just $ BC.pack "directory:\n" hash <- case itemHash item of NoHash -> Nothing x -> Just $ encodeBase16 x return [ header , encodeWhiteName name , BC.singleton '\n' , hash, BC.singleton '\n' ] darcsParseDir :: BLC.ByteString -> [(ItemType, Name, Maybe Int, Hash)] darcsParseDir content = parse (BLC.split '\n' content) where parse (t:n:h':r) = (header t, decodeWhiteName $ B.concat $ BL.toChunks n, decodeDarcsSize hash, decodeDarcsHash hash) : parse r where hash = BC.concat $ BLC.toChunks h' parse _ = [] header x | x == BLC.pack "file:" = BlobType | x == BLC.pack "directory:" = TreeType | otherwise = error $ "Error parsing darcs hashed dir: " ++ BLC.unpack x ---------------------------------------- -- Utilities. -- -- | Compute a darcs-compatible hash value for a tree-like structure. darcsTreeHash :: Tree m -> Hash darcsTreeHash t = case darcsFormatDir t of Nothing -> NoHash Just x -> sha256 x -- The following two are mostly for experimental use in Packed. darcsUpdateDirHashes :: Tree m -> Tree m darcsUpdateDirHashes = updateSubtrees update where update t = t { treeHash = darcsTreeHash t } darcsUpdateHashes :: (Monad m) => Tree m -> m (Tree m) darcsUpdateHashes = updateTree update where update (SubTree t) = return . SubTree $ t { treeHash = darcsTreeHash t } update (File blob@(Blob con _)) = do hash <- sha256 <$> readBlob blob return $ File (Blob con hash) update stub = return stub darcsHash :: (Monad m) => TreeItem m -> m Hash darcsHash (SubTree t) = return $ darcsTreeHash t darcsHash (File blob) = sha256 <$> readBlob blob darcsHash _ = return NoHash darcsAddMissingHashes :: (Monad m) => Tree m -> m (Tree m) darcsAddMissingHashes = addMissingHashes darcsHash ------------------------------------------- -- Reading darcs pristine data -- -- | Read and parse a darcs-style hashed directory listing from a given @dir@ -- and with a given @hash@. readDarcsHashedDir :: FilePath -> (Maybe Int, Hash) -> IO [(ItemType, Name, Maybe Int, Hash)] readDarcsHashedDir dir h = do debugMessage $ "readDarcsHashedDir: " ++ dir ++ " " ++ BC.unpack (encodeBase16 (snd h)) exist <- doesFileExist $ fst (darcsLocation dir h) unless exist $ fail $ "error opening " ++ fst (darcsLocation dir h) compressed <- readSegment $ darcsLocation dir h let content = decompress compressed return $ if BLC.null compressed then [] else darcsParseDir content -- | Read in a darcs-style hashed tree. This is mainly useful for reading -- \"pristine.hashed\". You need to provide the root hash you are interested in -- (found in _darcs/hashed_inventory). readDarcsHashed' :: Bool -> FilePath -> (Maybe Int, Hash) -> IO (Tree IO) readDarcsHashed' _ _ (_, NoHash) = fail "Cannot readDarcsHashed NoHash" readDarcsHashed' sizefail dir root@(_, hash) = do items' <- readDarcsHashedDir dir root subs <- sequence [ do when (sizefail && isJust s) $ fail ("Unexpectedly encountered size-prefixed hash in " ++ dir) case tp of BlobType -> return (d, File $ Blob (readBlob' (s, h)) h) TreeType -> do let t = readDarcsHashed dir (s, h) return (d, Stub t h) | (tp, d, s, h) <- items' ] return $ makeTreeWithHash subs hash where readBlob' = fmap decompress . readSegment . darcsLocation dir readDarcsHashed :: FilePath -> (Maybe Int, Hash) -> IO (Tree IO) readDarcsHashed = readDarcsHashed' False readDarcsHashedNosize :: FilePath -> Hash -> IO (Tree IO) readDarcsHashedNosize dir hash = readDarcsHashed' True dir (Nothing, hash) ---------------------------------------------------- -- Writing darcs-style hashed trees. -- -- | Write a Tree into a darcs-style hashed directory. writeDarcsHashed :: Tree IO -> FilePath -> IO Hash writeDarcsHashed tree' dir = do t <- darcsUpdateDirHashes <$> expand tree' sequence_ [ dump =<< readBlob b | (_, File b) <- list t ] let dirs = darcsFormatDir t : [ darcsFormatDir d | (_, SubTree d) <- list t ] _ <- mapM (dump . fromJust) dirs return $ darcsTreeHash t where dump bits = do let name = dir BC.unpack (encodeBase16 $ sha256 bits) exist <- doesFileExist name unless exist $ BL.writeFile name (compress bits) -- | Create a hashed file from a 'FilePath' and content. In case the file exists -- it is kept untouched and is assumed to have the right content. XXX Corrupt -- files should be probably renamed out of the way automatically or something -- (probably when they are being read though). fsCreateHashedFile :: FilePath -> BLC.ByteString -> TreeIO () fsCreateHashedFile fn content = liftIO $ do exist <- doesFileExist fn unless exist $ BL.writeFile fn content -- | Run a 'TreeIO' @action@ in a hashed setting. The @initial@ tree is assumed -- to be fully available from the @directory@, and any changes will be written -- out to same. Please note that actual filesystem files are never removed. hashedTreeIO :: TreeIO a -- ^ action -> Tree IO -- ^ initial -> FilePath -- ^ directory -> IO (a, Tree IO) hashedTreeIO action t dir = runTreeMonad action $ initialState t darcsHash updateItem where updateItem _ (File b) = File <$> updateFile b updateItem _ (SubTree s) = SubTree <$> updateSub s updateItem _ x = return x updateFile b@(Blob _ !h) = do content <- liftIO $ readBlob b let fn = dir BC.unpack (encodeBase16 h) nblob = Blob (decompress <$> rblob) h rblob = BL.fromChunks . return <$> B.readFile fn newcontent = compress content fsCreateHashedFile fn newcontent return nblob updateSub s = do let !hash = treeHash s Just dirdata = darcsFormatDir s fn = dir BC.unpack (encodeBase16 hash) fsCreateHashedFile fn (compress dirdata) return s darcs-2.14.5/src/Darcs/Util/Tree/Monad.hs0000644000000000000000000002650407346545000016130 0ustar0000000000000000-- Copyright (C) 2009-2011 Petr Rockai -- -- BSD3 {-# LANGUAGE ScopedTypeVariables, TypeSynonymInstances, UndecidableInstances #-} -- | An experimental monadic interface to Tree mutation. The main idea is to -- simulate IO-ish manipulation of real filesystem (that's the state part of -- the monad), and to keep memory usage down by reasonably often dumping the -- intermediate data to disk and forgetting it. The monad interface itself is -- generic, and a number of actual implementations can be used. This module -- provides just 'virtualTreeIO' that never writes any changes, but may trigger -- filesystem reads as appropriate. module Darcs.Util.Tree.Monad ( virtualTreeIO, virtualTreeMonad , readFile, writeFile, createDirectory, rename, copy, unlink , fileExists, directoryExists, exists, withDirectory , currentDirectory , tree, TreeState, TreeMonad, TreeIO, runTreeMonad , initialState, replaceItem , findM, findFileM, findTreeM , TreeRO, TreeRW ) where import Prelude hiding ( readFile, writeFile, (<$>) ) import Darcs.Util.Path import Darcs.Util.Tree import Control.Applicative( (<$>) ) import Control.Exception ( throw ) import Data.List( sortBy ) import Data.Int( Int64 ) import Data.Maybe( isNothing, isJust ) import qualified Data.ByteString.Lazy as BL import Control.Monad.RWS.Strict import qualified Data.Map as M type Changed = M.Map AnchoredPath (Int64, Int64) -- size, age -- | Internal state of the 'TreeIO' monad. Keeps track of the current Tree -- content, unsync'd changes and a current working directory (of the monad). data TreeState m = TreeState { tree :: !(Tree m) , changed :: !Changed , changesize :: !Int64 , maxage :: !Int64 , updateHash :: TreeItem m -> m Hash , update :: AnchoredPath -> TreeItem m -> TreeMonad m (TreeItem m) } -- | A 'TreeIO' monad. A sort of like IO but it keeps a 'TreeState' around as well, -- which is a sort of virtual filesystem. Depending on how you obtained your -- 'TreeIO', the actions in your virtual filesystem get somehow reflected in the -- actual real filesystem. For 'virtualTreeIO', nothing happens in real -- filesystem, however with 'plainTreeIO', the plain tree will be updated every -- now and then, and with 'hashedTreeIO' a darcs-style hashed tree will get -- updated. type TreeMonad m = RWST AnchoredPath () (TreeState m) m type TreeIO = TreeMonad IO class (Functor m, Monad m) => TreeRO m where currentDirectory :: m AnchoredPath withDirectory :: AnchoredPath -> m a -> m a expandTo :: AnchoredPath -> m AnchoredPath -- | Grab content of a file in the current Tree at the given path. readFile :: AnchoredPath -> m BL.ByteString -- | Check for existence of a node (file or directory, doesn't matter). exists :: AnchoredPath -> m Bool -- | Check for existence of a directory. directoryExists ::AnchoredPath -> m Bool -- | Check for existence of a file. fileExists :: AnchoredPath -> m Bool class TreeRO m => TreeRW m where -- | Change content of a file at a given path. The change will be -- eventually flushed to disk, but might be buffered for some time. writeFile :: AnchoredPath -> BL.ByteString -> m () createDirectory :: AnchoredPath -> m () unlink :: AnchoredPath -> m () rename :: AnchoredPath -> AnchoredPath -> m () copy :: AnchoredPath -> AnchoredPath -> m () initialState :: Tree m -> (TreeItem m -> m Hash) -> (AnchoredPath -> TreeItem m -> TreeMonad m (TreeItem m)) -> TreeState m initialState t uh u = TreeState { tree = t , changed = M.empty , changesize = 0 , updateHash = uh , maxage = 0 , update = u } flush :: (Monad m) => TreeMonad m () flush = do changed' <- map fst . M.toList <$> gets changed dirs' <- gets tree >>= \t -> return [ path | (path, SubTree _) <- list t ] modify $ \st -> st { changed = M.empty, changesize = 0 } forM_ (changed' ++ dirs' ++ [AnchoredPath []]) flushItem runTreeMonad' :: (Monad m) => TreeMonad m a -> TreeState m -> m (a, Tree m) runTreeMonad' action initial = do (out, final, _) <- runRWST action (AnchoredPath []) initial return (out, tree final) runTreeMonad :: (Monad m) => TreeMonad m a -> TreeState m -> m (a, Tree m) runTreeMonad action initial = do let action' = do x <- action flush return x runTreeMonad' action' initial -- | Run a TreeIO action without storing any changes. This is useful for -- running monadic tree mutations for obtaining the resulting Tree (as opposed -- to their effect of writing a modified tree to disk). The actions can do both -- read and write -- reads are passed through to the actual filesystem, but the -- writes are held in memory in a form of modified Tree. virtualTreeMonad :: (Monad m) => TreeMonad m a -> Tree m -> m (a, Tree m) virtualTreeMonad action t = runTreeMonad' action $ initialState t (\_ -> return NoHash) (\_ x -> return x) virtualTreeIO :: TreeIO a -> Tree IO -> IO (a, Tree IO) virtualTreeIO = virtualTreeMonad -- | Modifies an item in the current Tree. This action keeps an account of the -- modified data, in changed and changesize, for subsequent flush -- operations. Any modifications (as in "modifyTree") are allowed. modifyItem :: (Monad m) => AnchoredPath -> Maybe (TreeItem m) -> TreeMonad m () modifyItem path item = do path' <- (`catPaths` path) `fmap` currentDirectory age <- gets maxage changed' <- gets changed let getsize (Just (File b)) = lift (BL.length `fmap` readBlob b) getsize _ = return 0 size <- getsize item let change = case M.lookup path' changed' of Nothing -> size Just (oldsize, _) -> size - oldsize modify $ \st -> st { tree = modifyTree (tree st) path' item , changed = M.insert path' (size, age) (changed st) , maxage = age + 1 , changesize = changesize st + change } renameChanged :: (Monad m) => AnchoredPath -> AnchoredPath -> TreeMonad m () renameChanged from to = modify $ \st -> st { changed = rename' $ changed st } where rename' = M.fromList . map renameone . M.toList renameone (x, d) | from `isPrefix` x = (to `catPaths` relative from x, d) | otherwise = (x, d) relative (AnchoredPath from') (AnchoredPath x) = AnchoredPath $ drop (length from') x -- | Replace an item with a new version without modifying the content of the -- tree. This does not do any change tracking. Ought to be only used from a -- 'sync' implementation for a particular storage format. The presumed use-case -- is that an existing in-memory Blob is replaced with a one referring to an -- on-disk file. replaceItem :: (Monad m) => AnchoredPath -> Maybe (TreeItem m) -> TreeMonad m () replaceItem path item = do path' <- (`catPaths` path) `fmap` currentDirectory modify $ \st -> st { tree = modifyTree (tree st) path' item } flushItem :: forall m. (Monad m) => AnchoredPath -> TreeMonad m () flushItem path = do current <- gets tree case find current path of Nothing -> return () -- vanished, do nothing Just x -> do y <- fixHash x new <- gets update >>= ($ y) . ($ path) replaceItem path (Just new) where fixHash :: TreeItem m -> TreeMonad m (TreeItem m) fixHash f@(File (Blob con NoHash)) = do hash <- gets updateHash >>= \x -> lift $ x f return $ File $ Blob con hash fixHash (SubTree s) | treeHash s == NoHash = gets updateHash >>= \f -> SubTree <$> lift (addMissingHashes f s) fixHash x = return x -- | If buffers are becoming large, sync, otherwise do nothing. flushSome :: (Monad m) => TreeMonad m () flushSome = do x <- gets changesize when (x > megs 100) $ do remaining <- go =<< sortBy age . M.toList <$> gets changed modify $ \s -> s { changed = M.fromList remaining } where go [] = return [] go ((path, (size, _)):chs) = do x <- (\s -> s - size) <$> gets changesize flushItem path modify $ \s -> s { changesize = x } if x > megs 50 then go chs else return chs megs = (* (1024 * 1024)) age (_, (_, a)) (_, (_, b)) = compare a b instance (Monad m) => TreeRO (TreeMonad m) where expandTo p = do t <- gets tree p' <- (`catPaths` p) `fmap` ask t' <- lift $ expandPath t p' modify $ \st -> st { tree = t' } return p' fileExists p = do p' <- expandTo p (isJust . (`findFile` p')) `fmap` gets tree directoryExists p = do p' <- expandTo p (isJust . (`findTree` p')) `fmap` gets tree exists p = do p' <- expandTo p (isJust . (`find` p')) `fmap` gets tree readFile p = do p' <- expandTo p t <- gets tree let f = findFile t p' case f of Nothing -> throw $ userError $ "No such file " ++ show p' Just x -> lift (readBlob x) currentDirectory = ask withDirectory dir act = do dir' <- expandTo dir local (const dir') act instance (Monad m) => TreeRW (TreeMonad m) where writeFile p con = do _ <- expandTo p modifyItem p (Just blob) flushSome where blob = File $ Blob (return con) hash hash = NoHash -- we would like to say "sha256 con" here, but due -- to strictness of Hash in Blob, this would often -- lead to unnecessary computation which would then -- be discarded anyway; we rely on the sync -- implementation to fix up any NoHash occurrences createDirectory p = do _ <- expandTo p modifyItem p $ Just $ SubTree emptyTree unlink p = do _ <- expandTo p modifyItem p Nothing rename from to = do from' <- expandTo from to' <- expandTo to tr <- gets tree let item = find tr from' found_to = find tr to' unless (isNothing found_to) $ throw $ userError $ "Error renaming: destination " ++ show to ++ " exists." unless (isNothing item) $ do modifyItem from Nothing modifyItem to item renameChanged from to copy from to = do from' <- expandTo from _ <- expandTo to tr <- gets tree let item = find tr from' unless (isNothing item) $ modifyItem to item findM' :: forall m a . (Monad m) => (Tree m -> AnchoredPath -> a) -> Tree m -> AnchoredPath -> m a findM' what t path = fst <$> virtualTreeMonad (look path) t where look :: AnchoredPath -> TreeMonad m a look = expandTo >=> \p' -> flip what p' <$> gets tree findM :: (Monad m) => Tree m -> AnchoredPath -> m (Maybe (TreeItem m)) findM = findM' find findTreeM :: (Monad m) => Tree m -> AnchoredPath -> m (Maybe (Tree m)) findTreeM = findM' findTree findFileM :: (Monad m) => Tree m -> AnchoredPath -> m (Maybe (Blob m)) findFileM = findM' findFile darcs-2.14.5/src/Darcs/Util/Tree/Plain.hs0000644000000000000000000000610407346545000016127 0ustar0000000000000000-- Copyright (C) 2009-2011 Petr Rockai -- -- BSD3 -- | The plain format implementation resides in this module. The plain format -- does not use any hashing and basically just wraps a normal filesystem tree -- in the hashed-storage API. -- -- NB. The 'read' function on Blobs coming from a plain tree is susceptible to -- file content changes. Since we use mmap in 'read', this will break -- referential transparency and produce unexpected results. Please always make -- sure that all parallel access to the underlying filesystem tree never -- mutates files. Unlink + recreate is fine though (in other words, the -- 'writePlainTree' implemented in this module is safe in this respect). module Darcs.Util.Tree.Plain ( -- * Obtaining Trees. -- -- | Please note that Trees obtained this way will contain Stub -- items. These need to be executed (they are IO actions) in order to be -- accessed. Use 'expand' to do this. However, many operations are -- perfectly fine to be used on a stubbed Tree (and it is often more -- efficient to do everything that can be done before expanding a Tree). readPlainTree -- * Writing trees. , writePlainTree ) where import Data.Maybe( catMaybes ) import qualified Data.ByteString.Lazy as BL import System.FilePath( () ) import System.Directory( getDirectoryContents , createDirectoryIfMissing ) import System.Posix.Files ( getSymbolicLinkStatus, isDirectory, isRegularFile, FileStatus ) import Darcs.Util.Path import Darcs.Util.File ( withCurrentDirectory ) import Darcs.Util.ByteString ( readSegment ) import Darcs.Util.Hash( Hash( NoHash) ) import Darcs.Util.Tree( Tree(), TreeItem(..) , Blob(..), makeTree , list, readBlob, expand ) readPlainDir :: FilePath -> IO [(FilePath, FileStatus)] readPlainDir dir = withCurrentDirectory dir $ do items <- getDirectoryContents "." sequence [ do st <- getSymbolicLinkStatus s return (s, st) | s <- items, s `notElem` [ ".", ".." ] ] readPlainTree :: FilePath -> IO (Tree IO) readPlainTree dir = do items <- readPlainDir dir let subs = catMaybes [ let name = makeName name' in case status of _ | isDirectory status -> Just (name, Stub (readPlainTree (dir name')) NoHash) _ | isRegularFile status -> Just (name, File $ Blob (readBlob' name') NoHash) _ -> Nothing | (name', status) <- items ] return $ makeTree subs where readBlob' name = readSegment (dir name, Nothing) -- | Write out /full/ tree to a plain directory structure. If you instead want -- to make incremental updates, refer to "Darcs.Util.Tree.Monad". writePlainTree :: Tree IO -> FilePath -> IO () writePlainTree t dir = do createDirectoryIfMissing True dir expand t >>= mapM_ write . list where write (p, File b) = write' p b write (p, SubTree _) = createDirectoryIfMissing True (anchorPath dir p) write _ = return () write' p b = readBlob b >>= BL.writeFile (anchorPath dir p) darcs-2.14.5/src/Darcs/Util/URL.hs0000644000000000000000000001020107346545000014620 0ustar0000000000000000{- Copyright (C) 2004 David Roundy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -} {-| Path resolving: * An http URL contains the sequence @\"http(s):\/\/\"@. * A local filepath does not contain colons, except as second character (windows drives) when this filepath is meant to be used as repository name * A path that is neither an http URL nor a local file is an ssh-path. Examples: > /usr/repo/foo -- local file > c:/src/darcs -- local file > http://darcs.net/ -- URL > peter@host:/path -- ssh > droundy@host: -- ssh > host:/path -- ssh This means that single-letter hosts in ssh-paths do not work, unless a username is provided. Perhaps ssh-paths should use @\"ssh:\/\/user\@host\/path\"@-syntax instead? TODO: This whole module should be re-written using a regex matching library! The way we do this here is error-prone and inefficient. -} module Darcs.Util.URL ( isValidLocalPath, isHttpUrl, isSshUrl, isRelative, isAbsolute, isSshNopath, SshFilePath, sshRepo, sshUhost, sshFile, sshFilePathOf, splitSshUrl ) where import Prelude () import Darcs.Prelude import Darcs.Util.Global ( darcsdir ) import Data.List ( isPrefixOf, isInfixOf ) import Data.Char ( isSpace ) import qualified System.FilePath as FP ( isRelative, isAbsolute, isValid ) import System.FilePath ( () ) isRelative :: String -> Bool isRelative "" = bug "Empty filename in isRelative" isRelative f = FP.isRelative f isAbsolute :: String -> Bool isAbsolute "" = bug "isAbsolute called with empty filename" isAbsolute f = FP.isAbsolute f isValidLocalPath :: String -> Bool isValidLocalPath f@(_:_:fou) = ':' `notElem` fou && FP.isValid f isValidLocalPath f = FP.isValid f isHttpUrl :: String -> Bool isHttpUrl u = let u' = dropWhile isSpace u in ("http://" `isPrefixOf` u') || ("https://" `isPrefixOf` u') isSshUrl :: String -> Bool isSshUrl s = isu' (dropWhile isSpace s) where isu' s' | "ssh://" `isPrefixOf` s' = True | "://" `isInfixOf` s' = False | isValidLocalPath s' = False | otherwise = ":" `isInfixOf` s' isSshNopath :: String -> Bool isSshNopath s = case reverse s of ':':x@(_:_:_) -> ':' `notElem` x _ -> False -- | Given an ssh URL or file path, split it into -- user@host, repodir, and the file (with any _darcs/ prefix removed) splitSshUrl :: String -> SshFilePath splitSshUrl s | "ssh://" `isPrefixOf` s = let s' = drop (length "ssh://") $ dropWhile isSpace s (dir, file) = cleanrepodir '/' s' in SshFP { sshUhost = takeWhile (/= '/') s' , sshRepo = dir , sshFile = file } splitSshUrl s = let (dir, file) = cleanrepodir ':' s in SshFP { sshUhost = dropWhile isSpace $ takeWhile (/= ':') s , sshRepo = dir , sshFile = file } cleanrepourl :: String -> (String, String) cleanrepourl zzz | dd `isPrefixOf` zzz = ([], drop (length dd) zzz) where dd = darcsdir++"/" cleanrepourl (z:zs) = let (repo',file) = cleanrepourl zs in (z : repo', file) cleanrepourl "" = ([],[]) cleanrepodir :: Char -> String -> (String, String) cleanrepodir sep = cleanrepourl . drop 1 . dropWhile (/= sep) data SshFilePath = SshFP { sshUhost :: String , sshRepo :: String , sshFile :: String } sshFilePathOf :: SshFilePath -> String sshFilePathOf (SshFP uhost dir file) = uhost ++ ":" ++ (dir darcsdir file) darcs-2.14.5/src/Darcs/Util/Workaround.hs0000644000000000000000000000713607346545000016326 0ustar0000000000000000{-# LANGUAGE CPP #-} -- | -- Module : Darcs.Util.Workaround -- Copyright : 2008 David Roundy -- License : GPL -- Maintainer : darcs-devel@darcs.net -- Stability : experimental -- Portability : portable module Darcs.Util.Workaround ( renameFile , setExecutable , getCurrentDirectory , installHandler , raiseSignal , Handler(..) , Signal , sigINT , sigHUP , sigABRT , sigALRM , sigTERM , sigPIPE ) where import Prelude () import Darcs.Prelude #ifdef WIN32 import Control.Monad ( unless ) import qualified System.Directory ( renameFile, getCurrentDirectory, removeFile ) import Control.Exception ( catch, IOException ) import qualified Control.Exception ( mask ) import qualified System.IO.Error ( isDoesNotExistError, ioError ) #else import System.Posix.Signals(installHandler, raiseSignal, Handler(..), Signal, sigINT, sigHUP, sigABRT, sigALRM, sigTERM, sigPIPE) import System.Directory ( renameFile, getCurrentDirectory ) import System.Posix.Files (fileMode,getFileStatus, setFileMode, setFileCreationMask, ownerReadMode, ownerWriteMode, ownerExecuteMode, groupReadMode, groupWriteMode, groupExecuteMode, otherReadMode, otherWriteMode, otherExecuteMode) import Data.Bits ( (.&.), (.|.), complement ) #endif #ifdef WIN32 -- Dummy implementation of POSIX signals data Handler = Default | Ignore | Catch (IO ()) type Signal = Int installHandler :: Signal -> Handler -> Maybe () -> IO () installHandler _ _ _ = return () raiseSignal :: Signal -> IO () raiseSignal _ = return () sigINT :: Signal sigINT = 0 -- not used: sigKILL = 0 sigHUP :: Signal sigHUP = 0 -- not used: sigQUIT = 0 sigABRT :: Signal sigABRT = 0 sigTERM :: Signal sigTERM = 0 sigPIPE :: Signal sigPIPE = 0 sigALRM :: Signal sigALRM = 0 -- | System.Directory.renameFile incorrectly fails when the new file already -- exists. This code works around that bug at the cost of losing atomic -- writes. renameFile :: FilePath -> FilePath -> IO () renameFile old new = Control.Exception.mask $ \_ -> System.Directory.renameFile old new `catch` \(_ :: IOException) -> do System.Directory.removeFile new `catch` (\e -> unless (System.IO.Error.isDoesNotExistError e) $ System.IO.Error.ioError e) System.Directory.renameFile old new setExecutable :: FilePath -> Bool -> IO () setExecutable _ _ = return () -- | System.Directory.getCurrentDirectory returns a path with backslashes in it -- under windows, and some of the code gets confused by that, so we override -- getCurrentDirectory and translates '\\' to '/' getCurrentDirectory :: IO FilePath getCurrentDirectory = do d <- System.Directory.getCurrentDirectory return $ map rb d where rb '\\' = '/' rb c = c #else setExecutable :: FilePath -> Bool -> IO () setExecutable f ex = do st <- getFileStatus f umask <- setFileCreationMask 0 _ <- setFileCreationMask umask let rw = fileMode st .&. (ownerReadMode .|. ownerWriteMode .|. groupReadMode .|. groupWriteMode .|. otherReadMode .|. otherWriteMode) total = if ex then rw .|. ((ownerExecuteMode .|. groupExecuteMode .|. otherExecuteMode) .&. complement umask) else rw setFileMode f total #endif darcs-2.14.5/src/0000755000000000000000000000000007346545000011657 5ustar0000000000000000darcs-2.14.5/src/atomic_create.c0000644000000000000000000001125207346545000014623 0ustar0000000000000000/* Copyright (C) 2005 Juliusz Chroboczek This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #ifdef _WIN32 #include #include #endif int sloppy_atomic_create(const char *p) { int fd; fd = open(p, O_WRONLY | O_EXCL | O_CREAT, 0666); if(fd < 0) return -1; close(fd); return 1; } #ifdef _WIN32 int atomic_create(const char *p) { return sloppy_atomic_create(p); } #else static int careful_atomic_create(const char *p) { /* O_EXCL is not available over NFSv2, and even under NFSv3, it is broken on many systems. The following protocol is provably safe assuming that: - creation of hard links is atomic; - stat hits the server rather than working from the cache. */ static char hostname[65] = {'\0'}; int fd, rc, saved_errno; #define FILENAME_SIZE (11 + 15 + 8 + 1) char *filename; char *lastslash; int dirlen; struct timeval now; struct stat sb; if(hostname[0] == '\0') { char *c; int i; /* POSIX guarantees 65 is enough. */ rc = gethostname(hostname, 65); if(rc < 0 || rc >= 65) { fprintf(stderr, "Error reading hostname when locking.\n"); strcpy(hostname, "kremvax"); } c = strchr(hostname, '.'); if(c != NULL) *c = '\0'; hostname[15] = '\0'; /* clean up a few possible nasty characters folks might put in their hostname */ for (i=0;i<15;i++) if (hostname[i] == ':' || hostname[i] == '/' || hostname[i] == '\\') hostname[i] = '-'; } lastslash = strrchr(p, '/'); dirlen = lastslash ? lastslash - p + 1 : 0; filename = malloc(dirlen + FILENAME_SIZE); if(filename == NULL) return -1; if(dirlen > 0) memcpy(filename, p, dirlen); filename[dirlen] = '\0'; gettimeofday(&now, NULL); rc = snprintf(filename + dirlen, FILENAME_SIZE, "darcs_lock_%s%04x%04x", hostname, ((unsigned)getpid()) & 0xFFFF, ((unsigned)(now.tv_usec ^ (now.tv_usec >> 16))) & 0xFFFF); if(rc < 0 || rc >= FILENAME_SIZE) { fprintf(stderr, "Error writing to lock filename (%d)\n", rc < 0 ? errno : 0); goto fail2; } fd = open(filename, O_WRONLY | O_EXCL | O_CREAT, 0666); if(fd < 0) goto fail2; /* Paranoia: should cause the client to flush its metadata cache. */ rc = close(fd); if(rc < 0) { fprintf(stderr, "Error closing file %s. (%d)\n", filename, errno); goto fail; } rc = link(filename, p); if(rc >= 0) goto success; else if(errno == EPERM || errno == EOPNOTSUPP || errno == ENOSYS) { /* Linux returns EPERM when making hard links on filesystems that don't support them. */ /* It seems that MacOS returns EOPNOTSUPP on filesystems that don't support hard links. */ /* Linux using SSHFS returns ENOSYS for link(). */ unlink(filename); free(filename); return sloppy_atomic_create(p); } else if(errno != EEXIST && errno != EIO) goto fail; /* The link may still have been successful if we're running over UDP and got EEXIST or EIO. Check the file's link count. */ rc = stat(filename, &sb); if(rc < 0) { goto fail; } if(sb.st_nlink != 2) { errno = EEXIST; goto fail; } success: unlink(filename); free(filename); return 1; fail: saved_errno = errno; unlink(filename); errno = saved_errno; fail2: free(filename); return -1; } int atomic_create(const char *p) { static int sloppy = -1; if(sloppy < 0) { char *s = getenv("DARCS_SLOPPY_LOCKS"); sloppy = (s != NULL); } if(sloppy) return sloppy_atomic_create(p); else return careful_atomic_create(p); } #endif darcs-2.14.5/src/atomic_create.c0000755000000000000000000001125207346545000014626 0ustar0000000000000000/* Copyright (C) 2005 Juliusz Chroboczek This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #ifdef _WIN32 #include #include #endif int sloppy_atomic_create(const char *p) { int fd; fd = open(p, O_WRONLY | O_EXCL | O_CREAT, 0666); if(fd < 0) return -1; close(fd); return 1; } #ifdef _WIN32 int atomic_create(const char *p) { return sloppy_atomic_create(p); } #else static int careful_atomic_create(const char *p) { /* O_EXCL is not available over NFSv2, and even under NFSv3, it is broken on many systems. The following protocol is provably safe assuming that: - creation of hard links is atomic; - stat hits the server rather than working from the cache. */ static char hostname[65] = {'\0'}; int fd, rc, saved_errno; #define FILENAME_SIZE (11 + 15 + 8 + 1) char *filename; char *lastslash; int dirlen; struct timeval now; struct stat sb; if(hostname[0] == '\0') { char *c; int i; /* POSIX guarantees 65 is enough. */ rc = gethostname(hostname, 65); if(rc < 0 || rc >= 65) { fprintf(stderr, "Error reading hostname when locking.\n"); strcpy(hostname, "kremvax"); } c = strchr(hostname, '.'); if(c != NULL) *c = '\0'; hostname[15] = '\0'; /* clean up a few possible nasty characters folks might put in their hostname */ for (i=0;i<15;i++) if (hostname[i] == ':' || hostname[i] == '/' || hostname[i] == '\\') hostname[i] = '-'; } lastslash = strrchr(p, '/'); dirlen = lastslash ? lastslash - p + 1 : 0; filename = malloc(dirlen + FILENAME_SIZE); if(filename == NULL) return -1; if(dirlen > 0) memcpy(filename, p, dirlen); filename[dirlen] = '\0'; gettimeofday(&now, NULL); rc = snprintf(filename + dirlen, FILENAME_SIZE, "darcs_lock_%s%04x%04x", hostname, ((unsigned)getpid()) & 0xFFFF, ((unsigned)(now.tv_usec ^ (now.tv_usec >> 16))) & 0xFFFF); if(rc < 0 || rc >= FILENAME_SIZE) { fprintf(stderr, "Error writing to lock filename (%d)\n", rc < 0 ? errno : 0); goto fail2; } fd = open(filename, O_WRONLY | O_EXCL | O_CREAT, 0666); if(fd < 0) goto fail2; /* Paranoia: should cause the client to flush its metadata cache. */ rc = close(fd); if(rc < 0) { fprintf(stderr, "Error closing file %s. (%d)\n", filename, errno); goto fail; } rc = link(filename, p); if(rc >= 0) goto success; else if(errno == EPERM || errno == EOPNOTSUPP || errno == ENOSYS) { /* Linux returns EPERM when making hard links on filesystems that don't support them. */ /* It seems that MacOS returns EOPNOTSUPP on filesystems that don't support hard links. */ /* Linux using SSHFS returns ENOSYS for link(). */ unlink(filename); free(filename); return sloppy_atomic_create(p); } else if(errno != EEXIST && errno != EIO) goto fail; /* The link may still have been successful if we're running over UDP and got EEXIST or EIO. Check the file's link count. */ rc = stat(filename, &sb); if(rc < 0) { goto fail; } if(sb.st_nlink != 2) { errno = EEXIST; goto fail; } success: unlink(filename); free(filename); return 1; fail: saved_errno = errno; unlink(filename); errno = saved_errno; fail2: free(filename); return -1; } int atomic_create(const char *p) { static int sloppy = -1; if(sloppy < 0) { char *s = getenv("DARCS_SLOPPY_LOCKS"); sloppy = (s != NULL); } if(sloppy) return sloppy_atomic_create(p); else return careful_atomic_create(p); } #endif darcs-2.14.5/src/atomic_create.h0000755000000000000000000000053707346545000014637 0ustar0000000000000000 #include #include #include int sloppy_atomic_create(const char *p); int atomic_create(const char *p); #ifdef _WIN32 int mkstemp(char *p); int pipe( int fildes[2] ); int renamefile(const char *from, const char *to); #endif int stdout_is_a_pipe(); int maybe_relink(const char *src, const char *dst, int careful); darcs-2.14.5/src/hscurl.c0000644000000000000000000002212307346545000013323 0ustar0000000000000000#include "hscurl.h" #include #include #include #include #include #if LIBCURL_VERSION_NUM >= 0x071301 /* enable pipelining for libcurl >= 7.19.1 */ #define ENABLE_PIPELINING #endif enum RESULT_CODES { RESULT_OK = 0, RESULT_MALLOC_FAIL, RESULT_SELECT_FAIL, RESULT_MULTI_INIT_FAIL, RESULT_EASY_INIT_FAIL, RESULT_SLIST_APPEND_FAIL, RESULT_MULTI_INFO_READ_FAIL, RESULT_UNKNOWN_MESSAGE, RESULT_FILE_OPEN_FAIL }; static const char *error_strings[] = { "", "malloc() failed", "select() failed", "curl_multi_init() failed", "curl_easy_init() failed", "curl_slist_append() failed", "curl_multi_info_read() failed", "curl_multi_info_read() returned unknown message", "fopen() failed" }; struct UrlData { char *url; FILE *file; struct curl_slist *headers; }; static int debug = 0; #ifndef _WIN32 static const char user_agent[] = "darcs/" PACKAGE_VERSION " libcurl/" LIBCURL_VERSION; #else static const char user_agent[] = "darcs/unknown libcurl/" LIBCURL_VERSION; #endif static const char *proxypass; static int init_done = 0; static CURLM *multi = NULL; static int msgs_in_queue = 0; static char *last_url = NULL; static const char *perform() { int error; int running_handles, running_handles_last; fd_set fd_read, fd_write, fd_except; int max_fd; long timeout; struct timeval tval; error = curl_multi_perform(multi, &running_handles); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); running_handles_last = running_handles; while (running_handles_last > 0) { while (error == CURLM_CALL_MULTI_PERFORM) error = curl_multi_perform(multi, &running_handles); if (error != CURLM_OK) return curl_multi_strerror(error); if (running_handles < running_handles_last) break; FD_ZERO(&fd_read); FD_ZERO(&fd_write); FD_ZERO(&fd_except); error = curl_multi_fdset(multi, &fd_read, &fd_write, &fd_except, &max_fd); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); #ifdef CURL_MULTI_TIMEOUT error = curl_multi_timeout(multi, &timeout); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); if (timeout == -1) #endif timeout = 100; tval.tv_sec = timeout / 1000; tval.tv_usec = timeout % 1000 * 1000; while (select(max_fd + 1, &fd_read, &fd_write, &fd_except, &tval) < 0) if (errno != EINTR) { if (debug) perror(error_strings[RESULT_SELECT_FAIL]); return error_strings[RESULT_SELECT_FAIL]; } error = CURLM_CALL_MULTI_PERFORM; } return NULL; } const char *curl_request_url(const char *url, const char *filename, int cache_time, int* errorCode) { int error; *errorCode = -1; if (init_done == 0) { error = curl_global_init(CURL_GLOBAL_ALL); if (error != CURLE_OK) return curl_easy_strerror(error); proxypass = getenv("DARCS_PROXYUSERPWD"); init_done = 1; } if (multi == NULL) { multi = curl_multi_init(); if (multi == NULL) return error_strings[RESULT_MULTI_INIT_FAIL]; #ifdef ENABLE_PIPELINING error = curl_multi_setopt(multi, CURLMOPT_PIPELINING, 1); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); #endif } CURL *easy = curl_easy_init(); if (easy == NULL) return error_strings[RESULT_EASY_INIT_FAIL]; if (debug) { error = curl_easy_setopt(easy, CURLOPT_VERBOSE, 1); if (error != CURLE_OK) return curl_easy_strerror(error); } struct UrlData *url_data = malloc(sizeof(struct UrlData)); if (url_data == NULL) return error_strings[RESULT_MALLOC_FAIL]; url_data->url = strdup(url); if (url_data->url == NULL) return error_strings[RESULT_MALLOC_FAIL]; url_data->file = fopen(filename,"wb"); if (url_data->file == NULL) { if (debug) perror(error_strings[RESULT_FILE_OPEN_FAIL]); return error_strings[RESULT_FILE_OPEN_FAIL]; } error = set_time_out(easy, errorCode); if (error != CURLE_OK ){ *errorCode = error; return curl_easy_strerror(error); } error = curl_easy_setopt(easy, CURLOPT_PRIVATE, url_data); if (error != CURLE_OK) return curl_easy_strerror(error); error = curl_easy_setopt(easy, CURLOPT_URL, url_data->url); if (error != CURLE_OK) return curl_easy_strerror(error); #ifdef CURLOPT_WRITEDATA error = curl_easy_setopt(easy, CURLOPT_WRITEDATA, url_data->file); #else error = curl_easy_setopt(easy, CURLOPT_FILE, url_data->file); #endif if (error != CURLE_OK) return curl_easy_strerror(error); error = curl_easy_setopt(easy, CURLOPT_USERAGENT, user_agent); if (error != CURLE_OK) return curl_easy_strerror(error); error = curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1); if (error != CURLE_OK) return curl_easy_strerror(error); error = curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1); if (error != CURLE_OK) return curl_easy_strerror(error); error = curl_easy_setopt(easy, CURLOPT_HTTPAUTH, CURLAUTH_ANY); if (error != CURLE_OK) return curl_easy_strerror(error); /* libcurl currently always sends Pragma: no-cache, but never Cache-Control, which is contradictory. We override both, just to be sure. */ url_data->headers = curl_slist_append(NULL, "Accept: */*"); if(cache_time == 0) { url_data->headers = curl_slist_append(url_data->headers, "Pragma: no-cache"); url_data->headers = curl_slist_append(url_data->headers, "Cache-Control: no-cache"); } else if(cache_time > 0) { /* This won't work well with HTTP/1.0 proxies. */ char buf[40]; snprintf(buf, sizeof(buf), "Cache-Control: max-age=%d", cache_time); buf[sizeof(buf) - 1] = '\n'; url_data->headers = curl_slist_append(url_data->headers, "Pragma:"); url_data->headers = curl_slist_append(url_data->headers, buf); } else { url_data->headers = curl_slist_append(url_data->headers, "Pragma:"); url_data->headers = curl_slist_append(url_data->headers, "Cache-Control:"); } if (url_data->headers == NULL) return error_strings[RESULT_SLIST_APPEND_FAIL]; error = curl_easy_setopt(easy, CURLOPT_HTTPHEADER, url_data->headers); if (error != CURLE_OK) return curl_easy_strerror(error); if (proxypass && *proxypass) { error = curl_easy_setopt(easy, CURLOPT_PROXYUSERPWD, proxypass); if (error != CURLE_OK) return curl_easy_strerror(error); } error = curl_multi_add_handle(multi, easy); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); return error_strings[RESULT_OK]; } const char *curl_wait_next_url(int* errorCode, long* httpErrorCode) { *errorCode = -1; *httpErrorCode = -1; if (last_url != NULL) { free(last_url); last_url = NULL; } if (msgs_in_queue == 0) { const char *error = perform(); if (error != NULL) return error; } CURLMsg *msg = curl_multi_info_read(multi, &msgs_in_queue); if (msg == NULL) return error_strings[RESULT_MULTI_INFO_READ_FAIL]; if (msg->msg == CURLMSG_DONE) { CURL *easy = msg->easy_handle; CURLcode result = msg->data.result; struct UrlData *url_data; int error = set_time_out(easy, errorCode); if (error != CURLE_OK ){ *errorCode = error; return curl_easy_strerror(error); } error = curl_easy_getinfo(easy, CURLINFO_PRIVATE, (char **)&url_data); if (error != CURLE_OK){ *errorCode = error; return curl_easy_strerror(error); } last_url = url_data->url; fclose(url_data->file); curl_slist_free_all(url_data->headers); free(url_data); error = curl_multi_remove_handle(multi, easy); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); curl_easy_cleanup(easy); if (result != CURLE_OK){ *errorCode = result; if (result == CURLE_HTTP_RETURNED_ERROR) curl_easy_getinfo(easy, CURLINFO_RESPONSE_CODE, httpErrorCode); return curl_easy_strerror(result); } } else return error_strings[RESULT_UNKNOWN_MESSAGE]; return error_strings[RESULT_OK]; } const char *curl_last_url() { return last_url != NULL ? last_url : ""; } void curl_enable_debug() { debug = 1; } int curl_pipelining_enabled() { #ifdef ENABLE_PIPELINING return 1; #else return 0; #endif } int set_time_out(CURL *handle, int* errorCode) { int error; long time_out = DEFAULT_CONNECTION_TIMEOUT; const char *stime_out; stime_out = getenv("DARCS_CONNECTION_TIMEOUT"); if (stime_out != NULL){ long result = atol (stime_out); if ( result > 0 ) time_out = result; else *errorCode = 90 ; } error = curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, time_out); return error; } darcs-2.14.5/src/hscurl.c0000755000000000000000000002212307346545000013326 0ustar0000000000000000#include "hscurl.h" #include #include #include #include #include #if LIBCURL_VERSION_NUM >= 0x071301 /* enable pipelining for libcurl >= 7.19.1 */ #define ENABLE_PIPELINING #endif enum RESULT_CODES { RESULT_OK = 0, RESULT_MALLOC_FAIL, RESULT_SELECT_FAIL, RESULT_MULTI_INIT_FAIL, RESULT_EASY_INIT_FAIL, RESULT_SLIST_APPEND_FAIL, RESULT_MULTI_INFO_READ_FAIL, RESULT_UNKNOWN_MESSAGE, RESULT_FILE_OPEN_FAIL }; static const char *error_strings[] = { "", "malloc() failed", "select() failed", "curl_multi_init() failed", "curl_easy_init() failed", "curl_slist_append() failed", "curl_multi_info_read() failed", "curl_multi_info_read() returned unknown message", "fopen() failed" }; struct UrlData { char *url; FILE *file; struct curl_slist *headers; }; static int debug = 0; #ifndef _WIN32 static const char user_agent[] = "darcs/" PACKAGE_VERSION " libcurl/" LIBCURL_VERSION; #else static const char user_agent[] = "darcs/unknown libcurl/" LIBCURL_VERSION; #endif static const char *proxypass; static int init_done = 0; static CURLM *multi = NULL; static int msgs_in_queue = 0; static char *last_url = NULL; static const char *perform() { int error; int running_handles, running_handles_last; fd_set fd_read, fd_write, fd_except; int max_fd; long timeout; struct timeval tval; error = curl_multi_perform(multi, &running_handles); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); running_handles_last = running_handles; while (running_handles_last > 0) { while (error == CURLM_CALL_MULTI_PERFORM) error = curl_multi_perform(multi, &running_handles); if (error != CURLM_OK) return curl_multi_strerror(error); if (running_handles < running_handles_last) break; FD_ZERO(&fd_read); FD_ZERO(&fd_write); FD_ZERO(&fd_except); error = curl_multi_fdset(multi, &fd_read, &fd_write, &fd_except, &max_fd); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); #ifdef CURL_MULTI_TIMEOUT error = curl_multi_timeout(multi, &timeout); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); if (timeout == -1) #endif timeout = 100; tval.tv_sec = timeout / 1000; tval.tv_usec = timeout % 1000 * 1000; while (select(max_fd + 1, &fd_read, &fd_write, &fd_except, &tval) < 0) if (errno != EINTR) { if (debug) perror(error_strings[RESULT_SELECT_FAIL]); return error_strings[RESULT_SELECT_FAIL]; } error = CURLM_CALL_MULTI_PERFORM; } return NULL; } const char *curl_request_url(const char *url, const char *filename, int cache_time, int* errorCode) { int error; *errorCode = -1; if (init_done == 0) { error = curl_global_init(CURL_GLOBAL_ALL); if (error != CURLE_OK) return curl_easy_strerror(error); proxypass = getenv("DARCS_PROXYUSERPWD"); init_done = 1; } if (multi == NULL) { multi = curl_multi_init(); if (multi == NULL) return error_strings[RESULT_MULTI_INIT_FAIL]; #ifdef ENABLE_PIPELINING error = curl_multi_setopt(multi, CURLMOPT_PIPELINING, 1); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); #endif } CURL *easy = curl_easy_init(); if (easy == NULL) return error_strings[RESULT_EASY_INIT_FAIL]; if (debug) { error = curl_easy_setopt(easy, CURLOPT_VERBOSE, 1); if (error != CURLE_OK) return curl_easy_strerror(error); } struct UrlData *url_data = malloc(sizeof(struct UrlData)); if (url_data == NULL) return error_strings[RESULT_MALLOC_FAIL]; url_data->url = strdup(url); if (url_data->url == NULL) return error_strings[RESULT_MALLOC_FAIL]; url_data->file = fopen(filename,"wb"); if (url_data->file == NULL) { if (debug) perror(error_strings[RESULT_FILE_OPEN_FAIL]); return error_strings[RESULT_FILE_OPEN_FAIL]; } error = set_time_out(easy, errorCode); if (error != CURLE_OK ){ *errorCode = error; return curl_easy_strerror(error); } error = curl_easy_setopt(easy, CURLOPT_PRIVATE, url_data); if (error != CURLE_OK) return curl_easy_strerror(error); error = curl_easy_setopt(easy, CURLOPT_URL, url_data->url); if (error != CURLE_OK) return curl_easy_strerror(error); #ifdef CURLOPT_WRITEDATA error = curl_easy_setopt(easy, CURLOPT_WRITEDATA, url_data->file); #else error = curl_easy_setopt(easy, CURLOPT_FILE, url_data->file); #endif if (error != CURLE_OK) return curl_easy_strerror(error); error = curl_easy_setopt(easy, CURLOPT_USERAGENT, user_agent); if (error != CURLE_OK) return curl_easy_strerror(error); error = curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1); if (error != CURLE_OK) return curl_easy_strerror(error); error = curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1); if (error != CURLE_OK) return curl_easy_strerror(error); error = curl_easy_setopt(easy, CURLOPT_HTTPAUTH, CURLAUTH_ANY); if (error != CURLE_OK) return curl_easy_strerror(error); /* libcurl currently always sends Pragma: no-cache, but never Cache-Control, which is contradictory. We override both, just to be sure. */ url_data->headers = curl_slist_append(NULL, "Accept: */*"); if(cache_time == 0) { url_data->headers = curl_slist_append(url_data->headers, "Pragma: no-cache"); url_data->headers = curl_slist_append(url_data->headers, "Cache-Control: no-cache"); } else if(cache_time > 0) { /* This won't work well with HTTP/1.0 proxies. */ char buf[40]; snprintf(buf, sizeof(buf), "Cache-Control: max-age=%d", cache_time); buf[sizeof(buf) - 1] = '\n'; url_data->headers = curl_slist_append(url_data->headers, "Pragma:"); url_data->headers = curl_slist_append(url_data->headers, buf); } else { url_data->headers = curl_slist_append(url_data->headers, "Pragma:"); url_data->headers = curl_slist_append(url_data->headers, "Cache-Control:"); } if (url_data->headers == NULL) return error_strings[RESULT_SLIST_APPEND_FAIL]; error = curl_easy_setopt(easy, CURLOPT_HTTPHEADER, url_data->headers); if (error != CURLE_OK) return curl_easy_strerror(error); if (proxypass && *proxypass) { error = curl_easy_setopt(easy, CURLOPT_PROXYUSERPWD, proxypass); if (error != CURLE_OK) return curl_easy_strerror(error); } error = curl_multi_add_handle(multi, easy); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); return error_strings[RESULT_OK]; } const char *curl_wait_next_url(int* errorCode, long* httpErrorCode) { *errorCode = -1; *httpErrorCode = -1; if (last_url != NULL) { free(last_url); last_url = NULL; } if (msgs_in_queue == 0) { const char *error = perform(); if (error != NULL) return error; } CURLMsg *msg = curl_multi_info_read(multi, &msgs_in_queue); if (msg == NULL) return error_strings[RESULT_MULTI_INFO_READ_FAIL]; if (msg->msg == CURLMSG_DONE) { CURL *easy = msg->easy_handle; CURLcode result = msg->data.result; struct UrlData *url_data; int error = set_time_out(easy, errorCode); if (error != CURLE_OK ){ *errorCode = error; return curl_easy_strerror(error); } error = curl_easy_getinfo(easy, CURLINFO_PRIVATE, (char **)&url_data); if (error != CURLE_OK){ *errorCode = error; return curl_easy_strerror(error); } last_url = url_data->url; fclose(url_data->file); curl_slist_free_all(url_data->headers); free(url_data); error = curl_multi_remove_handle(multi, easy); if (error != CURLM_OK && error != CURLM_CALL_MULTI_PERFORM) return curl_multi_strerror(error); curl_easy_cleanup(easy); if (result != CURLE_OK){ *errorCode = result; if (result == CURLE_HTTP_RETURNED_ERROR) curl_easy_getinfo(easy, CURLINFO_RESPONSE_CODE, httpErrorCode); return curl_easy_strerror(result); } } else return error_strings[RESULT_UNKNOWN_MESSAGE]; return error_strings[RESULT_OK]; } const char *curl_last_url() { return last_url != NULL ? last_url : ""; } void curl_enable_debug() { debug = 1; } int curl_pipelining_enabled() { #ifdef ENABLE_PIPELINING return 1; #else return 0; #endif } int set_time_out(CURL *handle, int* errorCode) { int error; long time_out = DEFAULT_CONNECTION_TIMEOUT; const char *stime_out; stime_out = getenv("DARCS_CONNECTION_TIMEOUT"); if (stime_out != NULL){ long result = atol (stime_out); if ( result > 0 ) time_out = result; else *errorCode = 90 ; } error = curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, time_out); return error; } darcs-2.14.5/src/hscurl.h0000755000000000000000000000062707346545000013340 0ustar0000000000000000#define DEFAULT_CONNECTION_TIMEOUT 30 const char *curl_request_url(const char *url, const char *filename, int cache_time, int *errorCode); const char *curl_wait_next_url(int *errorCode, long* httpErrorCode); const char *curl_last_url(); void curl_enable_debug(); int curl_pipelining_enabled(); int set_time_out(); darcs-2.14.5/src/maybe_relink.c0000644000000000000000000001165607346545000014475 0ustar0000000000000000/* Copyright (C) 2005 Juliusz Chroboczek This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #ifdef _WIN32 int maybe_relink(const char *src, const char *dst, int careful) { return 0; } #else /* Tries to link src to dst if both files exist and have the same contents. If careful is false only the file sizes are compared; if it is true, the full contents are compared. This code assumes that dst cannot change behind our back -- the caller is supposed to protect it by a lock. On the other hand, it does handle simultaneous access to src, but only if src is never modified in place. It should also be safe over NFS. Assumes that rename cannot fail mid-way on a single filesystem. Returns 1 on success, 0 if the files are already linked, -1 for an error in errno, -2 if the files cannot be linked because they are not the same, on different devices, or on a filesystem with no support for hard links, -3 if there was a race condition, -4 if something unexpected happened. */ int maybe_relink(char *src, char *dst, int careful) { #define RELINK_BUFFER_SIZE 8192 int len, rc, saved_errno; char *tempname; struct stat srcstat, dststat, tempstat; struct timeval now; rc = stat(src, &srcstat); if(rc < 0) { if(errno == ENOENT) return -2; else return -1; } rc = stat(dst, &dststat); if(rc < 0) return -1; if(!S_ISREG(srcstat.st_mode) || !S_ISREG(dststat.st_mode)) { return -4; } if(srcstat.st_dev != dststat.st_dev) { return -2; } if(srcstat.st_ino == dststat.st_ino) /* Files are already linked */ return 0; if(srcstat.st_size != dststat.st_size) return -2; /* link is atomic even on NFS, we will fail gracefully if the name is not unique. */ gettimeofday(&now, NULL); rc = strlen(dst) + 6; tempname = malloc(rc); if(tempname == NULL) return -1; len = snprintf(tempname, rc, "%s-%04x", dst, ((unsigned)(now.tv_usec ^ (now.tv_usec >> 16))) & 0xFFFF); if(len < 0 || len >= rc) { free(tempname); return -4; } rc = link(src, tempname); if(rc < 0) { /* We need to try to remove the link in case this was a problem with NFS over an unreliable transport. */ goto fail; } rc = stat(tempname, &tempstat); if(rc < 0) goto fail; /* Check for a race condition. The size and mtime checks are gratuitious, but they don't cost much, and might save your data if you're on a filesystem without i-nodes. */ if(tempstat.st_ino != srcstat.st_ino || tempstat.st_size != srcstat.st_size || tempstat.st_mtime != srcstat.st_mtime) { unlink(tempname); free(tempname); return -3; } if(careful) { int fd1, fd2, i, rc1, rc2; char buf1[RELINK_BUFFER_SIZE], buf2[RELINK_BUFFER_SIZE]; fd1 = open(tempname, O_RDONLY); if(fd1 < 0) goto fail; fd2 = open(dst, O_RDONLY); if(fd2 < 0) { close(fd1); goto fail; } i = 0; /* This comparison is approximate: it doesn't deal with short reads and EINTR. It's okay, as these cases are rare and if they happen, we're still safe. */ while(i < tempstat.st_size) { rc1 = read(fd1, buf1, RELINK_BUFFER_SIZE); if(rc1 < 0) { close(fd1); close(fd2); goto fail; } rc2 = read(fd2, buf2, RELINK_BUFFER_SIZE); if(rc2 < 0) { close(fd1); close(fd2); goto fail; } if(rc1 == 0 || rc1 != rc2 || memcmp(buf1, buf2, rc1) != 0) { close(fd1); close(fd2); unlink(tempname); free(tempname); return -2; } i += rc1; } close(fd1); close(fd2); } rc = rename(tempname, dst); if(rc < 0) goto fail; free(tempname); return 1; fail: saved_errno = errno; unlink(tempname); free(tempname); errno = saved_errno; if(errno == EPERM || errno == EOPNOTSUPP) return -2; return -1; #undef RELINK_BUFFER_SIZE } #endif darcs-2.14.5/src/maybe_relink.c0000755000000000000000000001165607346545000014500 0ustar0000000000000000/* Copyright (C) 2005 Juliusz Chroboczek This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #ifdef _WIN32 int maybe_relink(const char *src, const char *dst, int careful) { return 0; } #else /* Tries to link src to dst if both files exist and have the same contents. If careful is false only the file sizes are compared; if it is true, the full contents are compared. This code assumes that dst cannot change behind our back -- the caller is supposed to protect it by a lock. On the other hand, it does handle simultaneous access to src, but only if src is never modified in place. It should also be safe over NFS. Assumes that rename cannot fail mid-way on a single filesystem. Returns 1 on success, 0 if the files are already linked, -1 for an error in errno, -2 if the files cannot be linked because they are not the same, on different devices, or on a filesystem with no support for hard links, -3 if there was a race condition, -4 if something unexpected happened. */ int maybe_relink(char *src, char *dst, int careful) { #define RELINK_BUFFER_SIZE 8192 int len, rc, saved_errno; char *tempname; struct stat srcstat, dststat, tempstat; struct timeval now; rc = stat(src, &srcstat); if(rc < 0) { if(errno == ENOENT) return -2; else return -1; } rc = stat(dst, &dststat); if(rc < 0) return -1; if(!S_ISREG(srcstat.st_mode) || !S_ISREG(dststat.st_mode)) { return -4; } if(srcstat.st_dev != dststat.st_dev) { return -2; } if(srcstat.st_ino == dststat.st_ino) /* Files are already linked */ return 0; if(srcstat.st_size != dststat.st_size) return -2; /* link is atomic even on NFS, we will fail gracefully if the name is not unique. */ gettimeofday(&now, NULL); rc = strlen(dst) + 6; tempname = malloc(rc); if(tempname == NULL) return -1; len = snprintf(tempname, rc, "%s-%04x", dst, ((unsigned)(now.tv_usec ^ (now.tv_usec >> 16))) & 0xFFFF); if(len < 0 || len >= rc) { free(tempname); return -4; } rc = link(src, tempname); if(rc < 0) { /* We need to try to remove the link in case this was a problem with NFS over an unreliable transport. */ goto fail; } rc = stat(tempname, &tempstat); if(rc < 0) goto fail; /* Check for a race condition. The size and mtime checks are gratuitious, but they don't cost much, and might save your data if you're on a filesystem without i-nodes. */ if(tempstat.st_ino != srcstat.st_ino || tempstat.st_size != srcstat.st_size || tempstat.st_mtime != srcstat.st_mtime) { unlink(tempname); free(tempname); return -3; } if(careful) { int fd1, fd2, i, rc1, rc2; char buf1[RELINK_BUFFER_SIZE], buf2[RELINK_BUFFER_SIZE]; fd1 = open(tempname, O_RDONLY); if(fd1 < 0) goto fail; fd2 = open(dst, O_RDONLY); if(fd2 < 0) { close(fd1); goto fail; } i = 0; /* This comparison is approximate: it doesn't deal with short reads and EINTR. It's okay, as these cases are rare and if they happen, we're still safe. */ while(i < tempstat.st_size) { rc1 = read(fd1, buf1, RELINK_BUFFER_SIZE); if(rc1 < 0) { close(fd1); close(fd2); goto fail; } rc2 = read(fd2, buf2, RELINK_BUFFER_SIZE); if(rc2 < 0) { close(fd1); close(fd2); goto fail; } if(rc1 == 0 || rc1 != rc2 || memcmp(buf1, buf2, rc1) != 0) { close(fd1); close(fd2); unlink(tempname); free(tempname); return -2; } i += rc1; } close(fd1); close(fd2); } rc = rename(tempname, dst); if(rc < 0) goto fail; free(tempname); return 1; fail: saved_errno = errno; unlink(tempname); free(tempname); errno = saved_errno; if(errno == EPERM || errno == EOPNOTSUPP) return -2; return -1; #undef RELINK_BUFFER_SIZE } #endif darcs-2.14.5/src/maybe_relink.h0000755000000000000000000000010107346545000014464 0ustar0000000000000000int maybe_relink(const char *src, const char *dst, int careful); darcs-2.14.5/src/system_encoding.c0000644000000000000000000000024007346545000015211 0ustar0000000000000000#include "system_encoding.h" char* get_system_encoding() { #ifdef WIN32 return "utf8"; #else setlocale(LC_ALL,""); return nl_langinfo(CODESET); #endif } darcs-2.14.5/src/system_encoding.c0000755000000000000000000000024007346545000015214 0ustar0000000000000000#include "system_encoding.h" char* get_system_encoding() { #ifdef WIN32 return "utf8"; #else setlocale(LC_ALL,""); return nl_langinfo(CODESET); #endif } darcs-2.14.5/src/system_encoding.h0000755000000000000000000000023607346545000015226 0ustar0000000000000000#ifndef __SYSTEM_ENCODING__ #define __SYSTEM_ENCODING__ #ifndef WIN32 #include #include #endif char* get_system_encoding(); #endif darcs-2.14.5/src/umask.c0000644000000000000000000000115007346545000013140 0ustar0000000000000000#include #include #include #include #include "umask.h" int set_umask(char *mask_string) { #ifndef WIN32 int rc; unsigned mask; char *end; mask = strtoul(mask_string, &end, 8); if(!end || *end != '\0') { errno = EINVAL; return -1; } rc = umask(mask); return rc; #else /* umask() has no useful meaning on win32. */ return 0; #endif /* #ifndef WIN32 ... else ... */ } int reset_umask(int old_mask) { #ifndef WIN32 umask(old_mask); return 1; #else return 0; #endif /* #ifndef WIN32 ... else ... */ } darcs-2.14.5/src/umask.c0000755000000000000000000000115007346545000013143 0ustar0000000000000000#include #include #include #include #include "umask.h" int set_umask(char *mask_string) { #ifndef WIN32 int rc; unsigned mask; char *end; mask = strtoul(mask_string, &end, 8); if(!end || *end != '\0') { errno = EINVAL; return -1; } rc = umask(mask); return rc; #else /* umask() has no useful meaning on win32. */ return 0; #endif /* #ifndef WIN32 ... else ... */ } int reset_umask(int old_mask) { #ifndef WIN32 umask(old_mask); return 1; #else return 0; #endif /* #ifndef WIN32 ... else ... */ } darcs-2.14.5/src/umask.h0000755000000000000000000000010107346545000013143 0ustar0000000000000000int set_umask(char *mask_string); int reset_umask(int old_mask); darcs-2.14.5/src/win32/Darcs/Util/0000755000000000000000000000000007346545000014572 5ustar0000000000000000darcs-2.14.5/src/win32/Darcs/Util/CtrlC.hs0000644000000000000000000000113107346545000016131 0ustar0000000000000000{-# LANGUAGE ForeignFunctionInterface #-} module Darcs.Util.CtrlC ( withCtrlCHandler ) where import Data.Word ( Word32 ) import Foreign.Ptr ( FunPtr ) import Control.Exception ( bracket_ ) type Handler = Word32 -> IO Int foreign import ccall "wrapper" wrap :: Handler -> IO (FunPtr Handler) foreign import stdcall "SetConsoleCtrlHandler" setConsoleCtrlHandler :: FunPtr Handler -> Int -> IO () withCtrlCHandler :: IO () -> IO a -> IO a withCtrlCHandler handler m = do fp <- wrap (\_ctrlType -> handler >> return 1) bracket_ (setConsoleCtrlHandler fp 1) (setConsoleCtrlHandler fp 0) m darcs-2.14.5/src/win32/System/0000755000000000000000000000000007346545000014105 5ustar0000000000000000darcs-2.14.5/src/win32/System/Posix.hs0000644000000000000000000000045207346545000015544 0ustar0000000000000000{-# LANGUAGE ForeignFunctionInterface #-} module System.Posix ( sleep ) where import Foreign.C.Types ( CInt(..), CUInt(..), CULong(..) ) foreign import stdcall "winbase.h SleepEx" c_SleepEx :: CULong -> CUInt -> IO CInt sleep :: Integer -> IO CInt sleep n = c_SleepEx (1000 * fromIntegral n) 1 darcs-2.14.5/src/win32/System/Posix/0000755000000000000000000000000007346545000015207 5ustar0000000000000000darcs-2.14.5/src/win32/System/Posix/Files.hsc0000644000000000000000000000220007346545000016742 0ustar0000000000000000{-# LANGUAGE CPP, ForeignFunctionInterface #-} module System.Posix.Files ( isNamedPipe, isDirectory, isRegularFile, isSymbolicLink , getFdStatus, getFileStatus, getSymbolicLinkStatus , modificationTime, setFileMode, fileSize, fileMode , stdFileMode, FileStatus, fileID , linkCount, createLink ) where import System.PosixCompat.Files ( isNamedPipe, isDirectory, isRegularFile, isSymbolicLink , getFdStatus, getFileStatus, getSymbolicLinkStatus , modificationTime, setFileMode, fileSize, fileMode , stdFileMode, FileStatus, fileID ) import Foreign.C.String( CWString, withCWString ) import Foreign.C.Error( throwErrnoPathIf_ ) import Foreign.Ptr( Ptr, nullPtr ) import Foreign.C( CInt(..) ) linkCount :: FileStatus -> Int linkCount _ = 1 #define _WIN32_WINNT 0x0500 foreign import stdcall "winbase.h CreateHardLinkW" c_CreateHardLink :: CWString -> CWString -> Ptr a -> IO CInt createLink :: FilePath -> FilePath -> IO () createLink old new = withCWString old $ \c_old -> withCWString new $ \c_new -> throwErrnoPathIf_ (==0) "createLink" new $ c_CreateHardLink c_new c_old nullPtr darcs-2.14.5/src/win32/System/Posix/IO.hsc0000644000000000000000000000366607346545000016230 0ustar0000000000000000{-# LANGUAGE ForeignFunctionInterface #-} module System.Posix.IO where #if mingw32_HOST_OS import Foreign.C.String( withCWString ) #else import Foreign.C.String ( withCString ) #endif import Foreign.C.Error ( throwErrnoIfMinus1, throwErrnoIfMinus1_ ) import GHC.IO.Handle.FD ( fdToHandle ) import System.Posix.Internals ( c_open, c_close, c_dup2 ) import System.Posix.Types ( Fd(..), FileMode ) import System.IO ( Handle ) import Data.Bits ( (.|.) ) stdOutput :: Fd stdOutput = Fd 1 stdError :: Fd stdError = Fd 2 data OpenFileFlags = OpenFileFlags { append :: Bool, exclusive :: Bool, noctty :: Bool, nonBlock :: Bool, trunc :: Bool } -- Adapted from System.Posix.IO in ghc #include openFd :: FilePath -> OpenMode -> Maybe FileMode -> OpenFileFlags -> IO Fd openFd name how maybe_mode off = do #if mingw32_HOST_OS withCWString name $ \s -> do #else withCString name $ \s -> do #endif fd <- throwErrnoIfMinus1 "openFd" (c_open s all_flags mode_w) return (Fd fd) where all_flags = binary .|. creat .|. flags .|. open_mode flags = (if append off then (#const O_APPEND) else 0) .|. (if exclusive off then (#const O_EXCL) else 0) .|. (if trunc off then (#const O_TRUNC) else 0) binary = (#const O_BINARY) (creat, mode_w) = maybe (0,0) (\x->((#const O_CREAT),x)) maybe_mode open_mode = case how of ReadOnly -> (#const O_RDONLY) WriteOnly -> (#const O_WRONLY) ReadWrite -> (#const O_RDWR) closeFd :: Fd -> IO () closeFd (Fd fd) = throwErrnoIfMinus1_ "closeFd" (c_close fd) fdToHandle :: Fd -> IO Handle fdToHandle fd = GHC.IO.Handle.FD.fdToHandle (fromIntegral fd) dupTo :: Fd -> Fd -> IO Fd dupTo (Fd fd1) (Fd fd2) = do r <- throwErrnoIfMinus1 "dupTo" (c_dup2 fd1 fd2) return (Fd r) data OpenMode = ReadOnly | WriteOnly | ReadWrite defaultFileFlags :: OpenFileFlags defaultFileFlags = OpenFileFlags False False False False False darcs-2.14.5/src/win32/0000755000000000000000000000000007346545000012621 5ustar0000000000000000darcs-2.14.5/src/win32/send_email.c0000644000000000000000000002140007346545000015062 0ustar0000000000000000 #include #include #include #include "send_email.h" typedef struct sMapiFuns { LPMAPILOGON logon; LPMAPISENDMAIL sendmail; LPMAPIRESOLVENAME resolve; LPMAPIFREEBUFFER free_buf; LPMAPILOGOFF logoff; HMODULE dll; } MapiFuns; int load_dll(const char* name, MapiFuns* funs); void free_dll(MapiFuns* funs); void get_recipient(MapiFuns* funs, const char *name, ULONG recipClass, MapiRecipDesc *desc, lpMapiRecipDesc *desc_lookup); int send_email(const char *sendname, const char *recvname, const char *ccname, const char *subj, const char *body, const char *path) { FLAGS flags; MapiMessage msg; ULONG send_res; MapiRecipDesc orig; MapiRecipDesc recips[2]; MapiRecipDesc *orig_lookup, *recip_lookup, *cc_lookup; int num_recip = 1, return_code = -1; MapiFileDesc attachment; MapiFileTagExt file_type; const char *filename; char *attachment_path = 0; MapiFuns funs; if(load_dll("mapistub.dll", &funs) || load_dll("mapi32.dll", &funs)) { return_code=0; } else { fprintf(stderr, "Unable to load mapistub.dll or mapi32.dll: Bailing out. \n"); return_code=-1; } if(return_code==0) { LHANDLE session; /* logon seems to be necessary for outlook express, sometimes, and doesn't seem to hurt, otherwise. */ funs.logon(0, 0, 0, MAPI_LOGON_UI, 0, &session); orig_lookup = recip_lookup = cc_lookup = NULL; get_recipient(&funs, sendname, MAPI_ORIG, &orig, &orig_lookup); get_recipient(&funs, recvname, MAPI_TO, &recips[0], &recip_lookup); if (ccname && strlen(ccname) > 0) { get_recipient(&funs, ccname, MAPI_CC, &recips[1], &cc_lookup); num_recip++; } memset(&msg, 0, sizeof(msg)); msg.lpOriginator = &orig; msg.lpRecips = recips; msg.lpszMessageType = "text/plain"; msg.lpszNoteText = (LPSTR) body; msg.lpszSubject = (LPSTR)subj; msg.nRecipCount = num_recip; msg.flFlags = 0; if (path) { attachment_path = strdup(path); /* convert / to \ (thunderbird doesn't like /) */ char *p = attachment_path; while ((p = strchr(p, '/'))) *p = '\\'; /* find filename */ filename = strrchr(attachment_path, '\\'); if (filename == 0) filename = attachment_path; else filename++; memset(&attachment, 0, sizeof(attachment)); attachment.nPosition = -1; attachment.lpszPathName = (LPTSTR)attachment_path; attachment.lpszFileName = (LPTSTR)filename; attachment.lpFileType = &file_type; memset(&file_type, 0, sizeof(file_type)); file_type.lpTag = "text/plain"; file_type.cbTag = sizeof(file_type.lpTag); msg.nFileCount = 1; msg.lpFiles = &attachment; } flags = 0; send_res = funs.sendmail(0, 0, &msg, flags, 0); if (send_res == SUCCESS_SUCCESS) return_code = 0; else { return_code=-1; if(send_res==MAPI_E_USER_ABORT) fprintf(stderr, "MAPI error: User aborted.\n"); else if(send_res== MAPI_E_FAILURE) fprintf(stderr, "MAPI error: Generic error.\n"); else if(send_res== MAPI_E_LOGIN_FAILURE) fprintf(stderr, "MAPI error: Login failure.\n"); else if(send_res== MAPI_E_DISK_FULL) fprintf(stderr, "MAPI error: Disk full.\n"); else if(send_res== MAPI_E_INSUFFICIENT_MEMORY) fprintf(stderr, "MAPI error: Insufficient memory.\n"); else if(send_res== MAPI_E_ACCESS_DENIED) fprintf(stderr, "MAPI error: Access denied.\n"); else if(send_res== MAPI_E_TOO_MANY_SESSIONS) fprintf(stderr, "MAPI error: Too many sessions\n"); else if(send_res== MAPI_E_TOO_MANY_FILES) fprintf(stderr, "MAPI error: Too many files.\n"); else if(send_res== MAPI_E_TOO_MANY_RECIPIENTS) fprintf(stderr, "MAPI error: Too many recipients.\n"); else if(send_res== MAPI_E_ATTACHMENT_NOT_FOUND) fprintf(stderr, "MAPI error: Attachment not found.\n"); else if(send_res== MAPI_E_ATTACHMENT_OPEN_FAILURE) fprintf(stderr, "MAPI error: Failed to open attachment.\n"); else if(send_res== MAPI_E_ATTACHMENT_WRITE_FAILURE) fprintf(stderr, "MAPI error: Failed to write attachment.\n"); else if(send_res== MAPI_E_UNKNOWN_RECIPIENT) fprintf(stderr, "MAPI error: Unknown recipient\n"); else if(send_res== MAPI_E_BAD_RECIPTYPE) fprintf(stderr, "MAPI error: Bad type of recipent.\n"); else if(send_res== MAPI_E_NO_MESSAGES) fprintf(stderr, "MAPI error: No messages.\n"); else if(send_res== MAPI_E_INVALID_MESSAGE) fprintf(stderr, "MAPI error: Invalid message.\n"); else if(send_res== MAPI_E_TEXT_TOO_LARGE) fprintf(stderr, "MAPI error: Text too large.\n"); else if(send_res== MAPI_E_INVALID_SESSION) fprintf(stderr, "MAPI error: Invalid session.\n"); else if(send_res== MAPI_E_TYPE_NOT_SUPPORTED) fprintf(stderr, "MAPI error: Type not supported.\n"); else if(send_res== MAPI_E_AMBIGUOUS_RECIPIENT) fprintf(stderr, "MAPI error: Ambigious recipient.\n"); else if(send_res== MAPI_E_MESSAGE_IN_USE) fprintf(stderr, "MAPI error: Messag in use.\n"); else if(send_res== MAPI_E_NETWORK_FAILURE) fprintf(stderr, "MAPI error: Network failure.\n"); else if(send_res== MAPI_E_INVALID_EDITFIELDS) fprintf(stderr, "MAPI error: Invalid editfields\n"); else if(send_res== MAPI_E_INVALID_RECIPS) fprintf(stderr, "MAPI error: Invalid recipient(s)\n"); else if(send_res== MAPI_E_NOT_SUPPORTED) fprintf(stderr, "MAPI error: Operation not supported.\n"); else fprintf(stderr, "MAPISendMail returned %ld\n", send_res); } if (orig_lookup) funs.free_buf(orig_lookup); if (recip_lookup) funs.free_buf(recip_lookup); if (cc_lookup) funs.free_buf(cc_lookup); if (attachment_path) free(attachment_path); funs.logoff(session, 0, 0, 0); } free_dll(&funs); return return_code; } void get_recipient(MapiFuns* funs, const char *name, ULONG recipClass, MapiRecipDesc *desc, lpMapiRecipDesc *desc_lookup) { ULONG ret = funs->resolve(0, 0, (LPSTR) name, 0, 0, desc_lookup); if (ret == SUCCESS_SUCCESS) { memcpy(desc, *desc_lookup, sizeof(MapiRecipDesc)); } else { /* Default to something sensible if MAPIResolveName is not supported * by the mail client (thunderbird) */ memset(desc, 0, sizeof(MapiRecipDesc)); desc->lpszName = (LPSTR)name; desc->lpszAddress = (LPSTR)name; desc->lpEntryID = 0; desc->ulEIDSize = 0; } desc->ulRecipClass = recipClass; } int load_dll(const char* name, MapiFuns* funs) { funs->dll = 0; funs->dll = LoadLibrary(name); if(funs->dll!=NULL) { /* We try first loading by easy name, then by ordinal, and then by other names seen */ funs->logon = (LPMAPILOGON) GetProcAddress(funs->dll, "MAPILogon"); if(funs->logon==NULL) funs->logon = (LPMAPILOGON) GetProcAddress(funs->dll, (LPCSTR)209); funs->logoff = (LPMAPILOGOFF) GetProcAddress(funs->dll, "MAPILogOff"); if(funs->logoff==NULL) funs->logoff = (LPMAPILOGOFF) GetProcAddress(funs->dll, (LPCSTR)210); funs->resolve = (LPMAPIRESOLVENAME) GetProcAddress(funs->dll, "MAPIResolveName"); if(funs->resolve==NULL) funs->resolve = (LPMAPIRESOLVENAME) GetProcAddress(funs->dll, (LPCSTR)219); funs->free_buf = (LPMAPIFREEBUFFER) GetProcAddress(funs->dll, "MAPIFreeBuffer"); if(funs->free_buf==NULL) funs->free_buf = (LPMAPIFREEBUFFER) GetProcAddress(funs->dll, (LPCSTR)16); if(funs->free_buf==NULL) funs->free_buf = (LPMAPIFREEBUFFER) GetProcAddress(funs->dll, "MAPIFreeBuffer@4"); funs->sendmail = (LPMAPISENDMAIL) GetProcAddress(funs->dll, "MAPISendMail"); if(funs->sendmail==NULL) funs->sendmail = (LPMAPISENDMAIL) GetProcAddress(funs->dll, (LPCSTR)211); } return funs->dll!=NULL && funs->logon!=NULL && funs->logoff!=NULL && funs->resolve!=NULL && funs->free_buf!=NULL && funs->sendmail!=NULL; } void free_dll(MapiFuns* funs) { if(funs->dll!=NULL) FreeLibrary(funs->dll); funs->dll=NULL; } darcs-2.14.5/src/win32/send_email.c0000755000000000000000000002140007346545000015065 0ustar0000000000000000 #include #include #include #include "send_email.h" typedef struct sMapiFuns { LPMAPILOGON logon; LPMAPISENDMAIL sendmail; LPMAPIRESOLVENAME resolve; LPMAPIFREEBUFFER free_buf; LPMAPILOGOFF logoff; HMODULE dll; } MapiFuns; int load_dll(const char* name, MapiFuns* funs); void free_dll(MapiFuns* funs); void get_recipient(MapiFuns* funs, const char *name, ULONG recipClass, MapiRecipDesc *desc, lpMapiRecipDesc *desc_lookup); int send_email(const char *sendname, const char *recvname, const char *ccname, const char *subj, const char *body, const char *path) { FLAGS flags; MapiMessage msg; ULONG send_res; MapiRecipDesc orig; MapiRecipDesc recips[2]; MapiRecipDesc *orig_lookup, *recip_lookup, *cc_lookup; int num_recip = 1, return_code = -1; MapiFileDesc attachment; MapiFileTagExt file_type; const char *filename; char *attachment_path = 0; MapiFuns funs; if(load_dll("mapistub.dll", &funs) || load_dll("mapi32.dll", &funs)) { return_code=0; } else { fprintf(stderr, "Unable to load mapistub.dll or mapi32.dll: Bailing out. \n"); return_code=-1; } if(return_code==0) { LHANDLE session; /* logon seems to be necessary for outlook express, sometimes, and doesn't seem to hurt, otherwise. */ funs.logon(0, 0, 0, MAPI_LOGON_UI, 0, &session); orig_lookup = recip_lookup = cc_lookup = NULL; get_recipient(&funs, sendname, MAPI_ORIG, &orig, &orig_lookup); get_recipient(&funs, recvname, MAPI_TO, &recips[0], &recip_lookup); if (ccname && strlen(ccname) > 0) { get_recipient(&funs, ccname, MAPI_CC, &recips[1], &cc_lookup); num_recip++; } memset(&msg, 0, sizeof(msg)); msg.lpOriginator = &orig; msg.lpRecips = recips; msg.lpszMessageType = "text/plain"; msg.lpszNoteText = (LPSTR) body; msg.lpszSubject = (LPSTR)subj; msg.nRecipCount = num_recip; msg.flFlags = 0; if (path) { attachment_path = strdup(path); /* convert / to \ (thunderbird doesn't like /) */ char *p = attachment_path; while ((p = strchr(p, '/'))) *p = '\\'; /* find filename */ filename = strrchr(attachment_path, '\\'); if (filename == 0) filename = attachment_path; else filename++; memset(&attachment, 0, sizeof(attachment)); attachment.nPosition = -1; attachment.lpszPathName = (LPTSTR)attachment_path; attachment.lpszFileName = (LPTSTR)filename; attachment.lpFileType = &file_type; memset(&file_type, 0, sizeof(file_type)); file_type.lpTag = "text/plain"; file_type.cbTag = sizeof(file_type.lpTag); msg.nFileCount = 1; msg.lpFiles = &attachment; } flags = 0; send_res = funs.sendmail(0, 0, &msg, flags, 0); if (send_res == SUCCESS_SUCCESS) return_code = 0; else { return_code=-1; if(send_res==MAPI_E_USER_ABORT) fprintf(stderr, "MAPI error: User aborted.\n"); else if(send_res== MAPI_E_FAILURE) fprintf(stderr, "MAPI error: Generic error.\n"); else if(send_res== MAPI_E_LOGIN_FAILURE) fprintf(stderr, "MAPI error: Login failure.\n"); else if(send_res== MAPI_E_DISK_FULL) fprintf(stderr, "MAPI error: Disk full.\n"); else if(send_res== MAPI_E_INSUFFICIENT_MEMORY) fprintf(stderr, "MAPI error: Insufficient memory.\n"); else if(send_res== MAPI_E_ACCESS_DENIED) fprintf(stderr, "MAPI error: Access denied.\n"); else if(send_res== MAPI_E_TOO_MANY_SESSIONS) fprintf(stderr, "MAPI error: Too many sessions\n"); else if(send_res== MAPI_E_TOO_MANY_FILES) fprintf(stderr, "MAPI error: Too many files.\n"); else if(send_res== MAPI_E_TOO_MANY_RECIPIENTS) fprintf(stderr, "MAPI error: Too many recipients.\n"); else if(send_res== MAPI_E_ATTACHMENT_NOT_FOUND) fprintf(stderr, "MAPI error: Attachment not found.\n"); else if(send_res== MAPI_E_ATTACHMENT_OPEN_FAILURE) fprintf(stderr, "MAPI error: Failed to open attachment.\n"); else if(send_res== MAPI_E_ATTACHMENT_WRITE_FAILURE) fprintf(stderr, "MAPI error: Failed to write attachment.\n"); else if(send_res== MAPI_E_UNKNOWN_RECIPIENT) fprintf(stderr, "MAPI error: Unknown recipient\n"); else if(send_res== MAPI_E_BAD_RECIPTYPE) fprintf(stderr, "MAPI error: Bad type of recipent.\n"); else if(send_res== MAPI_E_NO_MESSAGES) fprintf(stderr, "MAPI error: No messages.\n"); else if(send_res== MAPI_E_INVALID_MESSAGE) fprintf(stderr, "MAPI error: Invalid message.\n"); else if(send_res== MAPI_E_TEXT_TOO_LARGE) fprintf(stderr, "MAPI error: Text too large.\n"); else if(send_res== MAPI_E_INVALID_SESSION) fprintf(stderr, "MAPI error: Invalid session.\n"); else if(send_res== MAPI_E_TYPE_NOT_SUPPORTED) fprintf(stderr, "MAPI error: Type not supported.\n"); else if(send_res== MAPI_E_AMBIGUOUS_RECIPIENT) fprintf(stderr, "MAPI error: Ambigious recipient.\n"); else if(send_res== MAPI_E_MESSAGE_IN_USE) fprintf(stderr, "MAPI error: Messag in use.\n"); else if(send_res== MAPI_E_NETWORK_FAILURE) fprintf(stderr, "MAPI error: Network failure.\n"); else if(send_res== MAPI_E_INVALID_EDITFIELDS) fprintf(stderr, "MAPI error: Invalid editfields\n"); else if(send_res== MAPI_E_INVALID_RECIPS) fprintf(stderr, "MAPI error: Invalid recipient(s)\n"); else if(send_res== MAPI_E_NOT_SUPPORTED) fprintf(stderr, "MAPI error: Operation not supported.\n"); else fprintf(stderr, "MAPISendMail returned %ld\n", send_res); } if (orig_lookup) funs.free_buf(orig_lookup); if (recip_lookup) funs.free_buf(recip_lookup); if (cc_lookup) funs.free_buf(cc_lookup); if (attachment_path) free(attachment_path); funs.logoff(session, 0, 0, 0); } free_dll(&funs); return return_code; } void get_recipient(MapiFuns* funs, const char *name, ULONG recipClass, MapiRecipDesc *desc, lpMapiRecipDesc *desc_lookup) { ULONG ret = funs->resolve(0, 0, (LPSTR) name, 0, 0, desc_lookup); if (ret == SUCCESS_SUCCESS) { memcpy(desc, *desc_lookup, sizeof(MapiRecipDesc)); } else { /* Default to something sensible if MAPIResolveName is not supported * by the mail client (thunderbird) */ memset(desc, 0, sizeof(MapiRecipDesc)); desc->lpszName = (LPSTR)name; desc->lpszAddress = (LPSTR)name; desc->lpEntryID = 0; desc->ulEIDSize = 0; } desc->ulRecipClass = recipClass; } int load_dll(const char* name, MapiFuns* funs) { funs->dll = 0; funs->dll = LoadLibrary(name); if(funs->dll!=NULL) { /* We try first loading by easy name, then by ordinal, and then by other names seen */ funs->logon = (LPMAPILOGON) GetProcAddress(funs->dll, "MAPILogon"); if(funs->logon==NULL) funs->logon = (LPMAPILOGON) GetProcAddress(funs->dll, (LPCSTR)209); funs->logoff = (LPMAPILOGOFF) GetProcAddress(funs->dll, "MAPILogOff"); if(funs->logoff==NULL) funs->logoff = (LPMAPILOGOFF) GetProcAddress(funs->dll, (LPCSTR)210); funs->resolve = (LPMAPIRESOLVENAME) GetProcAddress(funs->dll, "MAPIResolveName"); if(funs->resolve==NULL) funs->resolve = (LPMAPIRESOLVENAME) GetProcAddress(funs->dll, (LPCSTR)219); funs->free_buf = (LPMAPIFREEBUFFER) GetProcAddress(funs->dll, "MAPIFreeBuffer"); if(funs->free_buf==NULL) funs->free_buf = (LPMAPIFREEBUFFER) GetProcAddress(funs->dll, (LPCSTR)16); if(funs->free_buf==NULL) funs->free_buf = (LPMAPIFREEBUFFER) GetProcAddress(funs->dll, "MAPIFreeBuffer@4"); funs->sendmail = (LPMAPISENDMAIL) GetProcAddress(funs->dll, "MAPISendMail"); if(funs->sendmail==NULL) funs->sendmail = (LPMAPISENDMAIL) GetProcAddress(funs->dll, (LPCSTR)211); } return funs->dll!=NULL && funs->logon!=NULL && funs->logoff!=NULL && funs->resolve!=NULL && funs->free_buf!=NULL && funs->sendmail!=NULL; } void free_dll(MapiFuns* funs) { if(funs->dll!=NULL) FreeLibrary(funs->dll); funs->dll=NULL; } darcs-2.14.5/src/win32/send_email.h0000755000000000000000000000032707346545000015077 0ustar0000000000000000 int send_email(const char *sendname, const char *recvname, const char *ccname, const char *subj, const char *body, const char *path); darcs-2.14.5/src/win32/sys/0000755000000000000000000000000007346545000013437 5ustar0000000000000000darcs-2.14.5/src/win32/sys/mman.h0000755000000000000000000000022607346545000014543 0ustar0000000000000000 #include void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); int munmap(void *start, size_t length); darcs-2.14.5/tests/0000755000000000000000000000000007346545000012232 5ustar0000000000000000darcs-2.14.5/tests/EXAMPLE.sh0000755000000000000000000000320407346545000013663 0ustar0000000000000000#!/usr/bin/env bash ## Test for issueNNNN - ## ## Copyright (C) YEAR AUTHOR ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. darcs init --repo S cd R mkdir d e # Change the working tree. echo 'Example content.' > d/f darcs record -lam 'Add d/f and e.' darcs mv d/f e/ darcs record -am 'Move d/f to e/f.' darcs push ../S -a # Try to push patches between repos. cd .. cd S darcs push ../R -a cd .. darcs-2.14.5/tests/README.test_maintainers.txt0000755000000000000000000000007707346545000017307 0ustar0000000000000000Please consult . darcs-2.14.5/tests/add.sh0000755000000000000000000000414607346545000013326 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 darcs init temp1 cd temp1 touch foo bar darcs add foo bar for (( i=0 ; i < 5; i=i+1 )); do echo $i >> file-$i; darcs add file-$i done cd .. rm -rf temp1 # add in subdir darcs init temp1 cd temp1 mkdir dir echo zig > dir/foo darcs add dir dir/foo darcs record -am add_foo cd .. rm -rf temp1 # addrm darcs init temp1 cd temp1 touch foo darcs add foo darcs record -a -m add_foo -A x darcs remove foo darcs record -a -m del_foo -A x cd .. rm -rf temp1 # issue1162: add nonexistent slash rm -rf temp1 darcs init temp1 cd temp1 not darcs add a/ 2> err cat err grep 'File a does not exist!' err cd .. rm -rf temp1 # issue184: recording files in directories that haven't explicity been added darcs init temp1 cd temp1 mkdir new mkdir new/dir touch new/dir/t.t darcs add new/dir/t.t darcs record -am test new/dir/t.t > log not grep "don't want to record" log cd .. rm -rf temp1 # Make sure that parent directories are added for files darcs init temp1 cd temp1 mkdir -p a.d/aa.d/aaa.d mkdir -p b.d/bb.d touch a.d/aa.d/aaa.d/baz touch a.d/aa.d/aaa.d/bar darcs add -v a.d/aa.d/aaa.d/bar a.d/aa.d/aaa.d/baz b.d/bb.d 2> log test ! -s log # no output # Make sure that darcs doesn\'t complains about duplicate adds when adding parent dirs. mkdir c.d touch c.d/baz darcs add -v c.d/baz c.d 2> log test ! -s log # no output # Make sure that add output looks good when adding files in subdir mkdir d.d touch d.d/foo darcs add -rv d.d | grep 'd.d/foo' # 'adding a non-existent dir and file gives the expected message not darcs add -v notadir/notafile 2>&1 | grep -i 'does not exist' cd .. rm -rf temp1 # test for darcs add behaviour on missing files. darcs init temp1 cd temp1 empty='test ! -s' nonempty='test -s' rm -f foo darcs add foo >stdout 2>stderr && exit 1 || true $empty stdout $nonempty stderr >foo darcs add foo >stdout 2>stderr $nonempty stdout # confirmation message of added file $empty stderr darcs add foo >stdout 2>stderr && exit 1 || true $empty stdout $nonempty stderr rm foo darcs add foo >stdout 2>stderr && exit 1 || true $empty stdout $nonempty stderr cd .. rm -rf temp1 darcs-2.14.5/tests/add_permissions.sh0000755000000000000000000000321107346545000015751 0ustar0000000000000000#!/usr/bin/env bash ## Darcs should refuse to add an unreadable file, because unreadable ## files aren't recordable. ## ## Copyright (C) 2005 Mark Stosberg ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib abort_windows # does not work on Windows. mkdir temp1 cd temp1 darcs initialize touch unreadable chmod a-r unreadable # Make the file unreadable. not darcs add unreadable 2> log fgrep -i 'permission denied' log # Testing by hand with a directory works, but darcs-test gets # stuck by having an unreadable subdir. #mkdir d #chmod a-r d #not darcs add --debug --verbose d #fgrep -i 'permission denied' log darcs-2.14.5/tests/amend.sh0000755000000000000000000000657507346545000013672 0ustar0000000000000000#!/usr/bin/env bash # Testing amend . lib rm -rf temp1 # set up the repository mkdir temp1 cd temp1 darcs init cd .. # do some work here cd temp1 # Plain amend touch foo darcs add foo darcs record -a -m add_foo echo 'another line' > foo echo y | darcs amend -a foo | grep -i 'amending changes' darcs changes -v | grep 'another line' # amend of removed file touch bar1 touch bar2 cat > bar1 << FOO a line b line FOO darcs add bar1 bar2 darcs record -a -m add_bars rm -f bar2 echo y | darcs amend -a | grep -i 'finished amending' # Special case: patch is empty after amend cp foo foo.old echo 'another line' >> foo darcs record -a -m add_line foo | grep -i 'finished recording' mv foo.old foo echo y | darcs amend -a foo | grep -i 'amending changes' # Amend --author, -m, etc echo "another line" >> foo echo y | darcs amend -a -m new_name foo | grep -i 'amending changes' darcs changes --last=1 | grep new_name echo "another line" >> foo echo y | darcs amend -a -m new_name -A new_author foo | grep -i 'amending changes' darcs changes --last=1 | grep new_author # check that normally the date changes when we amend echo "another line" >> foo darcs changes --last=1 | head -n 1 > old_date sleep 1 echo y | darcs amend -a foo -A new_author | grep -i 'amending changes' darcs changes --last=1 | head -n 1 > new_date not cmp old_date new_date # check that --keep-date works echo "another line" >> foo darcs changes --last=1 | head -n 3 | grep Date > old_date sleep 1 echo y | darcs amend -a foo -A new_author --keep-date | grep -i 'amending changes' darcs changes --last=1 | head -n 3 | grep Date > new_date cmp old_date new_date cd .. # check that the identity changes with --keep-date darcs get temp1 temp2 cd temp2 echo "another line" >> foo darcs changes --last=1 | head -n 1 > old_date echo y | darcs amend -a foo -A new_author --keep-date | grep -i 'amending changes' darcs pull ../temp1 -a --skip-conflicts | grep -i "Skipping some" cd .. rm -rf temp1 temp2 # This checks for a possible bug in patch selection where the no available # patches case is hit. darcs init temp1 cd temp1 touch A darcs record -lam A echo 'l1' >> A darcs record -am l1 darcs amend -a --patch 'A' cd .. rm -rf temp1 ## Copyright (C) 2011 Ganesh Sittampalam darcs init temp1 cd temp1 echo 'file1' > file1 darcs record -lam 'file1' echo 'file2' > file2 darcs record -lam 'file2' echo 'file2:amended' > file2 echo 'nkya' | darcs amend darcs log -p 'file2' -v | grep amended cd .. rm -rf temp1 ## Test for amend --unrecord ## Copyright (C) 2012 Ganesh Sittampalam darcs init temp1 cd temp1 echo -e "x\ny" > foo darcs rec -lam "add foo" echo -e "1\nx\ny\n2" > foo darcs rec -am "insert 1 and 2" echo yyny | darcs amend --unrecord echo -e "x\ny\n2" > foo.expected darcs show contents foo | diff -q foo.expected - echo yenyy | DARCS_EDITOR="sed -i -e s/2/2j/" darcs amend --unrecord echo -e "x\ny\n2j" > foo.expected darcs show contents foo | diff -q foo.expected - echo 'ugh' > bar darcs add bar # use amend to check it's still a short form for amend-record # if we make amend-unrecord visible rather than hidden that would change echo y | darcs amend -a darcs show contents bar | diff -q bar - # test that amend --unrecord --all and specifying files works echo y | darcs amend --unrecord -a foo echo -e "x\ny" > foo.expected darcs show contents foo | diff -q foo.expected - darcs show contents bar | diff -q bar - cd .. rm -rf temp1 darcs-2.14.5/tests/annotate.sh0000755000000000000000000000231207346545000014400 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 darcs init temp1 cd temp1 mkdir a b touch a/a b/b darcs record -lam ab darcs annotate a/a echo x > c darcs record -lam foo -A 'Mark Stosberg ' darcs annotate c darcs annotate c | grep "a@b.com" cd .. # issue1473 annotate repodir rm -rf temp1 mkdir temp1 cd temp1 darcs init mkdir a b touch a/a b/b darcs add --rec . darcs record -a -m ab -A test darcs annotate a/a darcs annotate . > inner # annotate --repodir=something '.' should work cd .. darcs annotate --repodir temp1 '.' > temp1/outer cd temp1 diff inner outer cd .. # issue2207 : annotate on directories rm -rf temp1 darcs init temp1 cd temp1 mkdir d touch d/f darcs record -lam 'p1' darcs annotate d | grep 'p1' cd .. # issue1473 - check that annotate works with and without # repodir and with "." argument. It should fail with the empty string as # a single argument and without any arguments. rm -rf temp1 darcs init temp1 cd temp1 echo 'Example content.' > f darcs record -lam 'Added f.' darcs annotate . darcs annotate f not darcs annotate not darcs annotate '' cd .. darcs annotate --repodir=temp1 . darcs annotate --repodir=temp1 f not darcs annotate --repodir=temp1 not darcs annotate --repodir=temp1 '' darcs-2.14.5/tests/apply-hunks.sh0000755000000000000000000000122207346545000015041 0ustar0000000000000000#!/usr/bin/env bash . ./lib # issue701 # step 1 darcs init temp0 cd temp0 echo m1 > foo darcs record -lam m1 cd .. # step 2 darcs clone temp0 temp1 cd temp1 echo a1 > foo darcs record foo -a -m a1 cd .. # step 3 cd temp0 echo m2 > foo darcs record -a -m m2 cd .. # step 4 cd temp1 darcs pull -a echo m2-a1 > foo darcs record -a -m 'Fix conflict m2-a1' cd .. #step 5 cd temp0 echo m3 > foo darcs record -a -m m3 cd .. #step 6 darcs clone temp0 temp2 cd temp2 echo b1 > foo darcs record -a -m b1 cd .. #step 7 cd temp0 echo m4 > foo darcs record -a -m m4 cd .. #step 8 cd temp1 darcs pull -a echo m2-a1-m4 > foo echo y | darcs mark-conflicts cd .. darcs-2.14.5/tests/apply-reorder.sh0000755000000000000000000000210307346545000015352 0ustar0000000000000000#!/usr/bin/env bash ## Test that apply --reorder moves to the top the uncommon set of patches between ## the current repository and the set of patches we are applying. . lib # Load some portability helpers. check_patches_order () { darcs log | tr -d "\n" | grep $1.*$2.*$3 } test_init () { rm -rf R1 R2 darcs init "R1" cd R1 touch "r1_0" darcs record -lam "Adding r1_0" cd .. darcs clone "R1" "R2" cd R2 touch "r2_0" darcs record -lam "Adding r2_0" darcs send --no-minimize -a --no-edit-description -o ../R1/P cd .. cd R1 touch "r1_1" darcs record -lam "Adding r1_1" cd .. } test_init cd R1 darcs apply P # Without reorder the expected order is r2_0, r1_1, r1_0 . check_patches_order r2_0 r1_1 r1_0 # Test that apply --reorder reorders even if there is nothing to apply. darcs apply --reorder P check_patches_order r1_1 r2_0 r1_0 cd .. test_init cd R1 darcs apply --reorder P # With reorder the expected order is r1_1, r2_0, r1_0 . check_patches_order r1_1 r2_0 r1_0 cd .. darcs-2.14.5/tests/apply.sh0000755000000000000000000001374407346545000013727 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2017 - apply should gracefully handle tag missing ## from context (complain, not crash) ## ## Copyright (C) 2010 Eric Kow ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. # issue1427: apply gzipped bundles rm -rf temp1 temp2 darcs init temp1 darcs init temp2 cd temp1 touch foo bar darcs record -lam add_foo_bar darcs mv foo zig darcs mv bar foo darcs mv zig bar darcs record -lam swap_foo_bar darcs send --output=funpatch --dont-sign -a ../temp2 gzip funpatch cd ../temp2 darcs apply ../temp1/funpatch.gz cd .. cmp temp1/bar temp2/bar rm -rf temp2 darcs init temp2 cd temp2 darcs apply ../temp1/funpatch.gz ## Also test that "darcs apply" can accept a patch on stdin. darcs obl -a darcs apply < ../temp1/funpatch.gz cd .. cmp temp1/bar temp2/bar rm -rf temp1 temp2 ## issue2017 - apply should gracefully handle tag missing ## from context (complain, not crash) darcs init R cd R echo 'Example content.' > f darcs record -lam 'Add f' cd .. # variant 0 - this passes trivially darcs clone R R0 darcs clone R0 S0 darcs tag 's' --repo S0 darcs clone S0 T0 cd T0 echo 'More content.' > f darcs record -lam 'Modify f' darcs send -o foo.dpatch -a cd .. not darcs apply --repo R0 T0/foo.dpatch > log 2>&1 not grep bug log grep missing log # variant 1 - tag in shared context darcs clone R R1 darcs tag '1' --repo R1 darcs clone R1 S1 darcs tag 's1' --repo S1 darcs clone S1 T1 cd T1 echo 'More content.' > f darcs record -lam 'Modify f' darcs send -o foo.dpatch -a cd .. # sanity check: should be able to cherry pick darcs clone R1 R1b cd R1b [ `darcs log --count` -eq 2 ] darcs pull ../T1 --match 'touch f' --all [ `darcs log --count` -eq 3 ] cd .. # the test: can't apply this due to incorrect context not darcs apply --repo R1 T1/foo.dpatch > log 2>&1 not grep 'bug' log grep missing log # variant 2 - tag created after the fact darcs clone R R2 darcs clone R2 S2 darcs tag 's2' --repo S2 darcs clone S2 T2 cd T2 echo 'More content.' > f darcs record -lam 'Modify f' darcs send -o foo.dpatch -a cd .. darcs tag '2' --repo R2 # only tag after not darcs apply --repo R2 T2/foo.dpatch > log 2>&1 not grep 'bug' log grep missing log rm -rf R* S* T* # issue1921 # Attempting to apply a patch which depends on a missing tag should not cause # darcs to die. darcs init R cd R # Setup a repo with a tagged patch, and another patch ontop, so we have a split # inventory touch file1 darcs rec -alm 'Add file1' darcs tag -m 'file1 tag' touch file2 darcs rec -alm 'Add file2' # Take a copy of the repo at this point darcs clone . ../S # Add the tag which we will fail on darcs tag -m 'file2 tag' # Take a copy with the tag darcs clone . ../T # Add our patch which will depend only on the last tag. echo 'file1' > file1 darcs rec -am 'file1 content' # Create a patch bundle with the new patch (by sending against the repo we # copied, with the last tag) darcs send ../T -a -o ../patch.dpatch --no-edit-description cd ../S # Try to apply to the patch which depends on the missing tag (we expect darcs # to fail gracefully here) not darcs apply ../patch.dpatch &> apply_output.txt # A best-attempt at ensuring darcs warns about the missing tag: grep "tagged file2 tag" apply_output.txt grep "FATAL: Cannot apply this bundle. We are missing the above patches." apply_output.txt cd .. rm -rf R S ## issue1873 - apply should complain about the right ## patches if it says some are missing rm -rf R S darcs init R cd R echo a > a darcs rec -lam a echo b > a darcs rec -lam b echo x > x darcs rec -lam x echo c > a darcs rec -lam c echo y > y darcs rec -lam y echo d > a darcs rec -lam d cd .. darcs clone R S darcs unpull -p x -a --repo R darcs send --no-minimize -p x -a --repo S -o R/x.dpatch darcs unpull -p y -a --repo R not darcs apply --repo R R/x.dpatch 2>&1 | tee log not grep '^ \* d' log # does not complain about an unrelated patch grep '^ \* y' log # complains about the offending one instead rm -rf R S ## Test that apply --skip-conflicts filters the conflicts ## appropriately. darcs init R cd R echo 'foo' > foo echo 'bar' > bar darcs rec -lam 'Add foo and bar' darcs clone . ../S echo 'foo2' > foo darcs rec -lam 'Change foo (2)' echo 'bar2' > bar darcs rec -lam 'Change bar (2)' cd ../S echo 'foo3' > foo darcs rec -lam 'Change foo (3)' cd ../R darcs send -a ../S -o ../S/applyme.dpatch cd ../S darcs apply --skip-conflicts applyme.dpatch test `darcs log --count` -eq 3 cd .. rm -rf R S # issue2193 - "darcs apply --test runs the test twice. darcs init R darcs clone R S # Create a patch bundle cd R echo 'Example content.' >file1 darcs rec -lam patch1 darcs send --dont-edit-description --output=./patch1 -a ../S # Setup a test that prints a unique string, apply the patch set, # check that the unique string occurs in the output once. cd ../S darcs setpref test 'echo 2a427e65f322be754dce67c829e5f8a3' darcs apply --test ../R/patch1 > log 2>&1 [ `fgrep -c 2a427e65f322be754dce67c829e5f8a3 log` -eq 1 ] darcs-2.14.5/tests/ask_deps.sh0000755000000000000000000000264307346545000014367 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp mkdir temp cd temp darcs init cat > _darcs/prefs/defaults <<. ALL author test ALL ignore-times ALL ask-deps . # add three depending patches for file 'a' # expect no dependency questions # 'q' will abort and cause future failure if an unexpected dependency is asked touch a darcs add a echo q | darcs rec -am a0 darcs log -p a0 -v --machine | cat echo 1 > a echo q | darcs rec -am a1 darcs log -p a1 -v --machine | cat echo 2 > a echo q | darcs rec -am a2 darcs log -p a2 -v --machine | cat # add some patches for file 'b' # expect no dependency questions for file 'b', # but every time expect questions for the three patches of file 'a' # every 'n' should continue to ask about the next patch # the first 'y' should make all following dependencies of 'a' implicit and stop asking # 'q' will abort and cause future failure if an unexpected dependency is asked touch b darcs add b # test 0 echo nnnY | tr '[A-Z]' '[a-z]' | darcs rec -am b0 darcs log -p b0 -v --machine | cat # test 1 echo 1 > b echo nnyY | tr '[A-Z]' '[a-z]' | darcs rec -am b1 darcs log -p b1 -v --machine | cat darcs log -p b1 -v --machine | grep '\[a0' # test 2 echo 2 > b echo nyY | tr '[A-Z]' '[a-z]' | darcs rec -am b2 darcs log -p b2 -v --machine | grep '\[a1' # test 3 echo 3 > b echo yY | tr '[A-Z]' '[a-z]' | darcs rec -am b3 darcs log -p b3 -v --machine | cat darcs log -p b3 -v --machine | grep '\[a2' cd .. rm -rf temp darcs-2.14.5/tests/bad-format.sh0000755000000000000000000000132407346545000014605 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 temp2 gunzip -c $TESTDATA/many-files--old-fashioned-inventory.tgz | tar xf - mv many-files--old-fashioned-inventory temp1 echo '' > temp1/_darcs/format # ensure that we successfully get repositories even if they have a bogus # format file, as can happen if no _darcs/format is present (i.e. it's # generated by an older darcs) and an http server fails to produce a 404 # error code. This is issue757. darcs get temp1 temp2 echo intentional-error >> temp2/_darcs/format cat temp2/_darcs/format rm -rf temp3 not darcs get temp2 temp3 2> err cat err grep intentional-error err grep -i "read repository.*unknown format" err darcs-2.14.5/tests/bin/0000755000000000000000000000000007346545000013002 5ustar0000000000000000darcs-2.14.5/tests/bin/hspwd.hs0000755000000000000000000000015207346545000014464 0ustar0000000000000000module Main where import System.Directory ( getCurrentDirectory ) main = getCurrentDirectory >>= putStr darcs-2.14.5/tests/bin/renameHelper.hs0000755000000000000000000001714407346545000015757 0ustar0000000000000000-- Helper to test renaming -- -- Copyright (C) 2014 Owen Stephens -- -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE module Main where import Data.List ( sort, groupBy ) import Data.Function ( on ) import System.FilePath ( () ) import Control.Monad ( forM, void, when, unless, forM_ ) import System.Directory ( createDirectory, removeFile, removeDirectory , doesDirectoryExist, doesFileExist ) import System.Exit ( ExitCode(..) ) import System.Process ( system ) {- N = nonexistent (unrecorded, not in working) U = unadded (unrecorded, in working) S = shadow (recorded, not in working) K = known (recorded, in working) O = OK F = Fail tgt N U S K N F1 F1 F1 F1 s U F2 F2 F2 F2 r S F3 O4 F5 O6 c K O7 F8 O9 OF10 Reasons: 1 no such source path 2 shouldn't move paths we don't manage 3 target not in WD/Repo 4 post-hoc move 5 target exists in Repo 6 target exists in WD/Repo, but could be successful post-hoc if target is made to appear deleted before the move 7 simple rename 8 target in WD 9 rename into file that has been deleted. 10 If target is dir then OK: move into dir, else Fail: target exists in WD -} data PathExistence = N | U | K | S deriving (Eq, Ord, Show) data PathType = File | Dir deriving (Eq, Ord, Show ) -- OK takes a function to modify src/tgt names, used to check for tgt existence data ExpectedResult = OK ((String, String) -> String) | Fail instance Show ExpectedResult where show (OK _) = "OK " show Fail = "FAIL" -- ExpectedResults are for: [File/File, File/Dir, Dir/File, Dir/Dir] resList :: [ (PathExistence, [(PathExistence, [ExpectedResult])]) ] resList = [ (N, [ (N, allFail) , (U, allFail) , (K, allFail) , (S, allFail) ]) , (U, [ (N, allFail) , (U, allFail) , (K, allFail) , (S, allFail) ]) , (K, [ (N, allOkSnd) , (U, allFail) , (K, [Fail, okMoveInto, Fail, okMoveInto]) , (S, allOkSnd) ]) , (S, [ (N, allFail) , (U, [okSnd, Fail, Fail, okSnd]) , (K, [okSnd, Fail, Fail, okSnd]) , (S, allFail) ]) ] where allFail = replicate 4 Fail allOkSnd = replicate 4 okSnd okSnd = OK snd okMoveInto = OK $ \(s,d) -> ds -- Add a newline, else we're not creating a valid textfile! makeAtPath File = \p -> writeFile p (p ++ "\n") makeAtPath Dir = createDirectory removeAtPath File p = do removeFile p void $ system ("echo 'Removed file " ++ p ++ "'") removeAtPath Dir p = do removeDirectory p void $ system ("echo 'Removed dir " ++ p ++ "'") expectFailure args ExitSuccess = fail $ "Unexpected success: " ++ show args expectFailure args ec = return () exists File = doesFileExist exists Dir = doesDirectoryExist checkTgtExists pathType mod src tgt args = do tgtExists <- exists pathType $ mod (src, tgt) unless tgtExists $ fail $ "Unexpected absence of move tgt: " ++ show (mod (src, tgt)) ++ " " ++ show args checkSrcDoesNotExist pathType src args = do srcExists <- exists pathType src when srcExists $ fail $ "Unexpected presence of move src: " ++ show args expectSuccess args (ExitFailure _) _ = fail $ "Unexpected failure: " ++ show args expectSuccess (U,_,_,_,_,_,_) ExitSuccess _ = return () expectSuccess args@(K, srcPathType@File, src, K, Dir, tgt, _) _ mod = do checkSrcDoesNotExist srcPathType src args -- src is a file, tgt is a dir, so src will be moved inside dir checkTgtExists File mod src tgt args expectSuccess args@(_, srcPathType, src, N, _, tgt, _) _ mod = do checkSrcDoesNotExist srcPathType src args -- tgt didn't exist so src will simply be renamed to tgt checkTgtExists srcPathType mod src tgt args expectSuccess args@(K, srcPathType, src, S, _, tgt, _) _ mod = do checkSrcDoesNotExist srcPathType src args -- tgt was shadow, so src will simply be renamed to tgt checkTgtExists srcPathType mod src tgt args expectSuccess args@(_, srcPathType, src,_, tgtPathType, tgt,_) _ mod = do checkSrcDoesNotExist srcPathType src args checkTgtExists tgtPathType mod src tgt args type RenameInfo = (PathExistence, PathType, FilePath) main = do -- Don't need to do anything with the nonexistent paths let [_, us, ks, ss] = groupBy ((==) `on` (\(x,_,_) -> x)) . sort . concatMap (\(x,y) -> [x,y]) . fst . unzip $ pathDetails -- Create all files/dirs mapM_ (\(_, ptype, p) -> makeAtPath ptype p) $ us ++ ks ++ ss -- Let darcs know about all knowns/shadows mapM_ (system . ("darcs add " ++) . unwords . map (\(_,_,x)->x)) [ks, ss] _ <- system "darcs rec -am 'add everything'" -- Remove from working all shadows mapM_ (\(_, ptype, p) -> removeAtPath ptype p) ss forM_ pathDetails $ \(( (srcType, srcPathType, srcName) , (tgtType, tgtPathType, tgtName)), expected) -> do let movePatchName = "'move " ++ srcName ++ " -> " ++ tgtName ++ "'" ec <- system $ unwords [ "darcs whatsnew" , "&& darcs move", srcName, tgtName , "&& darcs rec -a ", tgtName, srcName , "-m", movePatchName] let args = ( srcType, srcPathType, srcName , tgtType, tgtPathType, tgtName, expected) case expected of OK check -> expectSuccess args ec check Fail -> expectFailure args ec where fileDirCombos = [(a,b) | a <- [File, Dir], b <- [File, Dir]] zipErr [] [] = [] zipErr (x : xs) (y : ys) = (x, y) : zipErr xs ys zipErr _ _ = error "uneven lists in zipErr" pathDetails :: [((RenameInfo, RenameInfo), ExpectedResult)] pathDetails = concatFor resList $ \(srcType, srcResults) -> concatFor srcResults $ \(tgtType, expected) -> concatFor (zipErr fileDirCombos expected) $ \((srcPathType, tgtPathType), expectedResult) -> let nameBase = show srcType ++ show srcPathType ++ show tgtType ++ show tgtPathType srcName = nameBase ++ "-src" tgtName = nameBase ++ "-dst" src = (srcType, srcPathType, srcName) tgt = (tgtType, tgtPathType, tgtName) in [((src, tgt), expectedResult)] where concatFor = flip concatMap darcs-2.14.5/tests/bin/trackdown-bisect-helper.hs0000755000000000000000000000156507346545000020070 0ustar0000000000000000{- Tool for construction of testing repository for test --bisect. Written by Matthias Fischmann. Usage: ./trackdown-bisect-helper '[0,1,1,1,0,0,0]' This will generate a repository in which `grep -q 1 j` will first fail three times, then succeed three times, then fail once if you unapply patches with the linear implementation. -} import Control.Monad import System.IO import System.Environment import System.Process import Data.List import Control.Exception stamp i j = system ("echo " ++ show i ++ " > ./i") >> system ("echo " ++ show j ++ " > ./j") >> -- system ("sleep 1") >> hFlush stdout >> system ("darcs record --ignore-times -am '" ++ show i ++ "'") generate :: [Int] -> IO () generate = mapM_ (uncurry stamp) . zip [1..] main :: IO () main = do args <- getArgs let js = (read (head args)) :: [Int] generate js darcs-2.14.5/tests/binary.sh0000755000000000000000000000075307346545000014062 0ustar0000000000000000#!/usr/bin/env bash . ./lib binary=example_binary.png function checkbinary(){ cmp $binary ../temp1/$binary } rm -rf temp1 temp2 mkdir temp1 temp2 cd temp1 darcs init cp $TESTDATA/$binary . darcs add $binary darcs record -am P1 cd ../temp2 darcs init test ! -e $binary darcs pull ../temp1 -a checkbinary darcs obliterate -a test ! -e $binary darcs pull ../temp1 -a checkbinary darcs unrecord -a checkbinary darcs revert -a test ! -e $binary darcs unrevert -a checkbinary rm -rf temp1 temp2 darcs-2.14.5/tests/clone.sh0000755000000000000000000000637107346545000013700 0ustar0000000000000000#!/usr/bin/env bash . lib darcs init temp1 cd temp1 touch t.t darcs record -lam "initial add" darcs log --context > my_context DIR=`pwd` abs_to_context="${DIR}/my_context" cd .. darcs clone temp1 --context="${abs_to_context}" temp2 darcs log --context --repo temp2 > repo2_context diff -u "${abs_to_context}" repo2_context rm -rf temp1 temp2 # issue1865: cover interaction of clone --context with tags darcs init temp1 cd temp1 touch t.t darcs record -lam "initial add" darcs tag -m tt echo x > x darcs rec -lam "x" darcs log --context > my_context abs_to_context="$(pwd)/my_context" cd .. darcs clone temp1 --context="${abs_to_context}" temp2 darcs log --context --repo temp2 > repo2_context diff -u "${abs_to_context}" repo2_context rm -rf temp1 temp2 # issue1041 # should fail, since temp1 doesn't exist not darcs clone temp1 temp2 # verify that temp2 wasn't created not cd temp2 rm -rf temp1 temp2 # issue2199 "darcs clone --tag" gets too much if tag is dirty darcs init temp1 cd temp1 echo 'wibble' > file darcs rec -lam 'wibble' echo 'wobble' > file darcs rec -lam 'wobble' cd .. darcs clone temp1 temp2 cd temp2 darcs unpull --patch 'wobble' -a darcs tag 'wibble' cd .. cd temp1 darcs pull ../temp2 -a cd .. darcs clone --tag wibble temp1 temp3 cd temp3 darcs log | not grep wobble cd .. rm -rf temp1 temp2 temp3 # issue885: darcs clone --to-match darcs init temp1 cd temp1 echo first > a darcs record -lam 'first' firsthash=`darcs log --xml | grep 'hash=' | sed -e "s/.*hash='//" -e "s/'>//"` echo second > b darcs record -lam 'second' cd .. darcs clone --to-match "hash $firsthash" temp1 temp2 test $(darcs log --count --repodir temp2) -eq 1 darcs clone --to-hash $firsthash temp1 temp3 test $(darcs log --count --repodir temp3) -eq 1 rm -rf temp1 temp2 temp3 # various tests for clone --tag darcs init temp1 cd temp1 echo ALL ignore-times >> _darcs/prefs/defaults echo A > foo darcs record -lam AA echo B > foo darcs record -am BB echo C > foo darcs record -am CC darcs tag -m 1.0 cp foo foo_version_1.0 echo D > foo darcs record -am DD echo E > foo darcs record -am EE echo F > foo darcs record -am FF cd .. darcs clone --tag 1.0 --repo-name temp2 temp1 cmp temp2/foo temp1/foo_version_1.0 rm -rf temp1 temp2 temp3 # clone --tag with commuted patches darcs init temp1 cd temp1 cat > file < file < file </dev/null; then cat _darcs/patches/pending exit 1 fi fi cd .. rm -rf temp1 temp2 # issue2230 - darcs clone --context checks the validity of the context # file too late. darcs init temp1 touch fake_context.txt not darcs clone --context fake_context.txt temp1 temp2 # The clone should fail, so we shouldn't have an temp2 repo [[ ! -e temp2 ]] rm -rf temp1 darcs-2.14.5/tests/conflict-doppleganger.sh0000755000000000000000000000324107346545000017037 0ustar0000000000000000#!/usr/bin/env bash . lib # Tests for the doppleganger conflict bug. # For Zooko, with love # Also, for issue81. check_conflict() { cat out if test "$format" = darcs-2; then not grep 'conflict' out else grep 'conflict' out fi } # check doppleganger conflicts rm -rf tmp_dopple tmp_ganger mkdir tmp_dopple cd tmp_dopple darcs init touch a.txt darcs add a.txt darcs record -A base -am 'adding a.txt' cd .. darcs get tmp_dopple tmp_ganger for repo in tmp_dopple tmp_ganger; do echo working on $repo cd $repo echo "text which appears in both places at once" > a.txt darcs record -A $repo -am "recording an identical change in $repo" cd .. done # Now that the conflict has been set up, try pull one patch from the other. cd tmp_ganger darcs pull -a ../tmp_dopple > out check_conflict cd .. # Checking resolution dopplegangers conflicts rm -rf temp0 temp1 temp2 tmp_dopple tmp_ganger mkdir temp0 cd temp0 darcs init cd .. # Create a conflict darcs get temp0 temp1 cd temp1 darcs show repo echo temp1 > a.txt darcs add a.txt darcs record -A base -am 'adding temp1 a.txt' cd .. darcs get temp0 temp2 cd temp2 echo temp2 > a.txt darcs add a.txt darcs record -A base -am 'adding temp2 a.txt' cd .. # Resolve the conflict the same way on both sides for repo in tmp_dopple tmp_ganger; do echo working on $repo darcs get temp1 $repo cd $repo darcs pull -a ../temp2 echo "text which appears in both places at once" > a.txt darcs record -A $repo -am "recording an identical change in $repo" cd .. done # Now that the conflict has been set up, try pull one patch from the other. cd tmp_ganger darcs pull -a ../tmp_dopple > out check_conflict darcs-2.14.5/tests/conflict-fight-failure.sh0000755000000000000000000000153507346545000017122 0ustar0000000000000000#!/bin/env bash # # Test darcs conflict fight scenario. # # Set up two repos RA and RB. Create conflict in RB. # After resolving conflict in RB, pull new patch from RA. # Repeat, rinse. # # Author: Pekka Pessi # . ./lib record="record --ignore-time --all --author X" rm -rf RA RB mkdir RA cd RA echo 0 > file darcs init darcs add file darcs $record -m0 file cd .. darcs get RA RB # Create conflict in RB cd RB echo let it b > file darcs $record -m B cd .. for i in 1 2 3 4 5 # 6 7 8 9 10 11 12 do echo Create new patch A$i in RA cd RA echo a$i > file darcs $record -m A$i cd .. echo Pull patch A$i from RA and get a conflict cd RB time darcs pull ../RA --verbose --all --patch "^A$i\$" cd .. echo Resolve conflict and start fighting by recording B$i cd RB echo let it b > file darcs $record -m B$i cd .. done rm -rf RA RB darcs-2.14.5/tests/conflict-fight.sh0000755000000000000000000000203207346545000015466 0ustar0000000000000000#!/usr/bin/env bash . ./lib # step 1 mkdir temp0 cd temp0 darcs init echo temp0 > _darcs/prefs/author echo m1 > foo darcs add foo darcs record -a -m m1 --ignore-times cd .. # step 2 darcs get temp0 temp1 cd temp1 echo temp1 > _darcs/prefs/author echo a1 > foo darcs record foo -a -m a1 --ignore-times cd .. # step 3 cd temp0 echo m2 > foo darcs record -a -m m2 --ignore-times cd .. # step 4 cd temp1 darcs pull -a echo m2-a1 > foo darcs record -a -m 'Fix conflict m2-a1' --ignore-times echo a2 > foo darcs record -a -m a2 --ignore-times cd .. #step 5 cd temp0 echo m3 > foo darcs record -a -m m3 --ignore-times cd .. #step 6 darcs get temp0 temp2 cd temp2 echo temp2 > _darcs/prefs/author echo b1 > foo darcs record -a -m b1 --ignore-times cd .. #step 7 cd temp0 echo m4 > foo darcs record -a -m m4 --ignore-times cd .. #step 8 cd temp1 darcs pull -a echo m2-a1-m4 > foo darcs record -a -m 'Fix three-way m2/m2-a1/m4' --ignore-times echo a3 > foo darcs record -a -m a3 --ignore-times cd .. #step 9 cd temp1 darcs pull -av ../temp2 cd .. darcs-2.14.5/tests/conflict-reporting.sh0000755000000000000000000000417407346545000016407 0ustar0000000000000000#!/bin/sh -e ## ## General tests for the conflict UI: ## - conflict reporting on pull etc ("We have conflicts in the following files:") ## - conflict reporting in summaries of changes ("M! foo.txt") ## - conflict marking in files ## ## Copyright (C) 2016 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib mkdir R1 cd R1 darcs init cat > file1 < file2 < file1 < file2 < file1 < file2 < pull-output grep "We have conflicts in the following files" pull-output grep "file1" pull-output not grep "file2" pull-output cat > file1-expected < changes-output grep "M! ./file1 -1 +1" changes-output grep "M ./file2 -1 +1" changes-output darcs-2.14.5/tests/convert-darcs2.sh0000755000000000000000000000424707346545000015434 0ustar0000000000000000#!/usr/bin/env bash ## Tests for convert command based on previously checked results ## to generate new test material for this test, ## see bin/convert-writer.sh ## ## Copyright (C) 2009 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib skip-formats darcs-1 runtest() { opt=$1 name=$2 rm -rf temp mkdir temp cd temp mkdir repo cd repo darcs init --darcs-1 darcs apply --allow-conflicts $TESTDATA/convert/darcs1/$name.dpatch cd .. echo 'I understand the consequences of my action' | darcs convert darcs-2 repo repo2 $opt mkdir empty-darcs2 cd empty-darcs2 darcs init --darcs-2 cd .. cd repo2 darcs send --no-minimize -a -o ../$name-darcs2.dpatch ../empty-darcs2 cd .. diff -I'1 patch for repository ' -I'patches for repository ' -I'Oct 1' -u $TESTDATA/convert/darcs2/$name.dpatch $name-darcs2.dpatch } for opt in --no-working-dir --with-working-dir; do runtest $opt simple runtest $opt twowayconflict runtest $opt threewayconflict runtest $opt threewayanddep runtest $opt threewayandmultideps runtest $opt resolution runtest $opt tworesolutions done darcs-2.14.5/tests/convert_export.sh0000755000000000000000000000442007346545000015652 0ustar0000000000000000#!/usr/bin/env bash ## test incremental fast-export to git ## ## Copyright (C) 2014 Guillaume Hoffmann ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. # only run if git present git --version | grep -i "git version" || exit 200 darcs init --repo R # Create our test repos. cd R mkdir d e # Change the working tree. echo 'Example content.' > d/f darcs record -lam 'Add d/f and e.' # one more change, this time with non-ASCII file name, comment, and content # as well as a space in the file name # see http://bugs.darcs.net/issue2359 echo 'Liebe Grüße' > e/'Liebe Grüße' darcs record -lam 'Add file e/"Liebe Grüße"' git init gitmirror darcs convert export --write-marks darcs-to-git.marks > fex (cd gitmirror && git fast-import --export-marks=git.marks < ../fex) darcs mv d/f e/ darcs record -am 'Move d/f to e/f.' darcs convert export --read-marks darcs-to-git.marks --write-marks darcs-to-git.marks > fex2 (cd gitmirror && git fast-import --import-marks=git.marks --export-marks=git.marks < ../fex2) # restore the git working tree by making a clone git clone gitmirror gitmirror-clone diff e/f gitmirror-clone/e/f diff e/"Liebe Grüße" gitmirror-clone/e/"Liebe Grüße" darcs-2.14.5/tests/data/0000755000000000000000000000000007346545000013143 5ustar0000000000000000darcs-2.14.5/tests/data/README0000755000000000000000000000025507346545000014030 0ustar0000000000000000 Larger or more complex pre-built repos are stored here for testing. They are stored as archives for space efficiency, and to emphasize that they are meant to be read-only. darcs-2.14.5/tests/data/badrepo.tgz0000755000000000000000000000672107346545000015316 0ustar0000000000000000d6M\ ĔF"3w,Q. Ů',_4;ݳ^/,xXhBXxA`̅cT3_w,1ݝ~^^.vƚ=HR ˱ xc5' OPH{R\>i0}׬>UٿWG7}(SW#oZmݷQWDl+fZ}{HF;d9Q KRô!}Bm;W|N_ePJAH/题b"*XX$*DR5VH{{;B5OzEqŭ?/ [$Wy?qɸbIWN܅Y=Qs;3|eo^SEG\z!/~o웦O6W8{7/+;-|OCxꤩg}xۑcn1~ȜK)lQ7.j[w0kziDyWf?d2ǂjȧiBjZ2 5ŋK >% TS$,I)`nyYG]E( ?29IQºc$,J <^CH)X>i"6$Rz #/sUY=.^ue|<_=/e?_= 7.;)W߻Q4ʼN\եWw1Q:_U$vEKIeEU/)rIHDEE?bKD_  gOfʚ7V_^O_{UaMǝ}-aIh_:pֳ?z{죛"2 HXD 5]AO l"D= ~Hb )vHI%QFQW[ʊCGqƬ{5/xcWfz<:9tgGޮ~Q?90硷zȵ39coW󚵿T,~_, ؃.x}ͅ+Բ{?Yuv=6Fş =kմyP!e?+?ULWbF- & 6 E<ϴ-o"c[qg`)aG3LZƴ +?=<=rsнoC'|&p#13>we'@EkKԛc 50^q8@ _pOsY}`HKFiӲL[mu0S_ K[uS'd` cOsMLJіD;QSȅsQb/6LJ ֊Sg Պm .&ҦQ>cZ*N?/4=8svX)s'3;Z'O3rV~F)o)uZj;<=֍bH=tzp ZHWТURUJaL.v͘6mr1TJLx 2={><mb2QUh *w/,DYD;3z83?pHx2LB7fYCC71(MV.5 ߳ wf-% I94s=L &j\cD~kԧ3ZCX@u'2f]7ڶO. .uAiwBqm(!ÎzR7놉i@~4$`Z |s0h 9̍tl=śd]A&J.V?^^}dA P?X3c/g!k(NY`rf:CCY`HЊe 3PiMf(Xš~|BLqjv,C˂o9ILsPbPv&U͊H6 g56 y 3wlls9mA#oܶ%& F+o968 x7zPAZJ sd4VKԀ`,wPUwJZXn=$j b" 1CACo,@y`.L:ID)%prNA?s35lg:~˃vMa`L|#+^:;[6*֝pq&&5Y>JH4Dl X \pa p0~/ [uasZȇ65O{y5Voîʖ2RQKpYU\P]k%-%Lp3Za';0w^;2uxw杹sth9%0iS= zNyڻk>XVM}sPRMcͦ?+Hk&;q41QsAEĔ"*/":|4O!rÒ óP6 *. _8R.rp"#u׆ue9ՃUI~1>JG'pC0%2y=A\(sNX؝h"p⛄ۮ݇0Ϛ19pp<ⷤ2i4Df2456`HvuN#k, \Ƿ>sJ|'lRp4&[4wl_ODz_?+a2qoIPd},*(>G1$F6p^ae?7_P$­-OIaCw-Tr$aϊt *tcC>axUhcfqrdRHT $膔LzRNTT ab͏ (#ˊ(&yij$8k%K8jj<$4. jRm{?VZF9`U35 ?_Պ3O=O-/o:aĖ>J3~sѷ|SuQo\~'Ϝ|t+.U_t5/mxr-jjRC 3-h ŞyC*v_"U;?y&`Z"߈"Utcc$)<(oޅ?53N:"u޷;׏s\pc89qk7o[¯=}h/r vWp Mh柸tݗqg-62x%Sc:2%/<}OAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQHxdarcs-2.14.5/tests/data/braced.dpatch0000755000000000000000000000062707346545000015560 0ustar00000000000000001 patch for repository /home/ganesh/temp/empty: Mon Oct 18 18:27:21 BST 2010 Ganesh Sittampalam * foo New patches: [foo Ganesh Sittampalam **20101018172721 Ignore-this: 5e9ee20eb359c030581f54a73186405c ] { addfile ./wibble hunk ./wibble 1 +wibble { addfile ./wobble hunk ./wobble 1 +wobble } } Context: Patch bundle hash: f427e3af1c3f5486cf570a5c7bdb826a0a2eb3f8 darcs-2.14.5/tests/data/braced.tgz0000755000000000000000000000635707346545000015127 0ustar0000000000000000vIM\ pe?,U<EHGQ>H(Imy&-h&$|6vI9tEA8@A(R* "SGǩowMBkzfMr~?ݽ*.VIH0I'+,+"M0,Le.BB(p${W Xî 57Igt~ξqߟ~^ۮዣ+_8=5h,& kF=ǀBj92Gc9" u %YRNdVVuH 'ɜΩLr@Rl ǦKD vbd6oǰ_8c(_l-@" 2<#X]ijjr%.@2UNI"eQ\NR$XaH/YY&|VIYTpX!%M&ڿf}Bkzш5?˲ccofSH4㒡5lf\&PK@ЗXq_;,,8)a_7_M|ۮ]mǢO/X=3/۟K7x/ۇ/;wWb?4!fXQ0/'Sp^i3FO|oXNSg߬IԷN' b6f`WSg]̾sM=w Sq_=ys9l~eaM9n^xgžw5iGWpW#w'}DZWW=)͕}m_o-uMuąLߞ=G^]vX>M.ȤC),j3ta`kG^qJĄA 0pOg [#R0,2vlշa!a \L}]"mR;mvQ#tr0݆[iA1jbW\ÅVtVt.FIu%EЫKgDKׄEóbvg-Z]8dazVK *T]w:RpjΥCˣjM.u` ΘZ='W5Z}CVg0PZ6NuMnTAmͿD]KlvrrM@ڡ-H&[Z?6uhX>qA?oXm`=E썐R j{E`Fk7ضOvTjA~4 4ihBɋfVg8[- ] .6 qq9q3n0 FC=wV.tekʣhK( :@5ٶiYMg \y[+Ty? $mD!,ApCQ(0P!hD数K*l_j` BYXpW0؀jQ x1x$(_dT;hmDcUêJ8NHnn=ް^=lӄ|_/˾S!]A5%kn*>K:,hFmoIH .MP^J$<>.)g Ijevق>R&  #i -0%>)6jeT/pD/Tzi >Q`HB ZŁ]~ 4TlG2.@+u_ AthǺo hXt*!_ ]RшrIiz^,B Md,Nv0^G2 \Pq_X:/dxxav4N nzM] hzf~&qղkRX5 V Zo0Z[h dXFq Q8vX6INF5 kβ30@3CCXe0268]<`S;Y?UiMv:%GI{i˂qcH6&ix*xYlLE2&ЏE7D&KSqI`@ΫG\ja laRWn&[BeS`o:b4DžH4mI>j.pf^L+Nط:nW#wԶ]{Dn - 0 Gvc=LT}gA&Cm`8d'8藩 Sd TAj}xLȦ0?iqp0wU z_S)&Ʉ_PG_,>Xň#F1bĈ#F1bĈ#F1bĈ#A3xdarcs-2.14.5/tests/data/context-v1.dpatch0000755000000000000000000000137207346545000016346 0ustar00000000000000002 patches for repository /home/ganesh/darcs-comp/temp/empty: patch 573defe88544e8f75a18e530e3aeaf6608951aa1 Author: Ganesh Sittampalam Date: Thu Oct 21 18:28:18 BST 2010 * init patch c8ec7c8b2df55720ba2c3a21adb80790363f421e Author: Ganesh Sittampalam Date: Thu Oct 21 18:28:31 BST 2010 * ABC New patches: [init Ganesh Sittampalam **20101021172818 Ignore-this: 6a770d5966ed23f56e94c08977507388 ] { addfile ./wibble hunk ./wibble 1 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 } [ABC Ganesh Sittampalam **20101021172831 Ignore-this: 157403967fc6753e0f2540535937da5b ] hunk ./wibble 4 1 2 3 -4 -5 -6 +4A +5B +6C 7 8 9 Context: Patch bundle hash: 0a20411489222e188722666cf0db4c5de2539aee darcs-2.14.5/tests/data/context-v1.tgz0000755000000000000000000001010607346545000015702 0ustar0000000000000000yL\ |չ`b7&{vIB0B^Ǚ!;әEZAkVDZ{6 ,*bժ(>k{hߙ%KPMC3}|sl,dE$@8I EEyTSO\YMOU^9UVexg0rVbIYFcN s\cQ9IFRE=7-Ud?+`x_IgqT 5bM8]c2xˆ'"G3zg*΍=צi-ޕV^#_muYݵG7ӡË=jc?} 9խMxzFYu\ Ϻuϛ|k̞Q ]_S֮ ;A_r,Y)VcxB$ZdiQRL8,\Te ȪH6i)K}hWєmkl ߹|R_6xn{:;qn֎ 6n,s;c-[wUuG[~OIqR-+u&Λ9+v oΐ!ShM;!>x3?l!pE`}}sqr yEj?3OAp"˚ F  FH!R"%"KRÚ³PD@)KFi4#>?<>ӯ/ӯCm:H|}`eqp"s ʀ3Y:p%<55~xndKwV>vE|xۦ)~65{`p"ޯe@?AoZ1[uǘHY07ᡵݾ{/---f뷿ؙsfϯ‰/r<ͱ"  *(FJ(p <hBX)L' 8.A:_y8+E >NNȤ²BA`EdfiAB,Xea9hBlyOǾ2MOޟ?9n տY]G> 'Y 迿Ҥ't'PNѨ;7'MHh(O?&)GS@puF̘H *'M0a* CYQ$)H$%V4VPȱkaU Â`H^yx!iҥC9j-}sE-o45񵟼-UUԹqKߍ;is;?`ˏ_ -#o^JOnro[Z9z?n*k#Yթmc̽#,[41gȿ/ₙ=;Pzok/yb]9W8ݵioRx_p_>ǣ?2A<:No_}h- nx~&_WquiŃvyHez*4ISD*"k*< e99@ > ^۾qbU/wsGv']tkݽ%ߗ??#A=8n_ `Z6{=> s}?k ?c]uٴP3ɝ='$n-O+kT>ˣ__GWe9OXS?. `le !sl(Ç>|Ç>|Ç ?u xdarcs-2.14.5/tests/data/context-v2.dpatch0000755000000000000000000000136607346545000016352 0ustar00000000000000002 patches for repository /home/ganesh/darcs-comp/temp/empty: patch 573defe88544e8f75a18e530e3aeaf6608951aa1 Author: Ganesh Sittampalam Date: Thu Oct 21 18:28:18 BST 2010 * init patch c8ec7c8b2df55720ba2c3a21adb80790363f421e Author: Ganesh Sittampalam Date: Thu Oct 21 18:28:31 BST 2010 * ABC New patches: [init Ganesh Sittampalam **20101021172818 Ignore-this: 6a770d5966ed23f56e94c08977507388 ] addfile ./wibble hunk ./wibble 1 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 [ABC Ganesh Sittampalam **20101021172831 Ignore-this: 157403967fc6753e0f2540535937da5b ] hunk ./wibble 4 1 2 3 -4 -5 -6 +4A +5B +6C 7 8 9 Context: Patch bundle hash: 846f06469d8639ad0762c33e2030e5c24ebb1832 darcs-2.14.5/tests/data/context-v2.tgz0000755000000000000000000000623207346545000015710 0ustar0000000000000000=|L\kl-DPQ/+]{v;!5 ̝݉w̮c ZRZ WU* ?*BR-QDEڊRzlCZ(;yιqϝ8 vlTY߼*s5@/6E^iC1+F9pP[$,~xFPT&_eDGvLFKC*X?H܆?IXn4|9-A;,DP@ df25&݈`!\;ĴqDaq8EJ%Y(]I F3{^D/ybD$ Ǥ~A e/Zd:# ] v pl`XdGC=nyA`9Y.|@N4EPS5pݑ^Y膶熝PWAdBĵ>Lbr j!AQ .#4%iQW]!a)嚮>e.^݈8\@dx&rό epi"]6 W`*m<L t:aXWNR j ~p-͆E(]( xvڠ==ǁM#+G~9WS.D Z8oμbb]2>6pv8D:.d ۅPVT! !~؎ QL'IvНh UfMÔu0{ naSvˑG1L)" lIb=qKBD.y*0xmг"4Mt N-U ܅Qٴ=8”OPGD'~%vq)06 H$~6 UIt -5k r ңLn+$b̕.`Ir쌩xv)?]òRaXqk(6.ڊZSjpYg`>㩍͑vIugi 5ݞdiju]d쏍60;1qn Nf:ϭvsWgi?'M};HP 'I t4 A({{zhkS R%\* @ >A]q>]&is'sv`1s4u]4.v_N BoLϨҟ nT+@ I`[Սmɥ IȖ mM >Y[^8aƤq ա͵B:4ꏹzpc6O զU^a Q,1:e"VGkFe\pڤb~u]vO<hBD?NOvo  "4$3oOEbNnf>FWy"Kд2ckG2;vyҝO\̕5V4Y"*gʚS-Y!dpyMQ|>32@{QYlXRQ``PThH˲"pbe8ohJ2c{=kȉZ"`$NeMTM, ,oK"X$u7ЪqqXUxԀ,;=OOloUPoa4A8O9eYoxҳt75%\syEZ 2ew nz&O}Y:yDž'۵rzf'+n9+ϾW뷫v}/_ϹyR-;[gg~oq8 jLK\硟WnX|/3/|ߧ}/֮S/ʿtC ל~ߨܼ v2GnxW//*ާ3{o{ݣ?i^y Zo:w+x{۾/߹=s_>z]0v I_$2o\n8_r/ i9x߬(\'?{I'xk^Ya ~}~Ƴ}v/ ]ܴrom]̲ܟh}W#_C,)X5Cxk*ɫaMX2E8n%"bFO©K0>7BO)H/i;ķN_\6D9C-oKtK2X&HI4]%K qBWCJPy?Av%âGW8_{ko7óGͧ0QU-Ag7ٻbuԤ?v4qTvk 3ҺܗQ3j&2H(Zvxdarcs-2.14.5/tests/data/convert/darcs1/0000755000000000000000000000000007346545000016000 5ustar0000000000000000darcs-2.14.5/tests/data/convert/darcs1/resolution.dpatch0000755000000000000000000000204207346545000021371 0ustar00000000000000005 patches for repository /tmp/tmp6648/temp/empty-hashed: Sat Oct 16 23:32:07 BST 2010 tester * wibble Sat Oct 16 23:32:07 BST 2010 tester * A Sat Oct 16 23:32:07 BST 2010 tester * B Sat Oct 16 23:32:07 BST 2010 tester * AB Sat Oct 16 23:32:07 BST 2010 tester * C New patches: [wibble tester**20101016223207 Ignore-this: 64b5a1e603ddf61e59421bdde45b3bc ] { addfile ./wibble hunk ./wibble 1 +wibble } [A tester**20101016223207 Ignore-this: bc0d30ac5170e1a25ccb20e6cb06ac86 ] hunk ./wibble 2 wibble +A [B tester**20101016223207 Ignore-this: 3bbebcf8fa444bdcb31ab799c6754067 ] merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +B ) [AB tester**20101016223207 Ignore-this: 8fa03d26b9dbbcdb50a323e5c58b16dd ] hunk ./wibble 2 wibble +AB [C tester**20101016223207 Ignore-this: e7c0716361e411645066f8a3c2eff769 ] merger 0.0 ( hunk ./wibble 2 +AB merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +B ) merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +C ) ) ) Context: Patch bundle hash: b23d175b10d6fdaee3bb25ac92b55723de2822cd darcs-2.14.5/tests/data/convert/darcs1/simple.dpatch0000755000000000000000000000047307346545000020465 0ustar00000000000000001 patch for repository /tmp/tmp5746/temp/empty-hashed: Sat Oct 16 23:28:30 BST 2010 tester * wibble New patches: [wibble tester**20101016222830 Ignore-this: f155bc27211e0233c23b8c0a757b8071 ] { addfile ./wibble hunk ./wibble 1 +wibble } Context: Patch bundle hash: 1bfa82f0941e1dcc13f9f94179dd6a7426ca0b6f darcs-2.14.5/tests/data/convert/darcs1/threewayanddep.dpatch0000755000000000000000000000216307346545000022176 0ustar00000000000000005 patches for repository /tmp/tmp5530/temp/empty-hashed: Sat Oct 16 23:27:54 BST 2010 tester * wibble Sat Oct 16 23:27:54 BST 2010 tester * A1 Sat Oct 16 23:27:54 BST 2010 tester * A2 Sat Oct 16 23:27:54 BST 2010 tester * B Sat Oct 16 23:27:54 BST 2010 tester * C New patches: [wibble tester**20101016222754 Ignore-this: 355914edd0f88f0ea7c2ef60aec9c2a1 ] { addfile ./wibble hunk ./wibble 1 +wibble } [A1 tester**20101016222754 Ignore-this: 54df34ebd488b772c37c3d43a38b0bfa ] hunk ./wibble 2 wibble +A1 [A2 tester**20101016222754 Ignore-this: 4d1b08c7274743e7d0d2f210518d5a19 ] hunk ./wibble 3 wibble A1 +A2 [B tester**20101016222754 Ignore-this: 9ba51da6bb1506afa2104326cd5df54b ] merger 0.0 ( hunk ./wibble 3 +A2 merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +B ) ) [C tester**20101016222754 Ignore-this: 295e8a851b7a936b3d08b0ce7eaaf2ac ] merger 0.0 ( merger 0.0 ( hunk ./wibble 3 +A2 merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +B ) ) merger 0.0 ( hunk ./wibble 3 +A2 merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +C ) ) ) Context: Patch bundle hash: 3c77da1c02a49215134a9607493af93d55608f56 darcs-2.14.5/tests/data/convert/darcs1/threewayandmultideps.dpatch0000755000000000000000000000507107346545000023435 0ustar00000000000000007 patches for repository /tmp/tmp5411/temp/empty-hashed: Sat Oct 16 23:27:21 BST 2010 tester * wibble Sat Oct 16 23:27:21 BST 2010 tester * A1 Sat Oct 16 23:27:21 BST 2010 tester * A2 Sat Oct 16 23:27:21 BST 2010 tester * B1 Sat Oct 16 23:27:21 BST 2010 tester * B2 Sat Oct 16 23:27:21 BST 2010 tester * C1 Sat Oct 16 23:27:21 BST 2010 tester * C2 New patches: [wibble tester**20101016222721 Ignore-this: 64432ba123d81c8f0e688b44feb8f587 ] { addfile ./wibble hunk ./wibble 1 +wibble } [A1 tester**20101016222721 Ignore-this: d749f48333e6ff2e994b1df71e76933b ] hunk ./wibble 2 wibble +A1 [A2 tester**20101016222721 Ignore-this: 6f006a52975a708a8038d52e5e39ef0f ] hunk ./wibble 3 wibble A1 +A2 [B1 tester**20101016222721 Ignore-this: f4d4b5b1c73bd6fa8abe6e5e680d66a7 ] merger 0.0 ( hunk ./wibble 3 +A2 merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +B1 ) ) [B2 tester**20101016222721 Ignore-this: 1d60b6c0ba913fff4d1e32ad26ae07bb ] merger 0.0 ( merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +B1 ) hunk ./wibble 3 +A2 ) merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +B1 hunk ./wibble 2 +A1 ) hunk ./wibble 3 +B2 ) ) [C1 tester**20101016222721 Ignore-this: 25b6a6959d19980ad16983a542c6825 ] merger 0.0 ( merger 0.0 ( merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +B1 ) hunk ./wibble 3 +A2 ) merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +B1 hunk ./wibble 2 +A1 ) hunk ./wibble 3 +B2 ) ) merger 0.0 ( merger 0.0 ( hunk ./wibble 3 +A2 merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +B1 ) ) merger 0.0 ( hunk ./wibble 3 +A2 merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +C1 ) ) ) ) [C2 tester**20101016222721 Ignore-this: c16d607216c36d5f7727c64d2ec103d4 ] merger 0.0 ( merger 0.0 ( merger 0.0 ( merger 0.0 ( hunk ./wibble 3 +A2 merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +B1 ) ) merger 0.0 ( hunk ./wibble 3 +A2 merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +C1 ) ) ) merger 0.0 ( merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +B1 ) hunk ./wibble 3 +A2 ) merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +B1 hunk ./wibble 2 +A1 ) hunk ./wibble 3 +B2 ) ) ) merger 0.0 ( merger 0.0 ( merger 0.0 ( hunk ./wibble 3 +A2 merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +C1 ) ) merger 0.0 ( hunk ./wibble 3 +A2 merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +B1 ) ) ) merger 0.0 ( merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +A1 hunk ./wibble 2 +C1 ) hunk ./wibble 3 +A2 ) merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +C1 hunk ./wibble 2 +A1 ) hunk ./wibble 3 +C2 ) ) ) ) Context: Patch bundle hash: 1069761dac242f9583871b27db2fabbd00d6f805 darcs-2.14.5/tests/data/convert/darcs1/threewayconflict.dpatch0000755000000000000000000000155307346545000022546 0ustar00000000000000004 patches for repository /tmp/tmp5605/temp/empty-hashed: Sat Oct 16 23:28:14 BST 2010 tester * wibble Sat Oct 16 23:28:14 BST 2010 tester * A Sat Oct 16 23:28:14 BST 2010 tester * B Sat Oct 16 23:28:14 BST 2010 tester * C New patches: [wibble tester**20101016222814 Ignore-this: c125275c671c210086eccb12de9f6c1c ] { addfile ./wibble hunk ./wibble 1 +wibble } [A tester**20101016222814 Ignore-this: 653be63c1f8a6f4bc1de1e45c0ae9084 ] hunk ./wibble 2 wibble +A [B tester**20101016222814 Ignore-this: 1a8e3f57d2baeca09f2dda003e4df58d ] merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +B ) [C tester**20101016222814 Ignore-this: 9d40b33ef1b73b9a950f39c4e8a75dfe ] merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +B ) merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +C ) ) Context: Patch bundle hash: c189b5635aed28be92cfbcf0de65c0f40c79da7a darcs-2.14.5/tests/data/convert/darcs1/tworesolutions.dpatch0000755000000000000000000000323407346545000022312 0ustar00000000000000007 patches for repository /tmp/tmp6805/temp/empty-hashed: Sat Oct 16 23:34:33 BST 2010 tester * wibble Sat Oct 16 23:34:33 BST 2010 tester * A Sat Oct 16 23:34:33 BST 2010 tester * B Sat Oct 16 23:34:33 BST 2010 tester * AB Sat Oct 16 23:34:33 BST 2010 tester * C Sat Oct 16 23:34:33 BST 2010 tester * ABC Sat Oct 16 23:34:33 BST 2010 tester * D New patches: [wibble tester**20101016223433 Ignore-this: 577185c51e4839dd1041372fbfa8515b ] { addfile ./wibble hunk ./wibble 1 +wibble } [A tester**20101016223433 Ignore-this: 580c4417986d5c56590bf36f5a125f38 ] hunk ./wibble 2 wibble +A [B tester**20101016223433 Ignore-this: a9f2335fe2dc972fd0bc09edc6252256 ] merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +B ) [AB tester**20101016223433 Ignore-this: cba095e78e2bdfe15dbdf2cb5c69cc6d ] hunk ./wibble 2 wibble +AB [C tester**20101016223433 Ignore-this: da2a7e05abed8dba0077e69e55bd926 ] merger 0.0 ( hunk ./wibble 2 +AB merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +B ) merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +C ) ) ) [ABC tester**20101016223433 Ignore-this: db94de3935df87d0a991c0ab6a58e5b1 ] hunk ./wibble 2 wibble +ABC [D tester**20101016223433 Ignore-this: 829adb4326b290aa6f741b3a15fbabfc ] merger 0.0 ( hunk ./wibble 2 +ABC merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +AB merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +B ) merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +C ) ) ) merger 0.0 ( hunk ./wibble 2 +AB merger 0.0 ( merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +B ) merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +D ) ) ) ) ) Context: Patch bundle hash: 5fc1d0ff89472d10a0b19ae4f7849b1b99d500b4 darcs-2.14.5/tests/data/convert/darcs1/twowayconflict.dpatch0000755000000000000000000000117307346545000022246 0ustar00000000000000003 patches for repository /tmp/tmp5677/temp/empty-hashed: Sat Oct 16 23:28:22 BST 2010 tester * wibble Sat Oct 16 23:28:22 BST 2010 tester * A Sat Oct 16 23:28:22 BST 2010 tester * B New patches: [wibble tester**20101016222822 Ignore-this: 88662d08dd524d92ad4cca6df0d643e4 ] { addfile ./wibble hunk ./wibble 1 +wibble } [A tester**20101016222822 Ignore-this: 2d69de402438481946682efcad5e20cd ] hunk ./wibble 2 wibble +A [B tester**20101016222822 Ignore-this: 9c8daaedcb674c022ddbcef19752d694 ] merger 0.0 ( hunk ./wibble 2 +A hunk ./wibble 2 +B ) Context: Patch bundle hash: 1e2ce71b56e4666c1b086b09ae351a6c3c768b8c darcs-2.14.5/tests/data/convert/darcs2/0000755000000000000000000000000007346545000016001 5ustar0000000000000000darcs-2.14.5/tests/data/convert/darcs2/resolution.dpatch0000755000000000000000000000236207346545000021377 0ustar00000000000000005 patches for repository /tmp/tmp6648/temp/empty-darcs2: patch c88a093ab344f21fc3af74eee6741db45df22498 Author: tester Date: Sat Oct 16 23:32:07 BST 2010 * wibble patch 9d61f1de5ae27b8f1678735b4741abe4a869d899 Author: tester Date: Sat Oct 16 23:32:07 BST 2010 * A patch 3b3282935c87c2aede246a42f5c0a926fae2be35 Author: tester Date: Sat Oct 16 23:32:07 BST 2010 * B patch bc42df597aa06b720f03367499e3dffe36baa9a4 Author: tester Date: Sat Oct 16 23:32:07 BST 2010 * AB patch 8efe5b608a6236bd136ead946ef26369207ca5ac Author: tester Date: Sat Oct 16 23:32:07 BST 2010 * C New patches: [wibble tester**20101016223207 Ignore-this: 64b5a1e603ddf61e59421bdde45b3bc ] addfile ./wibble hunk ./wibble 1 +wibble [A tester**20101016223207 Ignore-this: bc0d30ac5170e1a25ccb20e6cb06ac86 ] hunk ./wibble 2 wibble +A [B tester**20101016223207 Ignore-this: 3bbebcf8fa444bdcb31ab799c6754067 ] conflictor [ hunk ./wibble 2 +A ] : hunk ./wibble 2 +B [AB tester**20101016223207 Ignore-this: 8fa03d26b9dbbcdb50a323e5c58b16dd ] hunk ./wibble 2 wibble +AB [C tester**20101016223207 Ignore-this: e7c0716361e411645066f8a3c2eff769 ] conflictor [ hunk ./wibble 2 +AB ] : hunk ./wibble 2 +C Context: Patch bundle hash: cc43b921f6010f451b2dbe275b7fcd04c3862335 darcs-2.14.5/tests/data/convert/darcs2/simple.dpatch0000755000000000000000000000056507346545000020470 0ustar00000000000000001 patch for repository /tmp/tmp5746/temp/empty-darcs2: patch 62068c47f23550e3a32aaf652d1e14e53598ba98 Author: tester Date: Sat Oct 16 23:28:30 BST 2010 * wibble New patches: [wibble tester**20101016222830 Ignore-this: f155bc27211e0233c23b8c0a757b8071 ] addfile ./wibble hunk ./wibble 1 +wibble Context: Patch bundle hash: 75ced55c52362a8b2ff171b48751d19000fe1790 darcs-2.14.5/tests/data/convert/darcs2/threewayanddep.dpatch0000755000000000000000000000243707346545000022203 0ustar00000000000000005 patches for repository /tmp/tmp5530/temp/empty-darcs2: patch 349a0bab437265867f9af955d72127bac4cea1a6 Author: tester Date: Sat Oct 16 23:27:54 BST 2010 * wibble patch 650955997f5fac7fa2e14127a25ea5ac70f4dab0 Author: tester Date: Sat Oct 16 23:27:54 BST 2010 * A1 patch 476d8520cfc9be9b44299e6f4753de6adca83bcf Author: tester Date: Sat Oct 16 23:27:54 BST 2010 * A2 patch 4d2a18f739f8f4c384b5653a5ad03d5e77724efe Author: tester Date: Sat Oct 16 23:27:54 BST 2010 * B patch 81ba98134cf0d725e827318ca2753be4148568b7 Author: tester Date: Sat Oct 16 23:27:54 BST 2010 * C New patches: [wibble tester**20101016222754 Ignore-this: 355914edd0f88f0ea7c2ef60aec9c2a1 ] addfile ./wibble hunk ./wibble 1 +wibble [A1 tester**20101016222754 Ignore-this: 54df34ebd488b772c37c3d43a38b0bfa ] hunk ./wibble 2 wibble +A1 [A2 tester**20101016222754 Ignore-this: 4d1b08c7274743e7d0d2f210518d5a19 ] hunk ./wibble 3 wibble A1 +A2 [B tester**20101016222754 Ignore-this: 9ba51da6bb1506afa2104326cd5df54b ] conflictor [ hunk ./wibble 2 +A1 +A2 ] : hunk ./wibble 2 +B [C tester**20101016222754 Ignore-this: 295e8a851b7a936b3d08b0ce7eaaf2ac ] conflictor {{ : hunk ./wibble 2 +A1 +A2 : hunk ./wibble 2 +B }} [] : hunk ./wibble 2 +C Context: Patch bundle hash: f9974a2fdbdea580b1be0eaba951e6285f9bfb5d darcs-2.14.5/tests/data/convert/darcs2/threewayandmultideps.dpatch0000755000000000000000000000337207346545000023440 0ustar00000000000000007 patches for repository /tmp/tmp5411/temp/empty-darcs2: patch fd370912c8a92d249e00e7c91856ed9530d6c914 Author: tester Date: Sat Oct 16 23:27:21 BST 2010 * wibble patch ac7df6a4761de10b4c440a9adb39c4f0236cb519 Author: tester Date: Sat Oct 16 23:27:21 BST 2010 * A1 patch 121d6130551316a64fa7a061cfc44f5946213f85 Author: tester Date: Sat Oct 16 23:27:21 BST 2010 * A2 patch 513848985dfc5b5ea1533d56b597daa7317f35bc Author: tester Date: Sat Oct 16 23:27:21 BST 2010 * B1 patch 84edd5450901a4d31f1b49a9a6da4563a6ed73fe Author: tester Date: Sat Oct 16 23:27:21 BST 2010 * B2 patch bec254c63929d83d13929eec63f2e5e5a8aabbb4 Author: tester Date: Sat Oct 16 23:27:21 BST 2010 * C1 patch 0e08cbe9489dfc7f21e9528b4c6a7d06f4fec25a Author: tester Date: Sat Oct 16 23:27:21 BST 2010 * C2 New patches: [wibble tester**20101016222721 Ignore-this: 64432ba123d81c8f0e688b44feb8f587 ] addfile ./wibble hunk ./wibble 1 +wibble [A1 tester**20101016222721 Ignore-this: d749f48333e6ff2e994b1df71e76933b ] hunk ./wibble 2 wibble +A1 [A2 tester**20101016222721 Ignore-this: 6f006a52975a708a8038d52e5e39ef0f ] hunk ./wibble 3 wibble A1 +A2 [B1 tester**20101016222721 Ignore-this: f4d4b5b1c73bd6fa8abe6e5e680d66a7 ] conflictor [ hunk ./wibble 2 +A1 +A2 ] : hunk ./wibble 2 +B1 [B2 tester**20101016222721 Ignore-this: 1d60b6c0ba913fff4d1e32ad26ae07bb ] [C1 tester**20101016222721 Ignore-this: 25b6a6959d19980ad16983a542c6825 ] conflictor {{ : hunk ./wibble 2 +A1 +A2 : hunk ./wibble 2 +B1 +B2 }} [] : hunk ./wibble 2 +C1 [C2 tester**20101016222721 Ignore-this: c16d607216c36d5f7727c64d2ec103d4 ] conflictor {{ : hunk ./wibble 2 +A1 +A2 : hunk ./wibble 2 +B1 +B2 }} [] : hunk ./wibble 2 +C1 +C2 Context: Patch bundle hash: 7f2bd6324e6e1f2d4efe67f98696ca0ead048fe5 darcs-2.14.5/tests/data/convert/darcs2/threewayconflict.dpatch0000755000000000000000000000207307346545000022545 0ustar00000000000000004 patches for repository /tmp/tmp5605/temp/empty-darcs2: patch 8d6bfafe7ac2a628340563d92917da9639a8d509 Author: tester Date: Sat Oct 16 23:28:14 BST 2010 * wibble patch c0a55ca9dedb993d05d2779ca4f72984e87083cd Author: tester Date: Sat Oct 16 23:28:14 BST 2010 * A patch fb027d809948379ca6357d654a6ce8cf45235dfa Author: tester Date: Sat Oct 16 23:28:14 BST 2010 * B patch 7eeb8289feadd843a19485f493235566a2c48bea Author: tester Date: Sat Oct 16 23:28:14 BST 2010 * C New patches: [wibble tester**20101016222814 Ignore-this: c125275c671c210086eccb12de9f6c1c ] addfile ./wibble hunk ./wibble 1 +wibble [A tester**20101016222814 Ignore-this: 653be63c1f8a6f4bc1de1e45c0ae9084 ] hunk ./wibble 2 wibble +A [B tester**20101016222814 Ignore-this: 1a8e3f57d2baeca09f2dda003e4df58d ] conflictor [ hunk ./wibble 2 +A ] : hunk ./wibble 2 +B [C tester**20101016222814 Ignore-this: 9d40b33ef1b73b9a950f39c4e8a75dfe ] conflictor {{ : hunk ./wibble 2 +A : hunk ./wibble 2 +B }} [] : hunk ./wibble 2 +C Context: Patch bundle hash: ba3e1ce15840fd37358fcd43c4c03273d1779153 darcs-2.14.5/tests/data/convert/darcs2/tworesolutions.dpatch0000755000000000000000000000326607346545000022320 0ustar00000000000000007 patches for repository /tmp/tmp6805/temp/empty-darcs2: patch d1638af339ea13cf23df131015309be1915ae247 Author: tester Date: Sat Oct 16 23:34:33 BST 2010 * wibble patch 687f568b2fa78eea4431b49c76524fd75cce06bf Author: tester Date: Sat Oct 16 23:34:33 BST 2010 * A patch f1859e4ecd30f209ad08440964b3fa7b7bb8318d Author: tester Date: Sat Oct 16 23:34:33 BST 2010 * B patch bb4b77fc72cf19af130db16c173f73341d847271 Author: tester Date: Sat Oct 16 23:34:33 BST 2010 * AB patch fe0a5a17610dbffc90b421d3b40a9ee30ff7e484 Author: tester Date: Sat Oct 16 23:34:33 BST 2010 * C patch 4ecd0a21ee5b7150e567a83c150810656ad76006 Author: tester Date: Sat Oct 16 23:34:33 BST 2010 * ABC patch 756f4b3ac209102b5804ad71e54852b74a7281c1 Author: tester Date: Sat Oct 16 23:34:33 BST 2010 * D New patches: [wibble tester**20101016223433 Ignore-this: 577185c51e4839dd1041372fbfa8515b ] addfile ./wibble hunk ./wibble 1 +wibble [A tester**20101016223433 Ignore-this: 580c4417986d5c56590bf36f5a125f38 ] hunk ./wibble 2 wibble +A [B tester**20101016223433 Ignore-this: a9f2335fe2dc972fd0bc09edc6252256 ] conflictor [ hunk ./wibble 2 +A ] : hunk ./wibble 2 +B [AB tester**20101016223433 Ignore-this: cba095e78e2bdfe15dbdf2cb5c69cc6d ] hunk ./wibble 2 wibble +AB [C tester**20101016223433 Ignore-this: da2a7e05abed8dba0077e69e55bd926 ] conflictor [ hunk ./wibble 2 +AB ] : hunk ./wibble 2 +C [ABC tester**20101016223433 Ignore-this: db94de3935df87d0a991c0ab6a58e5b1 ] hunk ./wibble 2 wibble +ABC [D tester**20101016223433 Ignore-this: 829adb4326b290aa6f741b3a15fbabfc ] conflictor [ hunk ./wibble 2 +ABC ] : hunk ./wibble 2 +D Context: Patch bundle hash: b0ac3265aeb09b15b7dbc1dcf9447dae35d00a86 darcs-2.14.5/tests/data/convert/darcs2/twowayconflict.dpatch0000755000000000000000000000146307346545000022251 0ustar00000000000000003 patches for repository /tmp/tmp5677/temp/empty-darcs2: patch 8b8ee8c8e9bae5fe01abfd8c991071091241aa1f Date: Sat Oct 16 23:28:22 BST 2010 Author: tester * wibble patch 23373e39b77dbce4de67f7631221f2d873ae21df Author: tester Date: Sat Oct 16 23:28:22 BST 2010 * A patch 0058ef88cdd3606a9fbcfa00fb8b7d494db77481 Author: tester Date: Sat Oct 16 23:28:22 BST 2010 * B New patches: [wibble tester**20101016222822 Ignore-this: 88662d08dd524d92ad4cca6df0d643e4 ] addfile ./wibble hunk ./wibble 1 +wibble [A tester**20101016222822 Ignore-this: 2d69de402438481946682efcad5e20cd ] hunk ./wibble 2 wibble +A [B tester**20101016222822 Ignore-this: 9c8daaedcb674c022ddbcef19752d694 ] conflictor [ hunk ./wibble 2 +A ] : hunk ./wibble 2 +B Context: Patch bundle hash: 33bebb546403626fc8539d4709fbcdb99e47e94c darcs-2.14.5/tests/data/example_binary.png0000755000000000000000000001512607346545000016660 0ustar0000000000000000PNG  IHDRBHB#sRGBbKGD pHYs  tIME `AIDATxڽ|{[ՙ{zuKꗺ6#iƎaa`$^jBeHfHX6lTe7RT IMrv!y116/SRK?ԒZ!-{wlB׿5K Xp?)idž jadY ]PJA8lSJ XRJ5`J)@B< !d2}BqgLRJH)W,W 8u,"H;\3g8_M(cb1DQA0iP"AXtEfvv*^{?裏~5G¶mtS_WO} J)H)`9Q`1TP5~QU9 %WJ ֬YX,x\xo۶7PH~b@꫃?򗿌!:EQ(Ѡb!_Ӷm~PU{z_:u?x|}݇[neG@)@H@ Rf$V(HHI˟lٲ%$(5%.OiYmqޭ*$rq K(5|yy<7n{^zqܹwyo~+PE꫹"J%Ϻք8%I <-(laؽ{7&&&9rdۊ8z-,,lDKK <+CZwWJQw;ϡi gg y֭[o^\.Gbffկ~X,fJmRB /e(X9$ 'HQO~@HSUB@4lݺCCCw>}zuCG}t莭["H󼚪$S[(`*@!2P4oܤPK#PA5r^IJVXv-Bڷ~{׭:T-A*;=K]O ;ЛE0 m8FTAi J!rZTW !&4"#s`6@ͣ' XfZл:H)<98:r~PE-mP<.Ygq *݃H, CBS4d2^!QYIc%YJPTB `t{? )._ _А$o<,m]Xc&T\-$^zgbeaimöm=/"FG !E $BTuhj h=* xVRT6FE79`] <_FC bI@Ȃ7(šCFe^@2ą  B)@4&~׈?ev2Sk .jh-.h  s?{.\ׅRJWJU%eRꃡ/@2I 8 & =X@+ %97BҜ+\:w֗;LeƺV]"e?X 7p;44T*l6@ 3 ᴀը((A9FEetQHA {V ;JRq ֽsPkFn(PT+zACl~Ss EA:eY|})# `aat⃹AtL(!NӨþ! vM[W|ҙ7Lxpo35TyheYXvmǭG( F$)A 4d$QP!}*iT XpCK8f $~G%4%u] b ؖ (xҥȜ!yҀt2?ڵk#A&#R9.L.P ,"5f¹f@IftMks|xA$g~A!( qNȌAM `Op& (6u]LLLcZ7N+R %˜rSZXOK2@i\!~aD}vQ?n `]5!]=Ѽ1gzAJ?X#</K\$H_~Z>BئM."{[n}`zzhoofkv7`a!7ǡ$a= ϪYI$bwH&S `xxlJ)obT;|s EI z'\Y~zFxXi.MdTi"50h)8V P!@* E#JaBq)`DiA6Y{&@#$R9 oG]!r&` !Br8I߆q`;R )PH:Avmi(o߾_=zǧN[Xq!`u"uF{ z3jzn}BYxuR+ hĆ,[55 g ėqM(Σ85kP-go⡇B* @ssM$@(cEˊs ?r,R= k?C]z6 ى`]-d2/~q|[߂mۤ̑:;;C0GY?y Ǜ1r@!`Eoqӥؼy:p188gxaY'rIꬫD"mJib`((x#$k577ëW~siرcz'p뭷.qy8vI BľD"mغiVr.\JٿyjT殻RO?4VZmϞ=W'N L&s޶^]W+BJ)w ByyrrްVyk"݃i&<*PǙLj晦RP?p3,,,zcVJhœjNNN[o F?H$C8E mzfnnBlQ%U>/ u@ڶ=JvcX1F1?+q>zzllt:}RUZM *ewsss3HKK #%A)9 \iijj%D"bF!$" Xxs~-˝L&NLji]ThH9 Ҁ]$ff[(1* ݨ*X\Ӵ03 g=)esOZu1~fڶ=r*xr¯w@*`5b4iZ0i-Ƙ!ZJ)K1"#JՀ6TPQij,R+h$5ot-54Ҁ*:W PXtg佖Zf2Hpg1XZmr.*FX|gY6?c dR5BZq Qd{ K&4#T{Ϲvu%M H8ʳJ,EѤ $qbHT\E-D" ^úeGmDtH` r,y`,{I'9"c)TNr#{ :~_3cɣ#g( dB$&u*(1[v|2Y;GJ?-PHGgZ(T=xL(8(-FFYJhFe $e:XM{_|:;qӞ4?CTi!toN;Vd`uH$^n,㦧B; R6z듮/_J]{^cVu{ژwE^ fzVOYٯp7{OS/\݃rMȞ%?]C3 4)`_xӉJ)OKWepˢ"#.@KhΈ)EY^UQ4R%Ĕg$|e:u8 KZ?^ry.;po^}?z7{W-K T-qڷ[~W[&w߸5&zʖQo=+zz7E_znzg 6h[ZnLpuhGmz]â}UR373Oko{xg7=ʏZ,n=€A_^]¿޿t~͔z^7 kk_+/(%G~'g1#V$83t߉:ϯI6ڭ"sg]'̟m Oιoֶf[]gloUm~}B.oYؼ;')?h2A(j,@%CPhnHJ$E ɩ9F& Gv,֑XΜտ~x($)jq%cKKίq̷&aDt1Cð+jABmgLq20a(z#@u缘G=UA 6 yfD\R"i1RƗ b%y9F1+tltM;M+H4Xٴ27׵qn)nb&T&,&Tw3BalES:@9#,PbEcWNgZblzH`6+")B ƪBHꄬiűq݌ٱxl݌M/sA3#ҙd@?gS "Oԍ 5폸ܱIP(B4 vڐ F9W/*Zq01Q4qD0l#P1"ԡ:xqD H#Fӌj= :@ "J[E *W6 ;3yTx'))!a{Gf۝Yg$EUBB7[/=79Q>n2L 5@0MD=!f]̩s<3cyאY:Pa!NxM CFh@D% l&B?`Ȫ'"E"hV؎#@oP+R\j\2ڼ{>}YO$6`=JA0aԻq}2 F(`Q0 F(`Q0 F(`Q0 F(&darcs-2.14.5/tests/data/laziness-cut.tgz0000755000000000000000000001040007346545000016310 0ustar0000000000000000'Q] ty9 BpbcKF`,#?@X.P$[ܹsgwݙ93zy!! J(!hC94-8`^ 4ȡ-gvlk|#i>{籣^kh|2xe4R/H$7p$F(ฆ,rI;r6N(ɔA G_L*8OM SM?43O>G1bZ(mǿEUczP42jAeE`ȡ0GTi-GB|hd+)_q۴:D4EB Kn-)! & 9cӒled v zrN8тT&AtJH͐dC4Y1Elɪ5FeT0h&b$״-uYl.ˉ"TQsO@\&7H/% (Š"K)#zIG9'\!Qêi+%SY5,ÒM-KQJ,#E)mɂ +A%hذDCClIX,Y7%Wx4LKb-X 2S{h 6(X6mCGX&h/HzZeېT k ް X5y^YX$AW)j6Tǵ$Ȩ$J,vuȕʟ^ro{ڿero?uѮ%/wcwmWͺ;c[}~_6}kuo^yAZSmM߼e[On/j`S8/oMZuA5+o?{ޖ>2>8ɞ!{-p\_Tv"`S u?'0A5Qf/]\rpY7,0sǎ̒n۟puS;G)j_¶(H")DSmA"hjDTD0!""dI 7xAD^4юe2qg|T|a[w[N?^q3}})7;̛Z=})o?{mo m/79̩?:tqgt'4yɩXW9)gټ%=*GN 'ݴqN}riiܟz\ߜK|·Rt37zNM{_M8}Z0hFvS(DčP(cQ7 8u Tg#v'DF/(?czbZL՗9RP8rK#eOAdā?$0Lq$^FQOj_뿪z|̸k)<C 0$趩[DzM"آD42ET^45K6T"ƒҺ`bF&/ilh+aM x0:ʝhnZ d]dM-jD%auK=L':_Dl A1XTm! ,֑lf}08# e=]O~^ΧԨZk5{2>?̳Co:.Oge,s59'l'O8rܐC\Fy6G# H"%axny.|B}d8-69@w]E9EaX,@sqzڻuNٹmMY=Tkrl͉@ #l¢Iڂhʰ3P~\+9Lu\Zy8'\f]LE+2ؤ5s\Z$āG0ZSIdPxUg91,_!& å%' ǥ++ARZz$uҲ ʉҲ+C'J]'((-o[]NdQseIF͖V]TIĥFJnk /\m٥%e>Y¥ο, ZTT@5]#Ƕt\p$cT.vtzD`&{D>P3˚8u'JD't#*R㮌}C5@РM+!4yIMUPd`^ү k^$'z!I͝KWԂ 5or $9IS6*6Pԓ9ߴy=G`3s=Q(K{2`R?;Iw~X%fTItqmE`is <'dcA.*1մ ^^S#dAP?Zǝqe0awBlTC9l.+U-̣(x9(JeSp[8R@IXHVlA.EVl3Yºoz?3kNW{A.EiHs0J%]]Qy\hVJMEfFqEJݸ)ռh|C ^4/!*_l]`Epv%x5Ia ƲfB 0[ AdžJȐEMݰ4l c0!_dCe8'14M:@ߚF_#Zi o{3f݄So*iX:/Ȉ ST t c$EE [ - oꚎl2Oi GMG?5hlM[Hl""Ze[,Hn !bVlC԰+2j>#Ju}#;au ʛӟwlx䞝wY{zN~nl_M9gn9ܱtު/| O/M7^~rӼoxyoзȥ<+n}֔;o{>u!F5 &FFM u сqdarcs-2.14.5/tests/data/many-files--old-fashioned-inventory.tgz0000755000000000000000000025224707346545000022576 0ustar0000000000000000zGmU7 $%Zi *BU{ Ejlڦ J&:4E@ M ċ _b˱RT$T B%b;NJ)D4yfqw8r=7M5h/z5`Z*9zB]SGܡ[+nݡpx믕 FC9F!?N=VVRB Mk;yY{!Ƙ;nK;8AQgڈ6n}c/ԟ+kpտNu7ivGܝ?k@77xÍwp}6^_W^v,P5߾yG^u=Pv9cWb2Ay@̐E tCgQd+ocW&.F?0AW}{񽷼/~=q!I _~c'ڛO ?=1?J?23(- #4eF%[_ px{߳*S|_y=}vvSZ_{Zڟ!!<A$j8K͓nCA5꿭]X_ IAg?z~Omk߳* h7}Ū 843*ꦟG+w?3j{E+s$W3e߿edzS-:X,Fh-2D}H^cQ;P 3G=&b!s-zl? 胇k ГEXiC?[ܦ:K$/?JQU 7F!ȘPQq9'נgVTϮ핛 ?#;m&:U3 ȠIF?Ugzf}Vb!?Ep< yA+kEdЉόU^ /o`fS[_9J_,E#MbIP7f|1$Јa(,³D5꿽E.WkP8//q`kg7ZZ-}y bǐS7y&Y.t6gdy MH$):s>`0pfCsFW@J/ Pinߗoyel`*}üd9$fT(_?}&/?J_RX oLe -Bp\[QqoP9A<϶ϑ JvpD4qxd dl^]Ej  J/copB!>X-JZ!l9ȑ?/jW\G Oa< !\ ;Tc(ru 8Qq9U(|?cB'O}qŭ {X3 ){fFOu(_b'u~B!>5XmyZ0-09-uF'%O5??:k/no|mP)M)%`'#02 ϋ\cWR_A/FP).2$b,jF'ɲZ0YE%kP) wo} O,Uف)d9]`8< #-y*U ""K9-G%̨Q1_Q9OT)B!>-8&|\ -OMJEt̨Qqo) %ӭ;?xS&=EH1%]^7`H^Ԩ8?͑%N UW ?>-dc@0#:N^ϙє?3jN?u(LJw߃_yB!>CB+&Qv(g?/j4,՛!/?JߴgQ`MmquK99ɚh5??J/d]PG^za0P7ϯ>F{4ՠP ̨Qqo9_7?H_(翢01he %À܃_5??J J?nOB'O}+hlAA 易!$U^qI%(ofԨ(C/h% w:6B!>U*Ǥ:bN6UQ眽B|d2 C͌v_ B?>._ OW%R…"y0YRZ5ڇ, H)wfԨ8(?CKO z ڨh* 6 R2E Mόv_U(=+$/?J_5QI`7Vh4+}4:ђEϐ*_;>.{ZB!>5(Juܧd.hG\3^Ԩ8JP9 7~ B!':N; Vc"hL3f& ev5E/P]ߏB'O_"811Chz~L[m?/j_j0T)HM2蜬qR&gb}&gQq5?uS Xѧ$/?JD4%-f w(AStӼS̨Qqn_/1o⩻ O7}p3 8`NIgFP9O %/?J27&mMҍdͭe^눘ό*iB?5.ޟ ?o\t[`bT`LG3JGt:_S?~CB'O}7y!z:,V.Ad?/jE(B_()0<ո'kX{0 0^Ԩ8?P9`IB! oٸV^'Ww[;'xCS̨Qqo4]_'7 ?>-+l [k>Qz 2 )w]WVL4"R)[Zm^kwV|[Pf?Z, bFJۤ b $E4sE "m,BM,AAM#;s !99ugŬ]ٹR:PF# r|.?h-_ߙ-D(Jt>Q %`Cșk@YzaX#z1MG__N.7^!25.+o= _*w6ۇ~eF/_S1\\1)  y9X$v:KWGy'-_e_ K ƘP3WC9W-f@E ,Z+=꿎0nc/?h-'T2>J-e_W]0:_Im^a5F/gk^Q*13sK4!p:?~=F/gkБIUPIS2 #g25ңo'.i /L|"?h-j֬b ѹ1ZJ*:y:%-z/ۅ_ZSLT2j 5SfS֢IYzq'ݻ{H;j-"T!*eOiRhfYzoH]`nC0arUV!GjEYW*/Wz]{} K?hu-]X4cBJV;KV?]?ZMF/g/Ak͠h,S !U@:HW?|U[ӕ #00g6pX;KoHuIm-<_-?h-e RюuT!V"Gg.i'W'o4?߬S3U2@MTl-T5F G(?7/ sd7 ,uii!Ey*Ӹ?W FKVC%5QjңǴǓoԫ_bâ8I:y=wo KoIEVdC.7tsa+F,=꿎rO4@{lϓ/__5fkUt ~lQBc 末_QuiOwITiF/g^j9J:k ^Ggy%K_Vb`w4?_zcp 5*hΠ )qI\;K㿝KZs߼%?h-B8K@Tq+䢏9:,=꿎??T?gj ?h-b⒲1C_EcġwxSrV9*q'-7.{w\[q)DNā%1cP\2v_q?T?gj= #7]!U ؒr6(z9Yz?EϙG_d|)#DT5kr6}G#IM^w&=A#oVM#Fp ߧ p7Lsz[zi:'/_;S7C߈W5ѳ lLփ_Qu@.ir{_/?h-}4UJ*S2Qg ޘh0$Wz?i}8#F/g >_-?h--d5H3"wgQu-]Ut{_Bީæib= s(+;K uIm.?8_z3 z3z GP2fK:r U `}G 5?[/zA#o-3}gb@ Tc`C5`Gh= NWF[@Tc!Z)p:hvY[u!'e+=꿎f9%-{J_7!g4G3q*_LVBH9ZeogRUQ%-W?O7 Ko)j`gr, @ \3b<"tD-;K?OdKZo,?8^| 7~h)iLP>QY>FFT kuIWf9O<7 K?a֫d TD͑uV,=꿆F*y%-b2w*?j-FGW[fRMG O%uɒ U,W wp;97yk_h)jjhh$Iư*UrTgQg?=G44|^z㥇^wH-?_R)%_,WЪ%w_tz \|21F lrTl!g)[zGKo [?{ ZK4!9Jmvl|T,WzGrKo E_ڛ_WšbrtiF8t$wv?a%&[޽7}ozۗ~'oz| /y㧿K?ן s>]هc Z,=n4ab~._2?_aʔ-T/@Ġ XB5V WzO>i-Eώȋn AήSX8o-)MFңGy%-_nhF_OCF/a֨!`EEç=] W+Z# w_=%Mr<."?d}!Y3 Vy )LcrA:O-tI؞[~/_Q +GD|5at J? {8ƷW['ȥɤRb1+!o9Aw_]g/O}r > M0P9d[9SZJIm]q7>&?d->``!t`% c|aS;K#&? Yӗ<4|f6&AL@N5<&[K/>6W KXG)ǢsLbM*`jTВ2UYzGuIm} z0 _.qNJCOV%]B$JQ_.ik;oCF/JT<TO1ӨGwIW_!#o= s*ۨҞ8ᬁ8K}G iseCM[c`g9ij!) ;%v_ Ӟ_LO2W4ܪRYZ]06%-+wi=opۄ_ C|&PI%=\J ?7KfV@A6&t:g_Qu O/fo:!#ogTq&e  :GwIm^{/o2JUőwn]UvR JB'Z{o1F(H PiЋb:V(*pEKrL2X*! <=`Hwc?|3.<p~}=r g5(F %+TT9_'VwIm|['w1?Mզ(UNZ(~$O1&&%DңcϴFm_^0k9w^ys%5-cQeIgx+e5E-cFD^V9PJT§PCVzyKZsf/}3w?MVC)RS/5e*%E.9DmG&sS]_a1xm І\j@!BƙdVz2>i˙f2?_IjuK`SFI`61_&?h]/0w?MERT DD$y(61jn,=꿌iGߋ?1w?JrXP I %i#?K/?&GgN=]_'kB6j˰6 2Y&#RT6Տ:(o-=꿌46_|z^[a2?_c%]Fƒ'+@g#ң?]o#a3f)%oOQPpAao+=꿌%-k~W?e55Q|@䘄, 1PZYT46 #'Ma=7:.gՇ%k`1D*$7_3.i_2?g5u.btN5>K(6l}[K/tI#$a3HBe„P ]tsQZJ:{~2|KoZ~/e2?ߓ2Ja E0]ovJ/E?&sG|oa3//_"\fm@(PbW:;0Wg+< |  la ҥ? 8do2w?MIJlS~}!KQ@ %"&@ .jGmGXCx0k6&S ΉAkWFfG|ң?_4)18{ OPHTFHY'%IEze \"%M7ꑹF[ OWnj+P&8&9ЇD2XEXzr|Ko*xf^[^e_NWa'RKeP7Gaa(UJ/=g}o2w?M.#1D $JBk*>Hm2.i3}?e+MTFFmCS"hsPG_?~%M-W O#ɨ,i,F%( |&jGXOZ?7s?_z/ a3h ^: J^jC(&T2&f?;?]_';(UQQ#]z=$>2_.i_2g{.g(A$B6(ȥ,|07._&_==?e5򿒒RPE(D _ ZUBVzz^ya3*ޚ3ԖoA(]1YQ,YXzz}J.g_MZ).V HbVXzO _{K9)>7_c4]G_e5_#щ@S!>:aK/G?y0w?EWˤh@-$e0 */ 0_>iS=ti.g5'5f<0Ն` Ƞ5>Jң?.ij#׼<a3KYkm4&(P3ge,%Mظ3w?MBZM*$b%xi!h7_?!ظCϾ0ksרJ@}(|V$,cD,h)[K/AK?d8sb2?_ \R;xіH؃2ېl61аKok7a3DW 1 Q{/ ^iDȐ"[Qe?ꗜ.g=9#i];}1!Ru X!cQ&3{_9=L> ?}ı/?}=Gn?g5ameNX6UNXe.mGh.iS^󵟻0kRxpbHG2$co+=XtImߙǎ~kv?MCy0w?MQ@k-A͟lIH J4Hl,=꿈rX4?O ޏ_e5X$~br xӦPt"gIa?f.g) W<נ6D0Y)]J/QgIa࿹d2?_K)eB!:'>do+=꿌Е9|O4?''~c2?_Uv} *%iR$QSLb_177\x0kt)H #TVƊ"2<o,]꿈 ~%M|oO _&YH>l t>GS?) Y.g_4 CP-ΨJ= n,=꿌,]#Gߛ_; OwPV(%kDA:u(lK/ъ]{S?) 姮.gJٓOA AìQe ңpM{qǎ8a3"a dr()$'mnYYǧ,,:AΤdoMuk|P^r*t$˵,(?ABhpfJ:*9fTTꇘ [ۧhg{a)u2`jіsVt *ڀ2h+# w(!}R8'~uO2T*x4rW.&5)*o_I}-™ﱗKךD ]t08M!B }eWhm6!#_\`Q[J#K*:F9*G?cS!#owMIDmrLђ;ˈyoHz7 p{CF/]Glj_v92bj4*;ˈjt\̴?_CF/1*E~1꟱:Oxr _CcWf!#_{v*aCY dKց`T8X _3}#gUgo(?d-!x@mbM`;+# o#gUgο} &U1|.(WFtYwϏ_gkREے(d[VYHJ_1u?Cgk&߳_2%US|amSؙD4CPP`yog1uw7(Tm]ꕋxb66-pI?;ˈ3$=??o;?>!#oqљ*@CQT1;ˈ_X? ]tG_g+Ɯ!(Sc}"H:M db}e7$=tɟ)!#oS!Z5 $&g=By2b^HK/MɯxDףwPL^T8-(Fdt@N WFt?GcF/is*R :N.P#U>d _.4~D[l?ߨ_N@PʦG2b oHOO Kwc8X. ѬM*Xt٥&~շ Ek.'w:\m?䠵 k }eHKk+2eW $oH4p-:?H}CKM>*?d-?_R92RP\L"WFAL?{_{]V!Y)#Zzg @Au4h1rP9M3" `AQ4)Lw%f~Y 7|?{~_3Vеx=//.:y`1m?(!G2^آoE/`Lר5mWq1X1mMv2_.s1!)O}ksHj+#4gw{;ۿX^'?_z~ϭ+o-/J{+JNŔ\mժu\ .N8y`1m? I}~[tn O/Wl JSQY+#O?Of}+>"_kpPL)&ɢ|iPu+#濍@kf[_Ptl3 XzEqce7&!y?$]z5~)#ߌ9yjFB]k ׆K([r`1m׷(sDzǓ_2kOΚٷ&7h\NdW}u>!c#3/3)#nJ&?e=_=*UK IG\KT H+KwS{]+VkU^1Ep _Vce_t{k ?e=_m*E{Б dhZK =XFi<.|_3(WGrs$c6 *h6dK|`1m.)##:%)-ޖXB:ꐁʈo?ܢLc.?O? OO_1#vU.@ (?VF'.?/|{2k翢ѓH B2b?Dp;_kA 4mLWsL-9\b,##-e)#b &1 1f&bC?WW m?Ia@\[kR tZ (ߐt:{u>z˿ Of?9OJQ1Sn&Yx6L8e++SF/TV7.A׆ UTS$2bϓG1Õ])Ly3SF/=f.n1M!\0r`1m?L!Õ])L)# Gp6"de+R[[ ?VFa!+_(锲Ggi@SF/]Ug9[w\MQjJ!*jCcenQ7Ck?^*?e=u`gPBrGd,#濍G!fG OO_09S6dJqh;XFq>'֯W{O*g;ݮ VR/ZA*:s9g0,D/-gyP]6J2Xw?u.{=|߷O>??WsίP4_"-̾oCP@ ΢~GWf'SF!|y,RبM;a?7bLH6g`zWQ+wd[X rAs)rQX1mCk;I({>aHޚd D$Oљ\b*)3&=?zk~Q+XȅYa3Fw&3G?"]?<:E1)Wj|ū}պnTcS+#WϠgQ(;k`9%j|"r fw)gk2b !zyxa)WZ(`!S\"͸ecu_ߤ?edkEbC<\(!ˈoqzHzH({ f@P\$%~J6ۆ {6_?D!3SF'ͦ60-BOI*O?VFLzHxwwvQ+Gh)S2>ZG#ؒAːo⿨`g(OO/W"T!rcÉ%Vk )ˈ_!f߳wSF5b2'/MK<)[mJp(Hz_{P({J2}Sr%!^&k_?Y)W߈oSJ-%RhCpr05M@Ȩǒ~?$=5wT2_Sg)ن5Z3T1mwM{6_?,zH<ſzQ+( JS} QjT8ʈot=9/i)W_Y66B|NjN`STW6_?I]?eyQ+swAR d#N~8qhs*[Pϐt{?SF5@YȮmd _}jP6_$!c{_kb Xs6dSbs+D,#濍2.?6k/?~߼P(7n 1cWs!Eʈoq..gߋ~u?e=d TK&4jC֕fs&[3zHz{ϳT2_S`tj!fW  \ 2bt߽fd+?e=w\( FfWeA=?&=5n[_k - >efI{et=їSF`K\Ɇ as!ט Vˈ_~]? ]gߧU2_dj̶ .'Pce7_.A?"]gWV2_> gki"@1\o~ǽSFSB$f싰3TˈoC!V9W6rE|&]InZR,#濍G5?e=]|mbȵ\}LPX1m?.ӓ…? ޤ?e=_QYs66\lc?XFywHp.SF$CbVޣ#2bvzoHp.ܿ?(OO/WphTa39Ja*`jJ$ce#t;=)\ůhO+OO/! %f/ʆbT(N)7C3=)\ySFOKL2(TKFg)@'2b.I}_~䷞R2Ͻ-P1bmdPV#իʈo?t=MO w/}Q+w?-w 1D\U SՅ$ɐ1?O*OO/i $YgS&|}5J2e;0]z`_SFddifVp"fX1L,P+#5wzR}ŏZ({R \l)a<9' @R,#濍THWI'~ߪ?e=_9N TS&19̕h*ʈo#![}(OFۘ͞Z"J,eB:>hCդ YyVoHE76" 4$f0)S:CبPd@5N/jeSoO{}i7<sùygcuQ$WF t?s!#o|5{"T-B\>}pQPʈ$!'˟?2fߪ?Gƙ Y,;9yD#iʈUGI}/8~#/CF/7+r9= JZ{TSCeW%{/T[*H $[Ķ `4Zka _=t]_pWk__. '\ RqʸFMAIחu 7?WDPָ(`|k_1uFC?,wX[ڻl &W2udumߝe'gH:a_Lx oE[=*1&А !}e!K73__:AfU\YF yoHzyG_g{uhT\ Ѥj(R rM_jyt'!#obME ۢ3_1u7V.?Zq}e oIHGlp.XJeYF_+!'_gk/FQQSRN欕v +%./9^LG Ml5zC`SV5wDѳgg1u?,uh uvրϬNZ`sDS(%[K%{yg1u,iϺ_jrNDLU^լBŴV )+#濎gZzo"?d[q+E&hM`h:Y퇞}}eWߜ?!釾CF/jd!Mlj*SD6Jy6:? -3s2*Ⱦzس!4j4cQ2ؖ_1utKע=XJMC( 'F/eLϨWOpo}!#oj"T\ jXCц3]U|F/v.?_=tǗ?,?d-" YcD4Į( WF'kF-zkCF/|/5Ujq8zk}덢kʈCZIF-צzNj^!?d['ImNxV;3y]U;ˈ? d:o_o2yD>hv\4*Tj|Urg1u?*tu!#o=PD1ibJŢs1VAGFa YFDžweiI!#o^O̾Fkx*5 YF&?$]WGfkPQ\ tzkU1!¬w^j_1cO[V,)R%RR*80-|] YF?6rHOgc!#oj8'LJN 5E YF4!å'ߧ!#ߊ׭ۖ_ )0T > Q%O}e'!="?d-?)9 L`ͦʈ-GDŽ_g{[!QM{O*Z"D\S$WFd.q>x ?d-?ߙ{P\A  yW3V+g2b/.;2ZrT\"@qIjy2b7TrHd_aӗ|CF/Ibu{pSXAi_l }eo?!^u>ڧ~]O} _g䅯?KWkJAWb-Kʣr9D9k2b۔QJ bǾvp]ɁmIFkLq jMޝX,#濎DzDztU[c(VzvVOZ;ˈbK_'6[N7х .1IeWQ;ˈ?N\.?'ߛO KwٕR󆓷ɪhL)u5g _t?oyD[\a.iTU9jO΃(%YF&oHz?_o2|MCd;="^; Le! G^s^$?d-?_6UW4S0*E1*AY:_'cF/B(Zո9xd,WFYMHd_OK#v9QgSPԄɔw_8.{ ?d-?#S[щۺ_:T1*],d;ˈ1rHO*?d-?[sbД\-k3dUI S:g1u?OeCF/\NcXrx fFP~(WI}ߵ&>'?d-oXcUGj۟5ru&ek-u&RuvF1 B]q:_y?7\iDFmK qZ,^>=O?j_o^1ۛo\}7P^sWDD/߲+Ts jf B6)Q_лl c?I Mo(?&?_rgŕ|MU>df2!Tc*oS?HC"_.Ƙ"7 FUkA/z|PH-s)CxïT(}Ze!Tߎo[pC"osdΌT d]+ѹJ0p=Z}e߷D/߰i^%IT?lH:f éN/zt_>BzydyPL-ƨHLDu %p8U/B -_/LFH-FebBQ WbY/z9eMw]!?$?_ %rDj3\"(rogt*Oo_'D/tY큫cSk3E'.4gFEŪђ1`~OG1u?`߅?F?%!P hbCpNQAU+vFa ;?]|UH-qdb#CHl!(d'c?_?^}JH-SrUcb=2Q3zᯋ;_7q_e6WJVpֿ&$gE]h7~[j0µ*pϔXk1Uc9vǧ|߾ZH ߨBIQ.蔜 ]Jl`U&_:e߅RY_2TT %טkF2MDk8U_:k߅'~UIq^UFNIO$hD_Fwv,>F`?.M% BY'/۫[eͤs~}@Ⱥx\_:?TBY'?i!Z dEvKJ2v1RwFqBY'3*?$e1s d]J";9ķA/zaJs7?7'?$?]RUX#!dCbT}c?H.4ExR̕~[$o,Ô)¤O6T $=c?.?צww|@H-{808mq.C.Kz.wF!o]h:?_WH_ u&Qœ k0Ο Eҥ\/oZi:go1yɇavdB(Gg9x`*k8H@;wfϩC"ostȾutK٪&zJ^ǜ;)fϩe?2U1X2i $Pe($Y3|#M7MOoE*%XkC-[ %(R=c@]hsjMo+{ڢ5WRhM՞:J}cjԲOSD/߲u2:+6ZD.)\wF+AgN-4}(K.2>YIQ/Stʛ>'?$?_+eЬ Jx H\sQIAwF_]hߨstɻ.9&?_YZ< ސDɺ8+=cLjmF/[uɦ2N-RKXJ`9g (=cP~߅k0GD/_aBKل"Wp96HMQdGc? M-Oo~wWH _┋h1:.1rɠ$:&d_:gӅ?j|?~[TQƇZ-{L*+Oo_w:1P߅?j_}C"os5/%rԬu`TPL cOchEwxR7^H-Vf`׊md GR@/zwC-Óߗe!Ė5>kJlRLkd}cBiFӿD/߲+QSLIke0v%P (=?-Ó7!/c1=c!!{XbR K;|߅_gD/߲/1jv6`L'"'Bt%Y4hׇ9/ÓSC"osZ+ʼnAGOZWG |,=c}hExR#w[5[]1!넧z_j(vvl7e!`1ژ L5_"MgMx'D/߰a&*ZNt>;TXbrog:c]hWy[ (Wҥ1#fR`vFQ]h{&?$e%)ZS*7cŬUZ{W_Os4?n[n赳I:V2Wg  -òOS[6X`4l3\Ce t_:߅a?_/c"os&TiP@&u::L_3G߃6~TH-:W:(V'g6foRc? Ms_a:O_eW `!8Ur~dMJ Uh;_o`>x[e) ptT d%% =c߇?XaןvC"_4`P #Zh&[}c?]hk|AH-(]u>T \qY3z .4=O|[WZCH5c8j9_p1o^`]}{"?$s X aFzqȆ#c?@}hŷ.?$?_S>xV읬h>w+߆V\t%A,#-roHzпO?CF/$ۿCUU!Eh`2b5GZ/L|%?$?d-?_}H=9TBXo?ٗV"}e G^ݿ.!#_7W`&GUX"%2bIWiSCF/WX딭2)$)TbTg1u?V3$]Ӵ_x hQ"gCJj:?roHh^x o{_T>cnR@\bAN&8;W2bNϘtOWKW 9pGDW=fW뜩)_1k?1&?} xWɔ"L_1u'[ I}&߷>/ Kהog͑mfbʈ㌜.KM zm[@d!)-(Xwg1uHzܿ?v 7?wt6&jcl*.LX:??$]ǿA1#oYU-5^Tb(ۖ33m;ˈ?rHz_/?_g;Z;+@%U"X@}e./zo~_ UFiA0xȕ#ų7 i2btWO=2JT%Y"q4:"m(1$v_wzoD'kg K& b$Ԥt˧509M,ߝe_P I}^{!#_Ogo%s.U%{ھ8"y:?NI}_O/=y Oh(6mBtе6N,#濎f;$]zד'| KPȣA 0Pf2b_+?koo|ebwO?O[.) AQPMJO:ƪz2b#Ƥ=ߥ!#op7T!Z\A2H٪*vH?ӿ 7?עb)smI\k1\ PCYF'?&=c~׿@[d&lNs5a:O,w_;$]\8O25qĄM̅$ TʈQI}_y Kwڶ%փjd8EJrg1UדDpF!#o^.D% Qjji ju}eAy?&][o{ OJvb rWT*(YFO?$]7=~!#o+w" 7͜TSnQ(j{ːZCK/NK{ )bgBHo` 2,WF(!k_N-߅_gk /:O89պ,;ˈ?U}?2Gr0Fb膫a$WFl'%KKϥ}w z?!hMBFy PZA-j-"WFOroHzO߼I[Cp5g#_*&CMT>OQrog1uwV!*c͛_Q[e_!Y p]/^jʈQW~.{J-;5ߑ_gk 7XUEOgҿ&E|O[[S.V)q0} jl\\{.rg1uDw]=  +*,0u> NѰ1TA:O?y?&]K??=!#o6ijSߖUv%rT3-s)(,#濎'Et5/v_V!#_SM`-ZZ*G^c!e8y?$]}OG _g{Tbme4k3I=`;ˈ?N?$=_o_xw2AoB5bBl,#濎4IKc%?d-?]X~!W=]C2*Yp2b?HzwW6 |0)Fà}X:Lt`+ʈ}e@~.M? K_Xbq%6cΔס*gMtDr4}eWߞH.sK-?d g+'24ڶa`œ*)k1[Ft_I=y'?uI!#_/*V4f(*ja+#濎'#.'^y JM+2Y!j 3%-eNC﹟xA!#o^޵\!@fh?ƅ_+#濎p?$]!#o阔s bNHQb;ˈM{S2XUv!T\DMa6J]4Z3W9_ Gau_CF/䬅bKmIAt}2bUu;ˈ$.a}d=S[5:8j*|#5N,#濎'5/K#)CF/Ld~qYEB Y;F9-eWNDp/_g{`#8"kP>f6915d:a 82bXϐt]X`s -+Р4!IEXsY H!3RZVCAt#Pp^ хT<3L`P)u]tzQiV >u}a7<3<߳f)#_ʅ>ŗUN(acd2??&]=yɏR;?.w1#pIX !{^\[kQ,#꿍u1"!3ӗ_/wgXyŮ\<QP u`Qm? I3V{{,*\vګLcqu$9&J.f< j)#Wƚ EnOs2 ʈ_YH:Gu)L?)#_*G$p*|"ZG D`ceDh+CsSF/{-[US0.`1eDX3+0'~"?e=W͊['V6ZT|(Og]-#꿍".?O o|_/w:[_&WRT S6<ˈo㿙rϐt=O ӿ+?e=BqhfmX c֩XQk?t=O }L;?-א:CSj#gʷ%9deD Kݙgأ?$?e=L*jcKI`k)Ɔ2o'YtҼ߇_=?`B Pb3Lke@?XtFOW;?'V{?\%aPE)h]p\^6O1*>)Lꇞ*)#Tw\PE"er0%?֘ 9XQm?CWIa;ۅ_/w]@456TT@ j2O.?{O$)#Uq5Tuʡ '2h9ˈoa#.?{_|f)#IZ Aj"Fe5%`QkQ.?{ qhsSָ/zƢ ?XF|C_|wOO_X4+L-*ԋ1KJZQ@,#O_,tD7=坯x+>r[9sϹMwox_=  bքfߐu4c9wR#O=)4[o}糄_/wf "4ƣosb%?VF󟿎zH߻\߽] w^K:ǘuk*`x@p9,#꿍c?^/W +Wm𵵊R<G_?-?e=P||Ϧh0X.|`Qm!f2_mMt&s5t E,?VFyO.?^aSF/jW5gfu`Xˑ3C{_SF/-/ xҎ*aHg]*:cdhQm.?^abޮ_/T)բF`vV'k/`b&XQMדX G'es +w$#8(!/)W=*5 3n25E7O!6Ʀ-,# Cy< Z 'g8%vx0&*c4Zg `QmhDz7羯OOWX 7`ٛ& #`XQm?.?o-%?e΄9AL6jG GeDI]_{ۅ_/w,&l\ INS0eDrϘtZ?7᧽ySF/{΍VUzPM.ʈo㿙+CGj7> OO_A]m.چ WQ,#꿍G?"]w3>M{muK&8TDu)UE_ JZI)'?VFaǤkf';_/W[}"/ Z pΦbʭN 7Gkf]=a)#kX % c1l Pʈo!?/OO_FBPlb8|w++[A?"]_e}`^SF/QTBjTk eDXǤ}y_ OO_$P {mkXQm?!?_ZbN;XFyWI}ߥGn2Erm$6c0 [ A.?i2_FS{J|rh4kCM :{oM)#$[X$5\ 3.2oߐtgGG{b&CYh j9.\.sD2 G_=^Qףg5]~S*@aVqԚ3FHeD !2 @MrŪLuAKTlMDs &Ii׳SF/;*ת)Y )K@SM2;XF'+9?$]iw_/1:Zd9ЂN;eD0 ;?%SF/k 1 #;X C,ˈ_ 1*k_/WU ђlhVcH6O?в?$]2_J`Sx89.Y2,?VF'ó OzL>G 2l+m̾AXQm? J?"]=?z@;?,w6Z;&t:iE`f$ˈo?)L}t_/wRdlE%dp\R$_. \K{,#꿍tAgw ?e=k`Ur^vU*9iMceD-.?Xy{_SF/kT>j`sl.@xceD_~w}D{MNg %A3Dh zIQwA ty_2_S@YS\#&kUBP,RdeDC?^e__y GVks Qeԡ CI,#꿍ߐt/*?e=;N6^Fb1&#$]($ʈo1(!?{g[VFI%30ÔǬ]Zsc5 VD4sP, 2I#)tFJ/:s?Ë`0E9j8ed#e탰{xwƻgg_ew[pj׉&C6Ko:?NowW t-Q5X@hlA3zIM.4]Zp_eW{;\ M{o:%WTU1st P߁KN?D/߰q&uĩ@IXyk6GTXlԱzU;Wool?O?&?$?_Md \@aZd#BJdgC"os5c*j][6:UT891u?-?Ҿo_ckBÿB:)b&.1u?B ?2?C"os]4s ٘AҕْJ^/z?_?2=.?$?!hj%4PJ5?O3:|cIƚN>_/g_/_eWbrT[2dpWSt`9g9,.4eK?jK *A!>׺jb_# =VMoS_Iӗ_ (suc -.c*wFae|ӏ!F{1l3a.MHQ{ TW=c߅={D/߲;gK.@\lʛcܰm@ =cׅ.!?$?_UZ^1#R:8 ށ+Hgo:߅?O G*c"_K(ɫ J"b6)ŝnue1Ug5_?]hk:!c%J%C 3AaZq@_cI]hӋ0~QH-u4k)z.h*&2ecɖ0r=cjy MzF _yJH-8d ձ<[9DŰwF!C4ExR{_e_j FQ*ZrA*dB5A;0]h{xF?k!RW', J6㓂]_9O>}EgxRQ$?$Os5g Ft᠏%Org:M(A<__W_*?$?_sUu(oX9\-ry0D=cGy -7cQy])P!P:}.N/z| M_O_e+WS jԎN;G5ۅ?Z'~Wc"os5Ұ,x8g(!kOJʼnwFQ(.4Ѳo_i~GH-::V51*h6C=R| M?[Ֆ T;r^Ec%Z/zOoh5Ss~MC"osUcQYkm}4l@[c*Vr):'=cπG7W_eW.wnLhg+!%g_ B-f?KC"_ѱ19hTc֒ 0;Z?ߕ^Y!NE%BAbr&&orwFAwG?_ew* xD9`JD18vQ~=<]hUs6^>Xe)M.sIAE -ؐT1Uc_oY/ÓHl=D&gL%`V8,f3z'oY/Ó߾/?$?_+u["}`Q5~<QEG_g.4 ^'^&?$?_gKbbTeP 1u| MìIaG>_=?rN#{wmQ>P( *ؤ2aX_:#MmO׈_eLrxWuJù?T hOL_:,A0ExR-?$?c}'d:ŕ(,=S]hfO oD/߲_B5UP0h@d^ZC1u?Fa0[^+?$?_5}OXc SRyvFDEwxRBtxk)8W#s:z:y4S1 -g.]\x Cgw umE*F咏d׃!Ţ-8Mc_u.4>_\tNy8$`dU$r>YO1u?ׅϼ7_zXp ʙb%F&#vFwv,f=q˻UH-;G°"g}D e{_c]h3{SOBH-5A,^2el*K~XŐ|ogWWc߇[^Л榟k}=ygDP\RS6[([kMDdIgg1$g_3~K!"j d#y Ygf}c?g_3O~LH-DBq 3&b`lqk1PA%=S߅?O8}j+a#HM.{^/z M_t'GH-{o}8b4(_wvlsD/߲kpS5sLΒu[\M}c?]h;[`ƻ_%?$sU1:HOVmH: EJ=O4A?~vQH-8E1YpjR:i,Fd\=FuVouww(?$?_ɩPSET bΨ/LcOM>|E_=d0dKIdU*`0{m C }co4?^؛9梜O !brf\Bg:]hR?,0IH-r>ݞ0j 0L_*5/we\Cw>ΔA" a'Bۺ4V] 3B\W5L$#>M_R(Lۙ0$F"PTP@CA box~03gOF`,: 5 ]$&_ňocX?Cnr_ogݩ?%_ɄX|&R c*cPkG1t =/O_;?Ba)tGޑT5dX6_?A_}y{5t곎9X+d /8Ec/B]aGkSWKϕ$!EMqjQ0E5^?#C ~Ϯ0K~FJ=?WS062C qZ>E1;SkGwcG_{mwaWX@B4 Ѥ8|bo!tX`GV)Qw~ -%R+1\nU%8y<۔c]7zo]9?wG_?%_SF=Vr !XJD[ s0FCC?cK (RZKhj&0sj ?#;S_DrAĴZRl9PCM9۪?#_>=5OG]}??W[}+TD߳;B{@okCz!*DkM_'WsWKZ>5B ƈu|] ')QjHB ,^w>(w]wD߳{- Tjflm$+ۚp(c1b?cu߿E?%_)3gq0R U*Fco$A?+D߳kB%"G[ci}28 C)%;#=?,XFDgs/)P02۬?#$zw?cSWK5PH>BI6Rm3D!3JV ~`6f}w~ߧ?%i%&'Y`;8EL@.1b?|=*)Q.54i{tIMT_4Z~?#sh]wl7^s [J=c  $&F3F`|"w0F}]wl7~Oz{͎d۝EJ'Z8 9l!l1bGfusm|;D߳k(HR Doj2ť?# gجn= )Q<%"Rrd^?#nͺ}AJ=Ibv +̓>g@.+N2P!Mn}ODߛr@\r. e\Oňo?͟kw]7{/6_ɅX-T[LNL[D,Fy~~?1GOTJ= X8ZBt"29>`6g߿Lǿ/O_cXO.]Ɯ0;P$Pkt?RwO_g/WΕJe|M 4/ G&(coLV??]tR_Jm!cʦ Zc `&1t;R߿ѧO_;0]>baOyb!dc1b~wwSW&roܼ"a?#ǫJޫ?%ߙ[6x-HL6iSWK%^5b CPk]?R/O_g/W2|VRDH!F4ĕ-ňo^)\~O~EJ=ڀ zxR+)8N:V#!t??|_@?%_`(aN&Mݏ-S.`0ƈo\!t=|p;?.D6L |AZֆXUF?#Y}sO~g??%@d Zl&$K(L?Q!.R~'~SWK=DrI%C* dcz ]y={Ԓ7 fǖ1I˛M,F!?{zu :`LkBHb$VCRTt>mim R$E K0JPВbԠl?4ͤj*{wO!9X_o˂s.?-0a3u6du<۲bATTe2Dpza3EIk/'ršBV0$XF7|?G s C#K+)r2bWԂ?"]{}6.g9z/*폔IucZF/#>7$sW={?~?^og[>|i5?_V,y[ ILוֹBme_ IOG>#xsyѧ/>;?ukUX^JC*i/Zd2b/zGwHR9o;0kT+LeOId/,o,Ctܥ Wv?M?[4wп,VPKD dVFeCwRO}_n7.g9_- 1U[I Jh!XF%C;. ''YTm,c &bb 992bWI}w?:.g V)K1d~)r.`EQ&)bo+#濌GA.?}~o} a3Y"*A@$5 u@!x<_XF}[~keԎJGIg lmi?ˈ/# C'n61w?MOw1f F 6mJBc2Q2b?C?]f_đgg2>+49z͏, MB("[1eo2 ‘xa3OT,%G$b6uOuBˈ/jt7/e2-th(ȉJ1∯o,#'>?&]Ro蕷,a3+8" _zƘL@7_O_.j7^e5?_Qhz uA&LB$do+#濌?:]/D*)( ;<&`)K5[1e?Ptw?eO}RI[bƃ/c]K]ao+c濄G&?$]йMa3wIXBH*1Z.Ĝ|2b?CgoW '; D& ,h1hb K(ʈ/ #?e5=XWW?- tvo&C Fo,#'?oO0k򿖊]LY?}bJ[1e?s/Ny '+it% PiacP$me_?J0_l>uט 5DZ PB֊ e2b(]_91hBN Vc2b'gt6.g^PJޓ1YǠR}VDe;.?C?.gn\$LE5Q_s<2?R!;;`}$a3|2&5uVXN)QBfo+#WCwv{_o.g5_UP@)- !gwc1eo?s7޳]_UQ9F.SJdS|)nXo-#濌HW\;j.gr&i &]0PJ:2?I2{Ke]F.$̖TVuE]me߈vCe9um1w?MOw(&aA26õDUgo+#濌c!Ssn_1oa3b}YM6:ZJc:_<_H~t_7~d29wxįIY_"HJM 1t6ZF 5H~1w?MOW"t@ir9SQjVF?tW7gpݍ]_g[63,tUKRio=[1eo?.?5G!.gjG`)`PZHKFhLmG2bh~t]t}5]2sI(- (=BTهx,VFISe5?ߕS"D(璯x JVyi|6:e!@;מ|5a3_1{MU([WWEPU0oc1|J??Oϝ~Gxԃ<y0kK" Bp+GԮdk,"XF_?)+ I|-O_ǟv?MO |.:鬋ZO (VF I]%-0kJޠhJl M#kr6 ZFǤ w3w?MOא%pbT?Evdo2v`H]ɓw0W-ʤSt`J"U (KH$rZ0_..]_=><ŋ wY :I1[82b>0g3]_tI%4J*=%g i(XFt~uza3' ,u4"@ |2bo5Dz?~ '+y*SV&*SPa066H=}~0kBHi㠠F.DTAgo(7_8?$=s;p]_0_T0  No,#濌ЮC ]_U3XY9K2TE}l-#濌xB~jO>] j+A 4E+E]d)Qj7_ct3w?MOwDp)u ߍOV&b<e.b G=XFLz2?/~czEQV8CEXQMWIrW'O [Qer&kb#^ʐBIrr2?c_ս?eOvcbkk~\UEyceDkw5?W *+Y-2P"Ep5rJYVeD7$]a_<}V Ց'aZw~W\ Eʈo㿂w`n?n/:ʀ_GJWq:jC,ld\bVj?VF'287$]77^2?7?'e*mY,#꿍8.g;>ʿOWUъ(LVw"b[SOD'=XF'3&]}o=S3O"RM%Jv4(߰`u 9XF|GvwQOh#~5eKDJEKH,#꿉z8Cg7Ɂ j5'g}ՓPVjE AkXQk8CoSJ%(Us#bt*ZL6Z=ˈo?gH۵y?|?eOfr2P\ E NXQm?RaH:!0O_ƒ2?79:H٤l/w噃G;+''=KYd  [ND)"$e+#꿍_`oHߞ&}2?_m…認zIfҹ$6Otٕ=)LOOf,SMAYVȐJ*c?XF'HZړ|OZ'TIꈪS&J-7,# Ǥ突=)L73?*3Wrk))r$]XJ9$ˈoL3G?S*T-5 ֥`mla)^YՆI`Qm?iDz7=+){%%l5h%s.5>WU^N IoqOkb6E̖I!h2tYEWg{6!_;kyx#){AZsr˭p!.ekceDL',?~}޻*s2IȤI:i2?wHzo-?2?/e/Ū 9gJ4Bɚ$IMɂ#gV0){WUl2%l(32?!3+{R  .l S mWJ2irp|7pϘt=)Lԛ}ʀ_s0YYsi m17RK?$]fmO ϯz?eO]VUarS(r E5?VF' |?$]O?Ia'2?/:U8Pk^y0TߣeDHHzriO _W?en%OrmSK6SDHŘ ?VFߐtƼW]%{6N'1'!E* NRE,%WU.)`Qm?!_w+o713?//ҖZU%[ 15ֱ6O#pHV=_W=WQI,LUl"gHe2؜eD()boO }2?/̂sR=(8fUK\2&.?+_=~y?eO_ޒoKd 5Qd| ,#꿍O9 I]ko|?eO_v.륌A(J3IoLP$`Q-b(ϊW_}i_hȤ[_}c>r1`VdR2?Ο/ =ii %^^3d֔XPSiO2?!b׳}ϟ KMNI&!'Jմ/df$,#꿍j~=xO{"S#.6TZ b2l4=!c=?o){P*u"Dr5?ˈ_ٟo?o/);?-W]8RmZ%icj Yg-.^r_}?ʀ_J) 9?Z}ak2o0I}^r5?= AFy/hesj7Y0kv?VFgc_9O|?en2|]HՊL3jkBT?ZC/|#ʀ9'WbaQsc5& w6Ӌt_{>2?/5jV:VMH5aclu!c?&]zy?eO_s֛cvXjq5[gceD I}^s){PI Jp: II`RkDzk|7 2?/W\RPf]!HeQEˈo1 .ޜ=j[!eV1jNT$;JX2?!ky>O?r}6Q^*ي`s :xڋ# Y:PA5RZ C0/j-5mT7- u&ɈRQz(jx^ؒ={Ş=,y}o7((ߣeXt;7wS2 r썍XPFYDɾw6OpHfy_Or )VV} rVJ2d[/| I}zW ]+5+r5\BnotVL"bs@dg?eO/$*&ae0'AZh\ˈo濴!k~S 2?k*: m,] Rw8.Vou'_3^w?eO/WEH3((VAˈoaHkf=>"ʀʢ0igXJee) k#G{K+ʀ7(WZ;}#@,\ ^zX1m?F#\=AD* +*\h0%prx Lz[kw' ʀ_P1PR3'1Ip.,-#濍G1OSu2,yIIė[Ýv*UC%K5`1࿔H\h7c){g+#+oHSFi(PΩʈo?OD\h]2?yZ)HSBxcE>:G{w6O"|?$]>O/j!ń@~ p;XF?O?_){g&]|ȉr JgKno5.P2b?Cg:g߽o 2?;%#$w$(O9ڣKˈo!Cgy3?2?{(8c6ۚۋ,IVI?VF'GfuOՄ"U)U72]^*H׹tr?VF6OIf:~{SuB:mW*H[<9%t`p5 56O?aI{u>OBEe`UqBS^#-Ww ˽ޚcɵ]U{9p1MW.?y/<ʀzrKI5r`oE+6]c{ʀw7bN"Qf2$M`:jlleh|뗂 ߉67!s"STeYty/!e?$=-w ^ ޛk>[ED]>gg-8?$]b_ySWi"\0dE·FV#JGe^GSbTcLR`EOQ>a*ˈo??#Gk?7?}-ʀ_::[PK劳դ6l%ceoI}<^U6){񿲏\8]efU(k[ VÜu2HX1mLt]]x}ÿ){_}$ֺs 5'Xw^ʪ*X1m?V3$]W?'SD{T[kQr#~vy\ \ 9(!e6Oc{);_3ՠo)mB42Y,#濍?cSs'^){,\HJcE#sJ_VˈoIz?5黾){FSo?g!YjUiaq-T?VFQb_'Sd%e9 5'Ed"xˈ%1k#){k$+j* ̉U{ ?VF'I}^3O5lMԆJ$TJ?KdsH?VF'1tKʀmW4M@`WS3?VFgt?7/O]*_[QTM!; ZpJőM.`1m?3?"]z} =]^C߫)ʙ5^3s6OtuO]lYReT,)"tGQ7N/c7$];-=_snZ_ːK,-{/RGX1࿲ o__x9% >_?\e162e_H'o{^2?ʉ HI59E],seJRT{&[1?!$>u)w3''$J,eQ Q:6OǤ[+O ʀ_TϮ N>&AV(EQI<`1mtX' ?eO/wEQ8]UcR6=sR)PQʈoфI]}R>1=Ie"+IVcR uC?VF?0]w$VIa= 2?k($ؖV +)z㥒?8'X1d7$]w$VIa#7 Zi+K6y_9f*{6O?LH F+˳j9h8 2bo I]}R ʆr )gSV6~R6O+qHz?ei&_-)wvd*֔ZKUu)fceߊҀ#W^M){SaSP UpdV`d5p`1m?HzW+w?O]Rdne(VzEzN;e;XF'1 Z)"iEgcB)d&'X1m?I}Zjʀ_dt rMI JZ塮,#?&]jUU_2?+ϭu$)H]pFuPI  .?wǿ=_TMR%KU/H5eX1mtWO/2Kq)l^r)񉪀`1m?.g 7?eOWwyԛZ)9|tUH&I?VF| I}Z=w?eO/w[B9V"ehJAˈo?c'?2?{5RRhEeee塰^j4,#濍4tk=5OeB=:< &fi7E3XB^TVEg* $-**~i- i0 x*u  _"jm jx: {7~9sq&ߵz5 җd2u_c2idLZɦqң9]rB ^xRt/9sN uJr( Tp2K<K/?M^x\t?~? uWvz$%)r% $GCs_c4?;[L*/k2rtP9JoUUң?eGo [=IdU R(Y>&R o,=꿌( Hm 5ikf cM6։a1(2h!҉9G j~襟_ɦ$^轭YxN.-a_ 6_cuIm `F_5XOI]D|0o,=꿈4cKo xgFccM.Z> oSrglB Jk*J_8`_4Ϟ}gG~,N}_~˷}oy˿zA}3gLU$""cu"mXz/X6;.M4_gk6FP2&B( 9lң濽4]jXf<0?#m%m?hqK?e??]1?Wy8m}b)AWY H*lG,k6?;?=:LyZDFÂ2VjIY0QLm,=꿌o6w%7_g+:ȉM :{'#Xc4*XzG6k8.CA*'2bY$H K/⿝KoZ|+2Fɲ JRitt\:(Xza;~2ǀ?߭\raNiq^Rr[Qe? o?z={ zJ˨uCC77t.cvm,=꿌Gh&/ˆ}vkkBI-qhixDjXz:O.i}_~A_gk CۗLArjȚxt5O?&)q><*oy>v_g5kwXRp|$/C!bңC8'm2^]_gkk7j5YRٳER9`Xz+Ood;{?1?#vU$ *cvR kj"gXz6'_|Mo_gu1,%.>h<cqn-=꿌G 6?O|=B<\]TMb+MVz9\ wHmߓ 5 2rBFi[k1WiL%Z&Xz:o=d3+"R1yK$eȬTG_g6?ݘ'_gkUY0M<OYd2MX&j׍ޭ?k0 >ْ r ^ŁRGhwIW~c2$}(Ҋ,2i U9hOK <0?࢒Y0Iz^[a$ʉ-bXXz wI'G?{{ =X;U1䜅4H9([Qe7?O_[^|ǀ?ߣIŬ;ɤ*PIZSЇb*?K_ ]|=+"TJ)C'/W᳴:7_g1Imn'm_gkT& ` IZ$ңU?3>i_7-0><{; H\> ~dN^pY*:=[QeÎ6OOg=-űSsdQI tVzGROHǀ?_sd[.fΡ0qv%lJ&2(mGߎ?IM {v7T3Dʫ䆖[u2G"GߎKo~ 1?wO"Ί\Xcpd%o,=꿌 wIM KoCkeR'S|6x G =E?^1?4ev&P6W}%lYtVzGUO=y/ǀ?_sY"Xc)t}T*EbIG>D;>ZU5+\P vyeokң68=?=W9_/IكN} Z3bMPK_WO=?u|ׇG߉oHHٺ@%C/U~SMf=4o+=l?+ߞO?1?8|p@a XrҎsɪT o+=꿌v]M__g\Y,%Jz}rƸl Vzi=g'=^ zQ8} kNY }! n-=꿌G 6?OC? 1?W"H$w 9YQ7aFK/ wImj'叼=*m0Z9E!-Uok'Ys[]Wο=js,;IZ)FrP@DxuϹ-KHdeVBɭfǻG3k6G!O(R1<DA"/ʷm eXM?Qp"@) ?G`o?Dzce?mi|a%8j+ߒ7i2m<j_g3Iamd_>CF°-l.ٲkkguj_?;s?2|kɒ5.u㠪EҶCYb~S/ {ױg'kM{gB4ԺИ2\[w֗t:?b5/fWX/Gg\XTā.cEJ.VM3?W;?8wo6wozO};|y˯Of_>oʅtIX.^.Loj_cM~U0;?`+e״STVt֕L--\jXMl-?Ia,{Vuoro؇ҷ]+"vy6QiUZ5/W? 3X/ۺ(CS:>7mmEK;.L*筫)1/{'){o'cesV”h[Ӥ+Z|IESpU+XMroOQ1?kfQ ٻrX>2UJ>B EXM ?| ?wױg_fm@mB@LEm[W6i{Z5/?Ia^z/f_kcZgL6n\+wmtalS!XXM7'S<?}?ce?޴ep*Rh}ɍєe$.WXc(??Ia^?vՐ+%=^E2Dm)RuT g_b(xw]x$:V7׬C?o\(\hbiZjnUl|ժ)1i ?~.ld_>nj֭'mmi,Eg3 ԲmC!jv}vq/5~p酽z>yi~R_z_:_/=]f>v{ﴶ]P2uv?^nǻ[x'9؝}<죟}8n/3"۽z 48wV_O]xl)6O>Hwc]ڻ]zһ?wv6<64~&孓SuٗptNgWv?q7#[jNlqx9^ڼ|~OGqw/`cߧԚwՍp-CҽHݐ>yoUpw["ni6/H;vp_'zHN8{gΜ=7uW߸t:~m޻[pH荃W$?uNm'OSʵ [[=w7鿫7R[{%gM~;{??I-;@ojRI7/vh?D3z}Rrt?~$u0Js'.6#lEZn1-v¸h-T [L1h)q8B UX^# l+*IJklˠy <;sh؃dN=ÕPH3\ B:Z9 ׂΩG[G:Z9 u&sLH3ԙj3aPg:ΌuVC묆:3Y uf Y ufXg5ԙ4ԙ4ԙ4Yce֙k4\ uZh3 BcIXg>FZh3BcyC ֙:3u6Xgl<`y:R3u6Xg=`PguC-Y`EXgi,YdubEXgk1:\u,MuѦ:lSbE)"۔XgmJ-%Y,rK uV"8A$D&qPg%2:+IYLJduV"8yaEި"oTXg7*Y`E&"TXgI*$Yd ,2I׍H4aIZD 4aE0I$ȨrhIpOq| H' -MXqa$ajk05I\Ŋ &,MXqwfD%DQH< cGaNT"( JIq܄Gr0+*-5`EQH> Ga^T"( JQ02*fqV\Ԩ Jܨ1 jt+.`t7X; $az$y$#CA #ܥ0@^ $0B$I<8'HMa$qHa$&qV\=YDS&I>iDS'I9yDS(M(.X;̔$rPI2a$0V ~+If: $3&qV\?̖$K%d|I2a7aeÈI2a$0d ~2If:$3La$0k ~6I?L$3M +.&N#'D#̜$a$3 +.!a$#lŠG9I?I"fN0s0sHD#̜$ad3'G9Y>GOBMPqObd\!fNObdl!fNObd|!fqV\>ӊ9Y?"fN0sObGMXq 3'G9Y?"fN0s~s܄0sHE:$̜,adϿcE#̜ckE:$̜,!ad3'G9Y?9nŠtH9YC"fNf ~E#̜&̜,!ad 3'tH9YC"fN9nŠtH9YC2bd1s ~9Y?̜&L9YC̜,!fN3'e9n:Fqv9YC̜ZC̜ZC̜ZC̜Z?̜&333333 +.!fN=zV\C̜ZC̜Z 3/<9nŠ˗ai9|fN-_S˗a5j9MXq3&AHStȘ9HSǘ9M(.31sj31sj31s,_1sj31sj31s0sj31sj31sj31s̜ZC̩E:d̜ZC̩E:d̜Z?9nŠtȘ9HStȘ9HS"jƊQ\fN-!c4"2fN#!c4"2fN#c7AōHӈtȘ9HӈtȘ9M!_bY0s"2fN#!c4̜Fts܄333333 3333333a42b42b42b42a42a7ae:id:id:id:idiDӘ9~3 +.ҡiD:Ԙ9H3Oc4"i̜Fst "̜FCӈt1s4fN#iDӘ9MXq5fN#ҡiD:Ԙ9~3Oc4"i̜V?s"j̜VCӊͮEaGPi vd$ޞA) Q Bl 8Eڇ3Q7gnD;ܜ;O͙h3Q7gnD;ܜw9w/vx9ps&L͙(~3Q7=8ޝ37gn/9Ls%W7gr\ݜsus&͙MW7gnrs&L͙(~3Q7gnD;ܜ;xwnD;<ܜvL?7g9͹C~qC7g9͙,~ndss&3Yܜ;g;ts&ۡ3YܜL?7g9w/vLC7g9Y,~nbss^ݜv,C7gPY(~,ps_0ܜvnB 7gPY(~!8a9 0ܜnB 7gP͹C~qpsa9 /ܜnB 7gs\Yh,ps?,~ Ys)~q~1Yd7g)nWSܜ;UܜvnB; 7gPY(~!8a9 0ܜoǹ9 0ܜnB 7Yh,psa9 /ܜnB 7=8ޝhlps6_9/ܜ;ops6ۡݜvl?7g9w/vlC7g9,~nfss_lnf;ts6ۡYܜl?7 9lnf;ts6Yܜ!8ۡݜvnFK7gQ͹C~qts6a90ݜnFK7gznoa=7gznܜo9ss6ܡ'ǻss6a9/ݜnFK7gshlts6a9/ݜnAK70ݜvnA;L7sP9(~tsГݹ90ݜnAK7sP͹C~qtsa9/ݜnAK7shtsa9/ݜnAK79hts_9/ݜnasssݜv?799,~nzrq;799,~nNnD+!8ۡsD9g}{ZܜH7'%͹C~qC7'( tsr"ݜH7'&͹CO.999DQjE9S nQ38FQj·]<8YQjfE9 V ᵨ9|K(5»Ss.J\(5gpԜRs>h Na3QjF9k N]!G;,5gpԜIRs71J(5gpԜYRs>h g38Qj~F9 .h!G;,5gphԜRs6J(5gplԜ; m3QjF9 Nn3QjF9BO.w挵͡5Ρ挵Ρ5ϡ挵ϡ|Ź=率3֐3֒38QjG9Bz;ۡ38 Rj.H9 .38 RjRsDJ\)5gYԜRsFJ\)5C/v 36RjH9{# 38Rj·_P%)5gpԜɑRs'GZy0H9wű.I999nNN#H9W]vsrݜi7''Gɑvsrrݜ;G;l7'wI]vsrrݜi7''G͹C~qvsrݜ%i7'wI]vsrݜi7]vsrݜ%i7'wIɑvsГݹ9Л$.I9KnNs_88wI]vsrݜ%i7'wIɑvs_ݜ%i7'wI]vsrݜi7=8ޝ$.I9KnN$!8a9KnN$.I9Kn9KnN$.I9Kn99^nN$.I9Kn99^nN$.I9Knzrq;7'K]vsrdܜ%7'wI͹C~qqsrdܜ%7'wI]qsrdܜ+xɸ99^2nN$.ɸ9K2nҋsdܜ/7'K]qsrdܜ%7'wI͹C~q9Z3~qn9K2nN$ܡ'ǻssrdܜ%7'wI]qsrdܜ;G;7'K]qsrdܜ%7'wI͹C~qqsrdܜ%7'wI]qsrdܜ%7=8ޝ$.ɸ9K2nN$!89K2nN$.ɸ9K2n$.ɸ9K2nN$!8ۡ$.ɸ9K2nN$!8K]qsrdܜ%7'wI]qsrdܜ+.ɸ9K2nN$.ɸ9K2n9K2nNoN'7\,;R~v\\'9S~xNܞ'9S~z\\(ߜ\9S~zr{G(WJΔߞ77(wJΔߞ7W(GHΔ~99D9Vr\:9E9Wr19FEr~;GYrܞ=^cGk~ڣ 6V{tjn؝rjX=ccGl蒍)jX5=:gcGl蠍]'{tjXU=:kcGwY/_^շoxի?|{ݛo^}ӛwytOoz_?7q;<??__Yd_9oǏ^x<ćYݏ/}>Oz~qK_?۽_]?s_\\\\\\\\\\=;P#darcs-2.14.5/tests/data/maybench-crc.tgz0000755000000000000000000033702507346545000016241 0ustar0000000000000000CT!J4x16O6{_4M<4OPF;?GZg?j"lvYҽ ?&sT>9P5>tps-X_[A ~spe\ AWx0ޕpn NCNp74k:sf`/\ǵ_cjf汒3oo'6M߇bHA~1P8'٢k'&N7d3q?ןUA?g*J QVƧWzIՉ_AQ„I3QEMq1Qsk/c0!^#({x8^-[My\ÌK=gň ٳq;m!tj:5>_ZW\gH_ ?A{ߟա0w|VEɐQԈNb;TzaB UOaۜ aAY5oSֵę-g6gTc*C1(Xa#tM`Tż ]SSʬG2$҄%z~D>)D}wi%AMUEW!NχR|"jg QZ !LIY«spGz~JeKr`Hi+4Y3=נ%*H{u WHWp@`9` StE Q-$j8wsci"c`Fw֌Fmr,A1g-Φnw_C \'"hr lD rZ{lLm3Ilz_7o3_Tϑw1-dXJ3Vt4P4K[]_" lpi\O͝6A` `Pb3Z#O2o4sJ@.=`ua::a>+Wo!l!ʆ@Bs԰FOpT*HB\ Fh2skX+Ip+RGCuʆrws9r2dCϛK@b!Ȫ &5-v&d;sbrmcΝ }BϜ"M@G:9wFrf f0Q25+R),SBɯBt6H$"KQ 0V2eV{7 THW 9k"Fs 뉰k ? ,rKMMcrSy2\>;ǁ\M-g'|Oap- ,h*P4?~Ai't0A*Cg3(}-WH* L,E5Sobe4}|gř<(=TH'(|s#o\F$lII*SrU|xիūW%.C5eH%\5i TD38&%dFeZMIdrȬ) a !la1͡ ۓӔtM9r~Q\^2LZ20U՞9%QJnJG\9am_c-ErItfz"߱G3͖"2~~V)P$FPS*8p>eJrRu7\ը~lej$N3!aKR1P%D!,R װDg;}tGL{mpYң!?Tb. QDc< l},>h(ՙe έhzA#.x4w+ފ)VFB :N]OJcJN|rF~T"po"p=؏"cg ET{FTʏE.Ft*FG)ߍ3!=$bToZVEee ZVEeAgg#"(_UX"־8mv |zve>!A* wNvSna3OVX&E\IN 1Z~_'))FbC?j_1K?ޔ%4ac'~ (PNi/Cb7RbBAI]|a' _3tog8tiSrbD&ƍ)Jzt 6|FJw~)qT+1?b? ד@XY8psMiꢅ#p$d]˄Q|wьP  SGsˑy@ZՃ^]C|v~m5 8&;g}87 mӫ~rqA6{=tuqyB`[k[͞vj7@[>Vw ttE[?ik׻NWeoկk]^vzMa5Zyulw6}3|h7"6U;=oRG+J} f z>7$B s>lPE&htqn$v #$r$fǯ_Q[aEGrS13Ul'-׳kM;[_ΒM{Lz\a pRrQ\  ?Worm"If$mj}'.m|bkQ܁?řA[IOҡРf87PK\<wDHlUe_-sk#H0],84MM+ܖl_-Pco45h.H ޅҟ̋uA4O=> ]5y3*pz/uP=BMSݵ'IʼnB$URfΖZ,//drpif凐iy(Q`m1Ď?@?{-O>|;,s{}c9sK$4O菲N x#FhY\wg?L[G.,iw]WE:a wgI?\ǴXP'ͱV=0 XLLZXŸ S%geOLh@+ϑJq}/T,'֐ }g1WV6jGMwsl+LﹳcfV [t]g_w2$ign/EP{Q _GW:=mR&窗V]$oX~W$Ϲie&C /h͝.vыMnk3Fč/mO?hxm@O]^_7wx_|.iH5g:0?S{&d(ʳbh,荬˸ACOǃX%>%ᦰWU/1^8LcG˙M.s]P ) c.@X; y-F PUCF2ml[{$|7LNCSG=Ž#o[B2hZi&.<1M 0>ۨdx%.M~ik Cefo~{*0P ?wzoO%n6~@I.#1 2 T9>8 '4vJ¸AE5 8 `I4]&ޑvjDHM,o*8cf {}K{@MR^dJI-Lykja%ɷ%d˽l@Eǿ6we5 HF3p_|18hn2R-)ϛhv&ir>TFXn'Ɨl;w'׿^ \tj.x8N,H-%/prɃde;@P/*$L JBQy ̤B **JS*- *"*("{kwv%mSxwdVW֋`$"Gi6ҁ|b \hSLEUW[9PG٘<$?*B7T;DbXzػ $F}JPʁAӲ Z3<$oUp"Qg(ra7_Nc!"OG? IJ|>>n>,D7J=8J_ ob 3_$Dpl7ڠR-XH9~=bq$NJJ84Vb"^$I0bDEJ|P>=_7D>47$r *X̔¢,'t8iBA zF0$I٨7 b0'(90 OrXA"a =`HR[ \CM?InR+d[Zz9LH ìsazX"B ӡD(1t$UImi|%CV@P2@~$,$CQ^(v{ 4W0pgdAJ44ɨL&91$,:% HF@К׍`è nA3viu:&s`Fr>6 D)z50$dne9K+[ÐiFXhyzy\ǒhAƃac|1\yH_ \D }RlDl>*USy.e«^m0zol%&'xh{SbQrbMFiE!zeEHdpeV~o$4HP.9YWP0D6pw 'ldr/-= L ra,F#B Z I)yP taHglҨɬ DJY\I~IEw jR)lU</D+`᫴xMIPJ$"F  ? n mɡd mPǑ0/?+UHM|Nn߂^}@Þڕ  Ҳ2 p  *^y]FMB{8 qN[ZΟ\4Js)/n\L dP&1)G -OH6GK/)4}hX=j)Ŗ: KIu9JzV-uL>>"?jPdA;ze =,݁y4Yxtc 0:4ԡHWN(a{Ǵ Ԙ 7÷ n%4J;Rv@!P$g:랤q=qAHI}ǐj!#as ĨdHŘDq"DGbW?,"tVP+uWa^%`_Z7h0$ bF}lE <˜C< m&| x(3q\D HL^V>bIRǁw9K{Sn`,+G+h*"m|$¯@έAx,pДr3jz hbX R Q(ŵ?4DzuWS!nEU8Y"%aAx- BvаV3X=MWJ'wez%Jx=r0WJ¾JW&GH YrU ހR*ラr }2NCR&>]&Db]**PrO՞vb4iZUi 9HHT{Iy 'FlR=˓pPO*=a.Rt[RDcey]F\h9 *f1|H 4\7-UI9y tu[I~c=\? K%mC:$Dd+ jڰyq3AB!ט ˄p% C^pfrF)k<!kKn@Uہ^EB%)OvnAv"͊Hv[bP/e7q[v3 kB^1K:VR%:u:N^!iL`r11Q6V^M(/$ao1+Kh_L'{QygˉJ9*j%u+B29w^}6̎q2j18R FۙrLKES`:vVAExT +NFW`‰)bʒm&M@n>AgԜOM5?jq]+瀛v=oQkxRA{2$`C lĹðE!<4q+<,0E511D` YtKJ,5ϣ`%; N R[`dsu6=aNvPTߓx=@Ύ0e$@ab "34ȉCW38{bh L#n ` #ޭ0]0PEF:;hƱSQ`ShAQ+"c`g(>b8 qCw mkAw0Z$#n+V!E90aq'1d?w!2LnՈ0- Ddrm"Xν%aN~ %r o+GP#ϣF9%ďX;*% h]Vd& "\ 69%a(d QO"qQwUP)ơ+ *bءpC?v3/(D$>cq/x$"nNb?v#e22R I+dfLۄƵ d *z:5ћy0 zDӫcE6-S5!OGJ}~|;HrLJ 9dmr8hA}7b#7x@6,!> w$+7F5I!YߪwpY$Q 4 URh MbXY!SΤEA/Dĉ4$mRJRZ]ʢ1!$a^V*VSU%sx@#F!$@Xa]x&$$~h`jC 򁚁W6ӣ7"\Ԏ6!asDAi#% F\!|}36@sRōxK:Y"(dߡIx^­b01B QV+s:Pg .@c]~ Qh<CFKܚPq!ρ 5$vyMP|&7H,(ˉdx3r)拋XRGߓ 88Vp0ޔEE"⭘ _ad+젗^ӑWYU/"̈Z%eWfDAH$RJZd%]}WUKôotsvFRH!6J;j"IMp  B!RKI[;IGG,E4""d a;̨IcQqM |Ȩj*Q/hq Ȼ," h "azsE74* ;> yHK:䢨'NFZ>67NH5E'"h%nh(np-ܮF"Cd+lX_ˁ/TB7㢰C-J%cDig\ xp'tUQk.ILb ShO*A{%Qȑ\zL.D|$KF$0V[QAӄT }Vb-$d7v5oh.}^;j9xa4nT*m??|ɊF(QY^M!'ue? }WS)p_ !eY/Ѩ0y\j5]"DkN.wleU!PȾ``~&MuOH%@? u$^ bSk.T58[jem($N B",샮Q(G-mڛ7([3x A+!3*"YIAb$&ZU"N [+Q)JLț@j`\ƕuI 0 Y}`à ]pTa{trL?D- zqHUb7]@)Z~'(T#QsHB}Hò[!1hpr$=MO*$5Q)p \=/l1XFܥrAB,D 0(whni'P gv~vHF% KC84&`8a:RCJHbkr('8ID9Ak,O:U`;%SsF&\- :GU\9W VYZт9Y/An.=rrno7 z\T|$ <6G ) o7H]}cTڒ:{^}>|q*/'OieT(g[T'm89cF M ?6/dSӴގv7{GmCgv,|Źg[6w͖Qp|ABqG{{jnlf;Vހ3g:m ezlFNo:Ck-yD?k~N]LOMRfHq?ca= Mz.et`g?w6KUY{[Lx~NmNe$u?D)_~;^՛mO<)9{ e|HmvI;j}עCwznjgگuiqCF OqL:~9jk +?+ύ?B_Mvs<nVb2Y#Lfc]XlkV<"VS.v3Y4iNSݿ~o٤"OƩG.m{s[厗jwaۿT IތE#ֲrrvFoZpo7WU-;ܢxcʜ'$Z[:{y権ۜvWtJ(XX4׵w#Lxe|nո ..U z`!be52rɚ6EY,j1prA &\ICFM[Hvvow}i'~k儸fxmcoyo[9GynڧKOɤ v(瑋җn0-[?C3lj?Xy׉M:uאwJr٣럽R%G@;U=7u6ho28b299m+v!2zX7To#ɬ5Ho]bŞt?5EM2_.oW1xhAwbƕ>{ YAW,1}U+}-E- AԳ*<ۓ'g]a0aq;$S ?);v'k3FVit"w#yԹmv$&T3o#O>wKS3+ :/νM.Uh^Ҽ2w:kw>go|~Q58N3&+N\[':tێR´w u\h_:]ͷqЄ㞩4ܡNIm8T9:o:׻apRug"%OMjc31|'gzCo~p.-5XMC_8<`(>N{ΝzDUiSo~mQpsGG?יK:O/xpo*oJE/36ՠ7Or&hw"!bലFc9 v)ߠ^[?~~ .|ּ}dGu L76ڳl$Ig55~gC󯷹p!Ҫ߲1^o-#gnb2rL:Z3wʭu1Ş oo?73F`Ybszj4XӮ9rL.߈PŃe[ V|*f:gfc苇&7h?/_Cכ\aV-ݶgo7-H)wɞi3SwO7n.aY~Wjѳ]RȰ忤9CZ?oL#K'no2Ŷ~Kt_~N'R7F;YVoq[Yf2m6ftZ\j1#fD7[M1o5  Nk<{H?~痢]>1Ţ Zt-ؼ{~Qw~``ot7Ўxa_cYA:ܺGl8tW.G&v=0sʿڽ׳wmgNx6'C%][~?x 6\?P2C9/\[NG0q}<ͷuY8ߚOÆO:}X͋/~PWϖd3O6;D d6d'kM&ns,hs.ⱻo-Jozk ߠ{']ڦwFwgOh˹ 1L}=ęJܙ34Vn=.*ŎOkݙj\;>I4}7ҳs;&{nig >˾w{2eŋ>Omi9ۡs_VǠ+?h͐'վzWަ%{nLsm7sQopb͗=/;^x]B3∷l;Fvnv_/=-lI'јHۺmǿ{ނGJBO%=aof՝<1'2ӛKO]zʊKɋV 6fe'?n+>/o5eM׹wZp_׾}#zs8j򰜛5y\659X-.NoquffK,[ <"gom6^Wkb٢/25̑msN2cqށs`ݿY1x`Ԅ?ь%SۍCMZ $l>oV/s_2jp:Q/h:3ތVН43x |+įW^uno$~ޡ|n-.:oF]4"o0Z &Nbvhvݔok[HFG>42~lgΜ4&ߦ4n^֌ }{diYdfz2=s09=s[ŽFάɗ0\~gKGr֚cbQ73kBl3YcrY  5!MAgA Mj}y;| Xxڻc-1"~fx222Q⮥c*&u㊂H+{PQ4):UPtTAQPCE RE('{wg$Z_h!V󜫦,*<=o߼ !6x{WAG_{+|@@0D$*DƒqD( KB~?ej2ѣ9X>;!SNgj 6{f=P7UxqFomuqv6o?hZ~0Q`VCU ⎔&*mV~uQ2bmi}H Go#1 \mܯ~73ɡd|MĮuȽt~J0Xvu3s\{gxSoU i1ħ3Lf."1R*nW͢n BC*;vӾa1d?W,'TPzNj-+cNN?NгKgrd.l0x̙pwm]_:ߌ;{FUʒALvfkǹwy4.]wg9@ 髪xq=T>NuON2ba2Ahs2o;G[Z-!{Zz|][=ɠ1"idX͖6-<,g }[&ww~TdPȬٛb~H S=dSϏa#i'>Ћէ1LӋ?)l'u[tg"SFϸe,}0D)\6Ymc| N٪vWQ\E^ OC^RƞsF&-9?Ph“[gnצ x<0C#rZ2Qc3>ig:gQE>Uy @FAeՃ$UH4V1JVV֯I~d)-['[Λqj+C97*ZJL[lB*v:4NQ"Fj{o] ^aObf_@qC2? ]rquYLqЦxs&&E*ioJ7YS%rߤ{"&8:).CRF gijSWr?j3G&IX" G)8,@%0R_R[-jѨ_;kbɨ<ϵh1Bx< GœBb0?JoYe&o9(c'SRx܊`M ͻz"ę$ tIidfS.V=מȶ rQ v_SBOyNybPJ麏@q = gm=UAaiAL*܍aɤVzۓ`ٯ|%ςgejRUJ2Ϊ٘Ӟdjn%/Q"A¡d \ F B)OS K߲DLɨa]zvSEB}5 Aer6Kg3hC,7un)&U><|/]=@_HeUumDaWםRװsMTfi;LlB>?FM Hm{mq})W×S132ftRRM'Wʿ[=,Pv\Z"mfBKI#5yf)#?/nKĚOExGd6Z^¨ۦ$Ds?ü< |%cY79[aX]Y ,? b ܟa<GxK!-<~cp $ R/ˢ!:xD0kvGKREn'`2R.|uK}j>?CI[cC}`FcG_' xW.'ط^+5m}ku"ZZd!mX0E9-BI%W-޾-70ή3!kZ~6mèL-wА馡9,EkhF<2 04߯koڽx u.51q+g-'` L&GX&T [x"$ P%CJoYY<:U% fQn3͆A>_L]%$gG^|{nkb9*ɠw+!&ܷkwT(-lKтjJ^3"آv%n= nS#A .|CE#8K3j4÷S*W gcF1}9}sXxO*͛_{6 S-SpX D@QJE$ ЅMTR?Eo FxǁGjW퇷m<;eɕ~ȘןƑ{nyɫRo|Ja^QnFe5Ze~iʻ$PU ϻb}P?ϊKߞ%4ݔpۘt杩h5\zwo"0?'!D<R@@!*^&Q d,dR̿-ۘ~9&'^ݫՓn{-YDT˦Ju܄[$_rܪ{̓WLɕ}bUClږބ$E|6+'xhDOdq`^k3(lHP$A%KtDrDtD@ s$9Jh$,Ib "e^kTU9u~:ϩZ{}^֒}f.DT; { ,~8 C"pXMX `?L+TUIN8{[*e0 ITغtH ^})3.5\Klw_EF29fq98N 3% !ed\̵%Ž(7m|5hOle-^GvCqZ[NCX]gNJ1ͺ8j7 0BaC7la@4yK cC0jy'KhTQHkZX/o4,1)D4@Sy^Vew['{KE)[d*Vx9a1%FmBD#*y^XY|8^s(8BFcP$ ` <C?6OǠ==7XٌlT~=0?v8 HH4 % XI`18O-qPC  541ĿпYiELN׆n+gk^GqEMe{/hLd?HևYn)C{(4Ҍ,?OBů0aqP$ww  ap( F?T/kO7?tZd9>2TU1S]vDruI* }O6#lIVQS4U@k7꺡 P:_ حdqŀGUo Us[$Z7/\HI#9j37D^ _)J6rXxKMb,8,rk1yH5$ kmʹrHԾ-Տ4A?~^L^ROt37}ӻ,}ԗ(gw-5Nus+C->;  C!x p8@cqP]/g2OXYu"'Sebm*dLi$qc5%{aNt9_:c<)[F Y@en@^\zI"^)F.ǟH$-r?}=} hT'xM>edV[K'xr {7G_&v\L -%ȋ%힑m1x^ւ AطhSH_ׯ\4N_k嘚u ~bM%V񏧢yT|D&9k]gXF^?O%D+=/RZ:ޟ|ivŇ >P&/s 2=RN3›bWVJU25(cd֨߷:{rS_4D>-*!w["b Š0k.um,L_XP2-kкeLu Egʗ X`8:I&$eAXQjU:n#*MƇ\cN |Mg4]A;EhK0MÃd=eBiUL< 궐.:iWté T Xn j73*"[>6"b/gWmg{T3\XJKi<J#+HqP~ǁmsp҉{s} @s"K] A匐Īm#M@2sT7zihN&=/(Oʹ'Oxk{2jgf}ǎbΎKܱI3ss7lII - (?_ĺs;wuIѬɤyIC8ua9KvX$=oRݿv/@I|"-qCD68\\dv::j^8!@,> F ƒ PA@#`PoJU򀰰8PHUM\29->͙Ȇ 2c 18 0УEj{ _DBHPZVE{C#֖&[Ș棌j,P˅)~/gp`` C/D#P ` _o.QhpKbMBšeF4D +PS18$/\<& 4!H-:CG"- ? SZG\>v1#P&B!R?9萹elfXL-/股Z꿗4Ӝ}ߏt-< DH55}t㠷̩vՂrݲz%1+r:ݕc.yYm =m>ypƬĺMi Wqktqh-|0R;^MBѥ'+4tgOu&+B&gDН-j:=;zW;PA)kCQMdKw UKV2ʊ?B1I⧻\S0k'P{%PRKI s_D/@Klj=6}*h(Лin;U/Ǧ__ETTsNva^e GX[ؓY,M_?hc^Pd>GaÚ4рe*P%z/lO½QB+/{w{9gh/~N_v\].4Y3 lNep~yx\"9nA! *:m97{Fx⼶|B0'SD@9Bl[7Zz"؛8ìJ#/qE{$Dzҩ\2Aq 6I,ghI:{!Zt0k#MIAY铂q.(a4i͇ 3G_xIuԬOyE.ArFDrPA@rN"N ɠdA$$HP@d rZg[깷U{fjzn8SztJWgA)f+}{{[H -K!Fk ky[)~@R!"\z˖!)m>Ze?k]~JOEn\OP䊨+vK[KiԽ=W3ֽY9n&T_VK;/L{*9C n\Co 9'1m }: G9?%V]?"r^]+##Mw;_b7|S*iLQ@{,[475&fw]M(x4Ȥ'1*O=䟑Ė^sY]Y^.b' jj^ W"#xNż֢O5 mmgdjHݻx ƿV:u/yD_rӽ̄ùwꜥ$?:\Y$y$![27Iख़f$uƝ\Sm, &E邠Q C#p/ KYg:;ݼ_TaI,1T r<ydsU;Ysʘ4$ڹoz'Hμɼ]nPp1^D1j:== o_^X8W6Rxsfsžrl.ZdL2>gV:3LZ@'9 5^uF ҥaNtU ?]\kd;=옿`sX%$,.fX%KU^f:h[~DJg\kԆr$UZ s3*^:IdLA٨nH hp<[dv²-@B^f.CR\Z34a8[ni89wy3߃)-o27D$Júfpk2ep ^2_JVpU󘙓}lO[*ִj%e/(5Rʁ&a.g|Sҽ-d>y#}o:l.1|1~JUiF/u?}\ފo8|=U"ӌr_Q7'*4BHD6j[ ^#iFۈR׹9f79nO '!!6"K}ǎNbf(@{SÉ `Y蟻$_C(BP 0K%sP襄6-N}꽪گ |gESC(?B[2h&aLH y50#`P?0 @` Â8!}8 AP%} u-QӐj*s P2L4*,o4~n2tҽޮlH=v&8͡%e*P'b:u=*ev<Ŷ,ػnm|ijo?>;"MwMd]G ZU%Kx쒖>D7˛MFɷ% ;lx$္tW\SIFuVz ҏB6{z "Q  P(,C q ?Ko-2L{ʏ:%ܶTk(+z؇YE*啹~Ʉ|\,^="I򨌠 c6S\+{YF˦KX\U¿π.QU=Hc q1fePL-dQf>˃b璤T"#ӃDl;A*>hΕLSFl0)3$sӀ-N]U-VF}w\uUhW_Zo;X-?[T~=AKcKNW_AU62(hNeDڂ2N a)O9>6+&ʸh' Ȗ>[̞˞O(HoxCT3geΡ-t ők=14KTM/?AtIm'Zƕ_f0P PGH%x{kmJ'OjiS,0«W8LVyUuaHJ(q:PU "QSAߧ<.pX c``#q  k%Sgcw+2۔a{^V>UQnEbpV5 9%i7>W6-o)o)#űX4I X \T87,""vkb6l*9̕]"utk{@tAQ I<.>6ʂj3qLSw%>G6߯&AͦPC5vxľ*DfgJ:gXĥQ3զ|ا=7`Q YG)4.| H\ц7j&3_nUh*wϓbܚ~k8{o&Br:߼/$ThcvSfS@yXƬDM^ 0VXY < Nn4KȝKaߤ0$+t_Q쮾tEw5S7 hrqB{Rke A`+?~@ 7"Ah(@C0ﭿx >}! !B5SoTFt;R䡈>I/_m7c$e\߬t:PfmiEHn4phMKV/\ [qwGE׍,$&lWhtZu]{n:窬B?&>^N=ɽ5BcpKk7/U~jٸG))ֶu?PjۉL(x{Y '%M/յ6vlO>bG/WC??}+B}GQH4}+4C~fWa?_?YJw0x2<[]IdVe x?>Y왪Ro{ĉ3×ߥNDŋJ{ |۝TړEX'}h0cN+Ljb.US`#TGy֔ε0}Xt1ÚdGGIĽOcx8P8CNǃ=0,Q,~f3W*콽bg"”^Tt^Y68LnlpM{7CyiiP$ܶW}|esS4jLv`QܒEԧ,AIfM^>;>MߨB,w|Ro4{ :^;\\S_S#oT Td"0hʒ8Bnڈ3ͨQr>x̓adoޣ4'9i@à)dFErZab_C\cC@OҼ*&34CRofSV8ɻs"vпY|5>fpy"Z"Uևa^O9+_}9@z7 \H,LpO 'Ti-ŞҔwɐe]:'-ȡ X!iv:߀Jm*un Q{^fkg>S"T{離Qy< q:uHj>7Ϙt+dX<)Uk#>0V3gqz7._uݝK^Ǎuy_իN~j7 ?'sؠTXxѝrU(+xtĢN♮*"*PrST LX D1sl~RjacַS4;a}]D~hh2^'YPҘUiw˛ 0ŁzyG_F66J4R2ٝI>㊧UM7[V{ B4 W„)qNp:Bv?@`?Aa1( ~C " X(}rL'C_?Yն6YaZt\ۼ!I]@BX| >10ൕ}Q+Jl]ő(f)^ bV7ڣJY Es\'.:vo+LzjůLhwyb /PY;OyW|o5w-OB]]dJ|,5Nt߁ұCcSU]}?SɴuA.("c0QOΗ/xD3+2W#]fFr-^>?o?XC@Ap @ b~f +_~??L ns}Q,~8 MXfPJx2ߝQ'#YD:^o ~Cl"H4FO(fedP s3AzYx A be>@vV,kO_kߟ5ѝpOMW*$ S_\W@(zx8 1H 1 ^EC!pDB,3 COeޖ)rMm1]k}0؄,MuzyR1lKu Dh_iwl\M+ʬ J4u#,[Y^a~]fp-c8"o8[SJ/[=eY@5OV~2-ս$eϺ;1mNZiڰ|+@MW]S9?{ڄ_X1)ۦ3 Umz]??7 < N,sz,9e1h D?G{/џ ن#v4R2zPiXŢ.IIq%Jwt) ]R(Hwo}wǸ:{w3wg5wwp/\l}ŚU&C(>w{98//İ ~Ot8L _UX۽'|eógyBÝNB.LY|{ڽ-())m`6t]G*=m"Ce m4wKIw_OO-K-6?؂eCk`A>\x\`~j;6jQ]t9Af&{7*lζWlWiN:c yb_K"*cBwY'ehgE]U]#ڼ=ڥ ^M7fPCDA?? _ىA+X` v)_w+WO5Msu<믃$*NțWh95N)F#Ů{$ܟwE_ѥFW~maNL~\-n"BÅMWi-L?>s$Dް\:?|9|.CZm8Om=skPSq_5 H~X op-|I>s@y.e! |yF,53ĕ- ?1(7&)>$ GC D(Q Ts? 7 T$nLKͶzf+63#āt&':O$F6Ǖs8#uu_?y)Fʁfg$\r|%5^wEu|(1޾VXf-QIek5J!@艪4bɏ(Db%5POd[?I*u{7PAD`X aHQ( `P Ň??QDxǥַYE'ܾڄzghc2>tpP0}CM\BK5b)"v"'ߢ:nzWd7Z9Z8d,&kӊEvMgwj=wM_Ny DFkg*jзd T@E`OP8DH h@ DQ?؟P/j7k!s\}* I‹}=g/GF%u/xdIu$Vc%vI}Q hĬ˂( XC~DŽɝx*ޥ>,Bp=ɮ)wтk"i4~C,VAs>T+ɋ]DܸwTڦzj^WjWܰMhFT|[uGHӾ '&~vcNNo:,9I/WyYKUo+i?"jF\^\Ht$xؒv*R iGj}z㐸jql˾s  ][\y]{uq=ǷZ&9,ݤ %QtBNka1g NFCns!1Y qU? ^ 4 @XE@@àX 3`WC~{U^-~#L $8?ֺ"\~\iNt1 t ?19Ic\q#:ޗ"D:ozbpݦ-\ 3.x\-0ܒ; "$,$$5ir%y~5V0<L0}oQ9\U0TŷqՏ$PqSÌUN&!cET<8G.xd[/YrJJ0vti d:(5QOÙ`ϪIOKY{r䚨+]vn38 2{dkx|]2|朢?Qb=|'ˀZoۆ4>t#`Ma㙾'.C&JҋN0;6Tsxgԯ+(;J}JC cѥ%-_wsnJ:7R ZN69=G\2 6 `C/GL%i"_sN+5Pju'Yx6Yx1\.}Uԧ3!_Z]%ʫq]΀=Xc͇ty)h馚~_z?#u+lEFUx~&6#)WXYȣ<`|qO~ >-t iD؄x--J  qϱ\xBqrׂXoU>C1eSt |a~?^p= =rNW}fm8Me Ćl>X5D<%YZ#}b<^4js!ZK2W}G/ .Y 062o.Cr}3#gr:!)APξᜓqo9!Oa94!EVkYKXk{׺Ysf iScP /'&W5rgnHc0Of&\0^U^h5//%Muxoska aRX1Sj{X<7>V(;1ViUE;%H8mi{Xzo3M{f+@"yVan -+ $~a(t"C '#y]}DxaWcݣCO&4Ew{8DJ$(7`3Nq9F@n5:XK7sO |B+ܕ%yWԬmّ%qw$qepan\HV#Y l5F8 U 5SvX=&j^N5df>9~{Ϩ$*3pamXy,yQ!Au{㠶\XaW;Y[/)h~!ThYW>eY璴+1iQNp(CFV}*-슒Gf6$+kK>а-=a>BX6&Dd'6~iKTܡZk5)킹dHccDZW>~&~ʦbϭۭ݅aY1% *h.PB+wߑ- ]>t?y2lvKonœ9oTt3<aFu]WҎ&(7f *]HkݎRK^%kmubp W#??E`(00! H('ȷ[+{D <φksRdͭT3ʆkJ\ $4#_]Ouvv XO..}Ê -Xw ff\c~哛gaEV,ϟm---PԪ{nĬA*os<,`Еdhw_o)#̚R :ĭ=tLpe}O|"&xYJ3ΗCb?d '6v~)~8X"+UZ:|XvKn}6"ȰvzQoĺkJhty(DmӨAFbe͐g?_.jd&xTWjP[baKmt9gmij9FjU"HCŤzI9.K̍{ݵ2] +춶/T=߹m4!HЦ),\;Jԫ`&+KR͚qYT,:Frc|2ޱ*zX[듽_;iυ'B|KbEͫR ^f4)PFAp ' %3xUN\/8m+R*&!VT,)-i^ue &c6?Qhսj`s5ȋIjFa"xG|/hcv ^Of^4>5IqsU0^ٝbAY(ZX~7Pcƒ}Ţ՗ICf^m 1š-exͭS8˥:=TJ0TIT݀>Kj/֕}|Rb4KpeRWMfb6HݗA Xh*,/S%CBdIKkj~2ڱ3ť _gT&pXWJzʹ#,39DTܺKB{Fxm a8::[фqU8*w'&в3֝%R>[4+h;7({vzrR¿w7$*F$ M`` X7"PX D_ C S mT= 7m`j3SbSxPo<'/lvJ45]yi;`>/kyZ+֐6ʷF4*RՕ q /Jyp??sIs[˗\ד[[om= V+OU{{4ߒg|d tF߲~U5YIfd\sL{!awXz #5@0ś)hF'KqZ!O(d>T%V0&zc;H]D.U^84@@1ot WWgǞю-MJ1Mj]|FQWOxU8bTN$o*_VekF](J(~fCz='lPUl.s_"X-A9)85Y5Bio.~;iu8hB.)f;},ȓ;feO8ZˁNs bZ0}ny7ܛ$'Qqz693Aff eL^|<zLndB@Ӎȓ 4c 6ʾwsiV ]|]KkE^u?UKNLR+MiכaOd?՚eᴨ(8V) |ᥬvZ`kR,&ȖZhgW?4+uرKT ߜU}<(C.scd)CZ 8Ϝ;?U\i婩+-ߏ/h#`݊N]s`$. 윱ܠB[s%' E䉪n3nD&R@# 3.yϿuJJӯ+%L3їs1ef8'?3/gݠWIzҢ3& !]! 4ك(_MFWxJK~'t >J g4ּ\(Le1&U=4T = z"t`pᶆg}1n4S4u,:wW':*֟3"ڻ38|{>2!4/ I,Dj MHb>mw|\dA6 @ Ȭ%~< -Vjq\ wŇtC:bvzr_+^b_Q 2j=Xt7{DR[dwZ %]d0ihZQ{Y,l~p䍙9X\m)}\-mrݱCh+%9 m NiZl5R[n9ü2}6Wp0( p8, /__E~?iC8}ľ8JɌj8G%@a"A.̞1md\J-F,S*mmEl/ Ae9I?}N˭1^ХYw}FVE.i.~VvA&/XfGLl93mb:m)Ad#^W# G_M, ΜnWX '8{ ;b 3;˵.Ր.'([|/UH<5^BX%?Bq"Ttܤf([Y 0[uxL- 4/wP}&Sm-\ΡJ6iy/1ڪAbT[tt@5>2&yM]J=BPy딶qJ$$Y)hVf (PW9}2:D)o]M ~tyn=? GbX( `X0 @ F~(\Tg!_%Sf&y1^5O,{|ut?o.4R5H󸅊P(SrW)J6ӽ%*OjH jьٶ9e8re @Ghw/3[iP g]XMaY貖\ᕕty83 _[cS *Fmit@JG$ -L-L&⯜VRdp7Iv>>٩E|YN= [[=k7uIFnyʝIvKk m~)͡J4I}sWϦK(.,qS?=I` "AcD]P M (.3 Go_ jPﻷ|V~=/lG/G9VtV:}=uEf$*Dž~"sٕ>D;#zvqi#|[q|lY+^3L/$S[]\:^:e!=/$% >ػ,L?n F|" P]X(cftCA_:Yh@tE vmeNV󚡆v FHLtP޻zA5 nc<8Ѿ`a+%|怹B`㒨Uw!( n*׋Y>O3$jD]R%;p0krũk>8‘S? ?QBѢ(N"1 H!v[WKM}@^n{n5c<|%Iđ_ĝ+Y3X7ö'6Fnrs*]jyzgyb\=^2d"2d^^ýSd.!C̤֘PBZȐ!D)ÒP"S*Ny>y ~_w>_8ئRSB*FJ FtXC82_MmM M)_y_a +INw; 53fzz.J];~wr-r?<+n)x,*a$0ֆK[/Ο';"!s;s!}A6ݢ(tZZ L6lnbYgt!feG·HaB]r&<2E][cn1MJJ683;$3Y28+tnp +HA-/r=[ Xujw5< w myv- -sb온'7Mj(Z]crջpi4vRѰki=v\|Ç*3 8u'':kqŖZ%(xؔgr-/} 9q! 85G?4v牑U*v@>#Zjlcᵂd >yTk~R$eH#UNn\[p?k\kT o&\+%15imLQv֣D /92Y# ܐ mWEh}3ڼb]0Zi%[`dwϸ aci _CYn\L=Qu~$R4"S ^͔U}+BJrѭ`v#_#ӫWcbdշ& oYm$6HyžM=z;4 6A~sۆWՁRN(L'z=8vSaUW I]k ̛Or2 y4h/Q;.3l~lXO̿WQw 6k&\>@AcgSvX^9h[+ }x^^A!(2#gE"TI* C )?oFOSsvLKV-c}6B^ttW/촚 Q/3'{ogty7"Bk{Lh-kmgV)$$I:#91҃#o+z98~s,S휉S0wubέ AlNZ\iѴeKiŻ ft5~-:#'GX.Z\fٰG0A$ H~Þ X$Đ12Q֍;H"Jh_ǀ߿FBXp%}HGY/7;CH<^i9LśY[i/#k:x' D;?zf]{窠ۣJĴ-mi3& `Kfi*{YRfGlalAa(w7wcrRJz=ϯJup\]#O(di*Ϙ^$d9tMx Qvٚʯ{_ä[Hj֤n=,ѐِ7Kʹ05&S^Ufji=L5D(KH2HQd,BRP"L(uo#/ѿ W0@XP9dgw~:{{qL/9䔸cǍJX63ً;]f([_4UHJ"EXk *\?QzVq;Q%Bo^ c,gxZGJy8p,T<(뛿@HH2I%H4I¬/4??# _M%ev6=[<x򞠖,0;c0@h9ͷi[-{I"xejí 3zT״b:ۢ)7xRҁSDk=y;ftS-Bk}Elvkkʚ*A+mldÈrY!ľyJi{EmĭjKW}! )ǘһ? c C׌TBh/8 3KEFuyE'Nݮޠ36{ܭ..u ;q{ #F/=6pꎣ eWmqqRk4ܮʫ_zF tpn /zs/<_Q|޺Wq/{JuX/wCaP?Pho}(4 ! hCQ( DS_F_g뼲s|I BuX ^!:Ļ*>_7hY=Kg.FJG3oӶ@x1f K |l*,4hU` 6.kke-:Ol9=-]8mJo~[%}K xd :E2:ꍔ\ȟڜh%/?@MWJգ-bD۶~pdul I^e6K{4Cg4 !-*>CYLw(O(|ƌ̩XM[קL q4P# 7s'-ဌz扪mN='m{~6CE9@DbєoFTJE8 3?  }W]`A7WY' ۨu/|=a/U >Mc9&0\YqTcv_|p_cS93P7b\qjgGeS׬\,UxlUڡEcūzf܉[}s4l oXW+^=@u;HVq8<'9_JmkAE[^~m9Etb~~5h,ǕM"{X{Ok7p|~ [3,Ž -'%BP/=mXϭG3w~ͷyf.X!į&D;]L|YI'qvj81V/vᔩeEFO` &zDUs%i=(,{hz2ߩ1A!0D, !H, #<(`/?5q4~F p&&`:_jLPYH]Ğ=عyFIDGPۼ'P⬜X̉,tJ1E %(MuaPYHYDZ2֨V0fK➻2ZX' K)mk) }U;.­53ʕ} esgBJh.S1f+镻j*V偾=30Ì"mdwa| /Tj(7pxCOhٝ,TިIH6;wo\)(zڍ3))0:RIIe*I턐*e͉acޱ;w]lYijZ;|{vAעQT΀pz @WK}⋝5/Ǭ%%o(* Vs |a~s^Ҧ5=ۜ7]Zn^w[o)I_WM9{v'*" L`zz▒1z,mntɧu1P7t-˜9X^EViK+Px +p~qdm@@ >terR}O+ w)$PB5ǖJ6[z'rExEF,?a-IdE:WHW^.!ϫ&E*_رEPL].&{nh.+m#z˔ד5"h' 1# |jxDT"{-ax CŘ  6`ƢfzVLW2>*x5x#fm}\qRZ6\ُ{RH~'9GfSK!p_ x>P"A)1p0DP܏pp/S 7jY9ic,dw,qTYvAO.ks>:f\w@) C!4(w{JCgkQ밄2)2ǒz el?oܦAzPN$"[RGjZV~bǶ曵GC?}@?H (Axȷ`X?__?H[QPMzMwCUmH0gm[`-Ծ 1+72GDk~q|Qك$PM3#dT!ptUB  I+r˧ֶedR %1.vvˊ.!0 h ͊#&Kj 6x _a紱fٗ DK; /{W.C{o'pT8Ϭ٢uLS4Nm*l.eFb{E3W6OIMb4k{L~Kü5žV-'ē}wگLf},ik}c .4#?{9HjyB'R1-6u\FYȭ;4f{v9E< b($ m0 Dq` kO1s?DG˙ch)Mv E;d9Lc gN^ɭYjB:g4h5ZȍDHܵC{'Kd])v}Ƃ\uZ  s@|a\7(NkEmnmh Gn:Юt";DF/bX+(f>Zj#ȹ(Tbh#{X jYX=rN&,WRk{z7/՛}usޖ,0#WU]'6"dJ'/)"ۖ_ __̗A0W_*SuQ;3U^. }L72[]1{#V8>98سA<`$QD@@a2bax1Z???GO-C,R}6N-zrw+^ד"Cu[o]fzO}z:_Xӕ앏mZ<=h…wu>4;X,4,LsDLF .˪>UV԰mEkvZq*U{X2dչ%vD 0w޿+4Un&|'o'HDL@baSZXBQ0p <(h? /m͝-&RMZ:r2fîrf uXf[u!fn%%^`fF8\oƇB%Cw'<3, K[XJ{ %Hœr<^$QPUvIo\鞄}k_Qp"Eh, d v= m ׳2G &8#tLƖwϞ{OWc\[ YW=MTN!ŋ)dtvi41@n~zbG 9rkƘ>>|F;%HU &ꧬDK\m3K/]7$JFޢp`L{2,[]_čWˬ(Nװqˌƻdde:V ONXOJRڱW%ؔd6o̼ M8UV./޷ է-5z$(x('P_)~c!")dIax8K 꿀2W7~=1aKU[OTQ5{UBfx`EG *JE(nٻzbػu"E;%6'="ܗ$TblaEKxbOe݇Ԫ<=]R;?MBi`,Lp\Jʊs,zAjnLS> ^%S4]^Nhb?rQe#u廢};Ĺ[?k?}uuAϾUۖ;䃉v\8;u4V-bEǖwsEy'^3&iki>7;_}4K -4{8aر}-}v9SI#Jy!snvB]1!EMBdlk`v#OK>x^?qBK\*KN"$yf*]%+vɶ.q^MM/U֣>1D8%Mg^X2 (8KĐHx"a `c}F_n|g ZFJ6JMyJ9L=%N%?y' ca:myLB@-S]?jTMK}W|.[BB4IpC2Dkbz$yi:RֶY;#NX󍅅bsT֩#&.\zCv͞*MeUϴFX`!ɝҋe=uf~_7`Sd?U =\AĢLn9M>g8(|fOGxKv:%ά'%.[آ<@ ے+B%-+jDg4v+{;B)\,*zi/oƓ|qgB(k#G;7vBAOzjOM+=O;zd^#((o\pf=b>^]cd2z Dyt;NEGzys  ï0L )*@ڏst|0$@$x)2_ 0$?R ??j=)op6>Ťw3=ql;k}Iȹzm)wzca'BdUw"Q&oHz'ϝNVTR>6ŋ HPڧ|܈#YcJڈ @] ݼ/9({xg쎆3d\#Jth4p~3Q.xdIk9On0ת"#]qaB`^mPw;uTiI f4s켍/H3dVPkR``{c)F`jq\ }1l6UIO],ؿ4B}>m5ٮeB?+v#D{zlN2NNmiM;D\P:#yC. ljΈxA4o ѕ\*05 q+t<Xں~}tOw㯕t5c[9zx*sLuc5&V{kϑ.Ky|sq$am嫫RKa7* X pAKҬd9dxX ,| o$ ;H9zw'OCh0=0Ru8LSi-TӘIȉ=SXɒeY8ᬗMm̈́qHHjzg*(玿xG}` .DKB$Xp*LA6~h/OoxzW{VTCWqyF҂vZ`hTSެU͙£ 6:O:U3,[ k0JKTN?Õ3?.ϛ~*Rmkc~z ~*!$_s{vEbL 1J2g˙09M L &~`Ujk+ܚ'nlLkiܿvT\޵]V,\];cͽL7sivIH[%SYPcBɭ5:3$Da_:Hj|5\KZu`OكSOvSk)=|h/6ϝ^.;m$df+fKwsJ⟌QV:ǚ"Z:{w:#+.6?n ꋖ_5Rq#aEbm#?oܯ~CA$"0@FXL b ?|w0i(Ds_h;x&=̐;?o_-rъ5STmbD5}msR)C`([RYLkhz7 ~9 |z#=:n 2֗$&HdKaMZ2}F9 K귃^f@ַp$epB͂fӏgYu!K=s3Pc#PX[p 2(LYKP~G`7.Pڡ`.>ч(L, $뼲GL=4O9azSN}!3PImhkX&o}utgo7S"Ĺ0z0R~=eϏ#@:yM;}wN5T1)q ?@A`4p0 ¡N4C!7g/?/wGO[ֽÜr`åQRÚJK q s?R;Dw Tfpe%-q噍 >/1kW]-A2%ԍs]$m ;L8kj()m"y9-_m71׈zϟ/qYu(d▀:J^;8F!Yz s;k<ÏUkGF  zk/_?|3|BIPH 1(00OapDƩX157b#SOn}DHB+uSL=o ƌ[qXgG9W>.+ B SiIoe~t3Mx&$˶&Ҫ׭\T H|Ӟ޾"Χ@2 .7NV,1j>LRUz.\k[Zm1IaU"!b#ᾟ[Uy;}2 ]A,;Uh=T!HX-WgWLߏƘQЗPaGXRa*i!*86)J՝fuv"|J-ڛ&wLrטgA^C=}AQ>"zzcJIO nJ F Io"fo\brEү⽘WJ ,)LL=g`[@NOb(l|-N]u%pȗ 玳 @0?p' x &Aa`/w;}":}jx_i* k* ͽg@,1a!-m Rݧ/͵WO178D*'4ū+RGYxNv`vrRlvrb~S t"/"<5GJDЏG1 A80`1<F0Xہ a KW l޶_8< 2xz0+IH-M%"Ylm!s=ڑKjm_Y[]#QS3^O7( yq &[Q)_E>u u]_of e'lpyp>>Y_yyofDŽhax}HsjONTRL[]y$Eh˰$yv9\yjvOR5 W@eOnv_{d4 2?(ɛ6!/T@DcZ1,;J@Rm/z>1}YARx'5HA8ҠΣpyxRz͓yZhէ@s PȤkV\f9:5K=!l{.uX "-PZᡖ\֧چq)-Dd}@C8{ԋcּq&i]PπLT_݃rDwFx$\\or.T)d'uV*ˠEj ¾RYXC+#j+vK]m~mtL!g뛵c[2jQoΏSu ؊1\TiF辚XzUΑMúYR%.x'q U>,SW)vh٬3,J^7' Պ↾Ŵ0}YER]ͭC*c(+I^$Dkpk׮pa{q?YJCϾuθ37Iy[ڦ WdgȼN cehĤzjnJ]< Y3uO.)v'Ch! 2%W0+}qEwn  ~mzYځQy,fڅ:ܨB؁P>jusJg*EΔ(bugZw3C$ ":O|}.5X;xv3iR³编3/5L R+ &S (h#;>OGè̎#c3E HO'}ұjayj`mWK6njQ?r!BPms~*&>ĦZD[FZ*0A_W, u""j[Z:n(Ԯ0&xYj(;W!{|t YSѶWG}4I"~z۩ᐥ<׶-rFC<9+֨b} L˜F㵃݂w|uOX9-Pl x.N>q''7"xj$$6|1gsřdi!(@ݜ-L;Z_z4eDfr ,3JpE!.i^i؁FT2o Mgn߳lbEOu~VβyE:*ؿnwgm~uzX踚=8u })8~.T~'bsi_t$J[^&6iڿȘya]0u @κMd-{[zR/\ +4U_~IS9qAL,х[$GTS|BT%QX47>dJusW,OM?EWnVsBjXj}0}`)~՜9@'V|~n^'Y0Ltu 'rDuK PqBz~=m(1 b+Z}/cWN ]ovF*y~~ey׺6j;;ݩi?G;6Oax;&=X~ϘexWBk7 z-z˞·$!ڧ O4{FƧe{flBh>w紖N_- 5}3r,+mUe:>]Bxim8/Yrh뵩(dBSer:ܹQ;}sǸy+5klb˾G׀o kYSBpZ5;A oA.Ɏ|~B_Jh{I̻c7uP.] b3gz%#Bq\o8E6WYۃҠ^ƴU3#9Xeǂje^pXc!3 F;v5`^lcHՔN2CoKŁEe"m,}S {ƝT^ю)R;Ւ;gV6ŒTkiZRKgR򥆋cS-Mߴ=fQ^kM;G8rZJJwrωB}VPK=9zXU9]u{~ڈÅw?zcGy"higf\j}Ts1+o9~G@(I@@PpGh `x BQPCv;p@ (+r3$#ƉR\SLtAmX91}smS.nvx]tX,k iy7hac@"X@5By΍GA'#U 4 N9QY(ч<ʧL1/a&,fKftvlpo?*&i:-Yu/l(96Hٚ IzZu3DCٛ~Џ8X04Z{ ¾0OC}7 n`u)B4lux*ngVu>{^80?,V5YzS ݃JPviXUXXoZMMe)>=3ўDkW(1/mNu-aQ!gDms` G޴(Β\[iCC&۸"6Xׯ ?`$mH8]#?3_7d?xҧ씦iOȻm)]1JFk4I:Z- K0Wg,DK'lܧ$ %KOqeZSg b6=(`3wIm>TjpWnB_9OݎfګrlO}AZ:/WǗaAGxO]<_=`;N6`Q],( g7;ْ&S4<~ c5.a5YT/#䡖&tCН7;4S8E:S1FyM9_9>ܧ޷0EiOV*|Wۈǿ d@  Ł(<@?wkjr|KNA6.¡$>R/Y|0>Y EceÄwFGg'I\sC{XJkX2?y3HPNuHZʒ#$VJB<5%A??P$0~Bs0D^e6 KfpjXUp܁B'dq UVKgz=7_K577#ts}H2}rߍ~g[C4wML;^^_m?UB/&BSXv\H0M^^IԌ|qx/Hį'nK`j?Ӫc̖7%a+ExZP g%?l~YGdm3dTvp}c_ZH3w NtFVY/tYͧ /A2.$sw7\}_i^'bw5}{z (-h9HwFN=M9k k8TK2ĵҞLqW(bu7+)MoΔ&ב`O~Ğa G 4~  ~zlOTsx75qrW<[]ϵ\ӕ-5ʈ+ٞל@!L+xCC; ui 9l[lyj>Wǔ58m(Zkx.}V4җeV&ߝF`h=k#xZF /ـap.$Ǩgz.Bbgޮ|̞yͽbNdzxSлZ?֩ |N_Rv[T>$M(f$7NYtMWg(@@pF<0O1H bKu|47 2ν~(ho|mdLTBV]4AS|sq@Y\m)iՔ{s5ULF&1_ WM.b/?ؽA -)ƫiZYzkf>#y[s b"qm j*/5?m1p8Bzw!! $ġ@4 pX a@ C"HOAA?(wK}sS?fB5҇47dEnc:,urW{]OHs _t4e]uxY2Zd3dݴ3ؗ{3Fj_8Fn" |YhfEcQbGWՒgȍWmTeOrJ|yT($ 4};=874np 1 '>5H" "#G?r B<ڵƕ,Fо+~e_? ?f!BD̅"QDh@} dna)/$w/i?*b- 906Z[p-+JQ9䗩bKcrQ}{e c?g=kX;(XW^|e҅,_iܻ°×[Oy)*TffJ:Uue>RKγ.V_* i^?Gkكr_{Be6C7bNy퉢m ? -L%U@B|0|s)Re,5Иu-y"ηx9´Ȭ0*ȫ\T/KC|+%\60rNjt VWFRn;8hMZ`ֶAU S B&;|}H~ g65N%`.46_խL]m Xd{QkFsƤ#eI*j2-Bq'!>Qm!ʘ>:U6:I+¯Y8 OI^Ԥl$rrwčֺ9~^ xUg)GEǏ.#Jmk$뜷X0 n;Κby]H r4Hl6ͬ::6K.Vtl5z!x > o'QGUY:V@^]hzyb$&t+}fIrλ x8re(]S~#&9oǙцoW gC/%m2-. Al_p4[֥E9 sjyUvuM}{S;6b={;9%Hڄ\شP%JBN`@ݾahپ0%_$zN#(;ŻE^Mۧ*xs'D C臨g5č`32Rw+(-JY?en0˽P'XFx3TL ""syy[}Q;zeIZ/IG"FC!AkFZ׷Ÿ{'O.\6~ίM$ v6U7@бZ#k+p בs+%3ӎ>ow;?? SasyYkۼAϩ_-rƶ6w\TVLX 57?RuHw-99[W%ڸ?5qc!R?a=mƆ7\jf.G"C섇t/=Y$0Gi{_z|?}gkEX5hx{ #dCYJs3ʟ{@ 4WqwCZlҁt[K[LzC+4ӡiNBwY0Udr37EwL\I&vǟ+)z]0j{r[V!2GY/:(u˾+sS /),Cʽ|\Ntʥɔ7_S, 4QI ';>G8Ȣ\AODA|>nExRYl5jT!KUc]3SM2ޣ·E>ME 8֔Nƃ=|OyCҨU}xqpّe']4ݙDUn kq _>nk(7-}qI܈YV1_)MFbdSCI (^hF)gryZܾ&vnrq{Abdl6 'yJW}mB3#vOlgxG5 sO$xXKSop -pX*RK\ ߖ^]L:)Qc|`d^́8+1]Q^ED0BxS.DvDOUqtoKͰ8sWƗJ f-n={eJw}%O)]Ӳ3Y>#`@֮UH&.%#R<#|sE~k̘f6-O6wi"|*=nfI=^Мz$STlY;dZQ&ɫU8I~zܝrWF8"oB\/w>3Ώ{&#Epںwo>vBn_/OɔzY\Z[w<Wji%^?1_ܡ7m C /:l/~ttblQ[Y$ I7cWF܂]€% s ;+a$ޮКdCMώ%1 ,{)ҧ]/BXpdZ׉x.;8lc44.~Ko\3H (I\Hr9J:VZBRțX?N;Z\ Ut^' _RhUrMMya7 /sD$9X.6g}\@Y=|c,ζv+z#o-mn=6!WPaeE ơa]@m|e7T&N5,KӯĞ>q1q8Tڕoj<픮 eRZ4@m=BZJ#? %[.6lzz&23>)I|Nl^OA#"MJS p]YvS%c{:Xl~9|,ΰ*0SD3)n[xL5| YtT4 +ֺDa<|Fڧu]a/񆧶OR$?|upK봕hݴ,5NgvW!G{r vVu^a^ !8Ċη]+>F{kijZ6&<=_2&2PDžSjɔޟLٔ1¿^+Ɇ5 RzlJvFyy 3 ΄o\GשG؃ibEϷ}&j0̡ b};v?|PQm31!iyCAKwe G9%{ߥ5ҿ :k 9Bc>d8_)ag|JӦخV9иm;/I6+u)8&MO0٬ÀWCty=g3_G2Yd!)t{T룆]ta!)j>2o֊?0O_.>9_m^koYܩN\P,3Qw>˛~mTIFnޚ\ U})" =Z>Ʊn4WXm`Ž|* `~[>NP␶Md'g[Y8wü©Fsp_hݱSKZb9Xw P7͑S"LH7ڵb2ikvRJL4hj~lC5x'3kQ$YdEK#>Q Gޮ쁫2;fSn$Y&3`X29PHMڭ?WuJc[wD\IQ8{W-X籥j?eEVL{P΂.ۓ-}8,YI]}Wn[>6~ PY,7_V|0ے`%{Q j/Ts pC> pOQ$[V 6"N2˭}Xgs|E?+$/nV 9X AZ BA!`)/iUj=[aMSy>5'4{Taz@zo~냽w#QxiC:w-GzD|NZ15/O񿈠+*( 󂡂` F:` 9,$,",l. !" !/Ҏ]󗴟SiLT^{=!gLm]˭w_:W_e:hV7G{>QW@XyHJd[Yq#CD)ZTIpMŮw!,,pILnu\F9e秏=}W}])7k(Rڃe߱<}vp!xjQeZ0^ZdD#w ~Q="n\< )'AA8ey,v>y! 7Ǟ$^UeH̯Xr_}uLÛuPB'>\1g?Aca[`\&IszdUa 1Gn;)ªOe/K dHK.^ɉ# S[7(z9[U~M Tv55Gˉ77w'IZ<Z[?Jƻ4ܖY@bw&y؍nH~8+kKXa|Rgnf&xj:4oc?5s9l+Ļ ,b %yM溔BT ;&M^'x \v;TI,y5HPvz[IV<#KC Ș3sVfN6~"yJsF D#2WG I僜Sj2-.?W>[q#_u^B_YIr=j'[|q5 QMPvWI`aIO*yՈEYMO >V # %G Ǥp̻ZF5}%[KN/$ڃK Yzn[k14X>$W3/_pAO}~ufqO@ -OMC\s#))Ü/+4֤^"װTĄݻs<iї9FH w(.aؗ5͝䌄OFFO|I˯f'Y?c!L=_JK->G7bTWKX±OQ~[U&:~W{6&M`9}׹R3*72M%?k}c}{bˢYDP0/_\~QדEJ1UY87>䖣˴@+mzLBʭ#{dm.\ WyWG77IlwKc''pu FCn9MQx3n{JnT+UKZrX.d?q8֋e:>Oă˳&iݯkKn iW/ħ{ov6鰗= xlƁ;$S 4&!+Pw4v(S^~K|ed}0=6EYn-A![3;D:Bh?ym4xє{dde+Nlwpx4u'?6nRw~ cɛ xeYF"vWEUCK0׮,vg΃BVwceW=qů_]VW7>g;d(OEvWZv}gV9.?H&؅RW!#B8oBYǝhۢr o:8:{2 (x!.Rgc?o]YH|X ~"]}PN"ɇT(_%7pO$e(1cc'үǂ1vLN4(y;\°D9<~9S?L G)HYy×+e4X+eϤ}7BU>/48U޲・ZП/lKT7Fz <6_Uua{~M*ӷGMz|][wrImX]]Fpma~U#O9Jqmn⃮wK}bɹm e'>ZS{TH?ka@:D-  sas(P ``! & XP ѿ#w_~mByQ؇ G6avѬr аR Ԋے7u6vCܭoث_Hz h!Z֧U7p8|GWRћ&[>֯ǭ-ޕ+YBzfз6|hM`QeAN`Hڡ!!scz{jֿ%e`bA7 vX`y$[8HU9tst_ w3b!{iBws8 /k aY^wUW+}6kGT#3/ r{Yܛޥ ;t[!6!^*٫3ktoI֗f͵L#v &gc@6|'ۣɻCQ&MBob <~퓗X^Cם?Gܺuf_z=+W\7/9.<Sڤ]pyT_Ļ*e iiޱm OȌUҹ֝Ee5n_uV䩧8थ}4С}m@tG=Cv/?%B`9B"DBBP0j PRDXDf) !{*I]!NJE+cyW;,upG811h|ݯ5鞕P}7gH󝲼;]!'u)ǭ'[W~LJSOǫx};9VuDcn'S?JFU{c5ha Iɨbڨ'yu)kx OG>{nM|-( Oaڐb "D‚񧭧vz/LFS}*>-'2R^NHx֯bt1vN\T/U҃7-vu)yxZ'GȦq tR$+ngKG1b6l7u,t>:?HH-H5Ӆ\%c]6Z=ykx",~|%J:ᦖN; J]Mw9}!+lT'n9Lj2|]~;cQ}]Y1>o|.\[RL|7R b(屿 W@ GG~jhBN}yqicR,kWeR>H>!vUO[y5̨ -|'ҵlEdl9 qw@&_W?vY t)39Tq*BPX昨e,,ܮ.\XR;:ҩjX rJ Q7e;Vn45?|2d_yZj^fiN%v܀i{uن=ٯxxƃ}+upk"T3-> Xۄev]vn!Vu,֦-'^XPKrC <&(6[[ݺ@0EBo6c㑱ex\U7&B˻6$l[i '<1^G>>Xӧ+F?1ls4i+}Uo[3QHb:7ҖP\K4Ң?n ?t@ئWVYq9p6_h/+'} Rn$twG٩$ɵ2ݴ0b{~HAa]-F'"/Sz=[jSQgD˥63Ċs^^?^Կ@|QYĻEZN#lNC׮1 i>o-a;Wb&o;WڥvVk B/H 5Hq l1DW#RrhSmB2FDԊr6b\>q[$mBS9LJR͉?.ʳ.g%J' D {:\~e.8;uz_]P=MͦO%ioHhtu(C蒣8X؃4gήXq`z eQ( Ïs* ߠ8 ^"s࣫s".GpwrVsfc1gDHrU ?}u/G{枤7Xߥg&ۉim{M }~0gPq|Rջ* KKş;:Tʷ6>Z"98uv&440ttkT PakУlm>d` xIAd]r̗UIZu_66txw酎eGFSb V>cwiM\l=GZ+GR+%9c"$y[rRuۥO@'&{<*nbڊ nZMN`_{#ߟ*j'![y[0ݻѺkp1R/E=?}/ަU(d:(x8u}b?IT,xgx5ң3,Y?+3.DN%c#Q=BcT Z\7[ښV.Ikw׮}Y }k[$GI|]tknok`OdXt?sGH7x Ia\G[Z}<3<ŵs] rR>)}=^PJJ^ XG~!f I8/:HJ񻫔'/lG%?u."QLoj|J 6)YC{DJ=Vy[7nB`wRR|.V6gs 11pąg'0PKlxv^$EHoqj]\ ".iDSS9'>kqjŤ7q&(c%<۵cZ& 6e)^e3wO+DDZyݯtz˒3+y>b7VPךsF箚(0)Vrr&'y~޳NnOֺƒK vzN9)PՈr7g4bn 6<[=n^볼 Ъbaҵp霴]o%Z;%bB 7WK^--#3R &g.RVReqvn59Eͧ4l=,yCuI !;%o 7FL"kWBO8<=&nmő,EMZ>OΏdd!CvQ/65 IN>e&_mr<63k%?SXRڀ7MT]1ye"Mpсu{m'JT*#n︇; >\ \zUoRC OPJ%{9$GZ *R^j$vEg--ŸUN iծW#b1ҲgHwB'wj/Qxn"״xI]Cǐ0qbR}[}ESLJ3Tn5yc·}|WxUzwI(m7 3u/ ۈř4^vQ\2JRTfN8cHXLܝG.5.#5^-,;h #T"MR݅RڂAEPA}`/NA`e匢Ufۉ]5ŃMIL =#Ľ&puII脮BÈYk`+~L,6R=fLw\6cMTS\Zݛ.MFcWvs_ҽt¿J~!I7 T:wa}9+8 .\̖]ӱGh\'n1KqJ;rxFCj_/sv}:C3QjƧΊvsgI5wrk)cbA`;c)JWܓ)qMz&UbeղOLU /P輾c!ꩄ)H‚Y9qڟ*C\NL2Bo`\iU2R|L~qLRu_z~+*]nq'sI\_#HX@_.h鍉wmcM 늋) ME;Or!_r+.]:ǚh$%A]z.$"t #{=g}LFw җ^hgb T/Cц.<+)E\R$<[Wӟn ڊ=qiJfDzI96/wUej=(VVx2 ޝ\/%y LP*w膏f#.8QQʌ=/簷/SŴϦtS;C>LJT@QFevנf)+-%3s| ,Jz?)} qk=Hլ8{^y>sCfA^/ț廗].ra\y E:{.>֦yD.ݽCߘa܆Ŗuc[2buOlSV^M~%^>Q$ka$>MT7 !#*Yg"ypV@¢,lM% cc^&R<|fvv:bmr+o^ًDsNt}o]_B؂*!5@##QX}ϛKI"|U,*^Qb.?•yXCau2a7ϱ),{#4\ͷ=q__HR>Y~lt /7RoӶfD: ~!VD!>y$SJ^|rO~o'J{[^oXnrMK1w ܰ1{l<|rmk#hSv9[*y 9ZMIdLM$$ D{O,ZzKIn^ |M>ܘ{r"«pjbFWm>pOUo[n_WԧLBRG(=،tsr*Gs~)YEZ,zq7^!{ B)ݤ?S^5Yd>\ s}k"_F2>/3z.Et{!A O9RSy~%t+oyBj{,97\Jf'3;ӵ Ԝ}k$O.^:7-N)qr-)ڠo]LZ 5ʢi{;M*wA"VxDC_ۛبIi ,vŝ;0{0Edi:3<<)( ?'?,6D mlbF謂wZ(d/,)߮!V7P0XYٯ^)z^cenSmqxcaS s0ܮw1un[^72zDuQj]O)aB5i[Or2X}oح]@l R2&;P!_+d[Zrxm e6Um WiDS?^p!eRt=m:ͣ lk̭5sWI.n (uW,^ #-G_uQ1(\Ff4DoTW;ѝGKEH7]$Z_Ywasx%謵06qrkiʂ'`~M”}J:ʼ7K-_JT>:޼I#SRi+s}qhW̖c^ܵ)6FTxKii8p~ 㐬7ST;!t ޔoFx}?,,]6/@da)b  YZB` As!(@@H\B -_c(ToxZ_lL.aH{+L }hX[!0F6gTt L8u]/Q=sϋ" 3PN5ck_f}kkZ).j)ɨ2/1^Jbva`4~J#:_ɜW ,beq anB ̆Ia\<Ô }^bN'{N\?84_2m`\lT9{%p iۄl`@-кjoqˀIv2FٺI؅ImoB;V="l"(xM:5$Rqa+,DU3m")pw /mmhQK?J?+QOFoZX BZX -""B ?S+\6vDŽ#H K\GMŘ7e9۵hO7xmn+Dx<- rwU&']m͐]0#Xʦt\̣aagRsϹՔITWr'ԷAh]s{ps{i$!y; +7A2&x&IJ٣?{dGSA$;%6)#Cy <]+Zq~^^$P{"Fs?v>MO?_Z6҄y׹J[UoL݇}ۈKz|طXn!EQ8t;>Cqr6 : ,Q׫?-n~g?\kM3{t^{YC%"DTΑINL{>>l9"9 x'v5IgAGT/{ Nm|(5stxح{kK@s[;ܲL^R/Gƕȸ{#4} IFCsW{Kp";n]S/R}{%.ƹ_tYv5s|Yṕ஽MμG'/s1 b ?}=h?Sɍ.:A!p*6td_y Zr$j"v^%ĜQ"b )%sǴ 2N`8nKq r>]1`ٷe[w< [ /'임6KShg xw:Y<܁EyoM1k:_BU@Rc%rLIWS/ ݣoէ2lŶo|7J6S-?'GW5G鰈|/OMh We0 g!q˝ui^*z=uUZޣUFFR[ջlzs$vgS+f`uy{|,&ا@2}v ҬzD9$ /;:B6ݽQt>k|d=KzKWROsT[ "ܛ. }(1\ʺσ݆}Di.pR9àAkzʓrs<,b6&uFb LwIαw{U;m0oΊҺn!QJmw*.gO@T@ Z!`% ZD #/ D-E@0s@0XMw_dtGUyY(H:߿]m-E3<|w}yNoَ\zWx6s̹}TpFZתdJm.!y|Raq>"+^[kLKϟ(Ve^{&v_ 3bsq{=@>ɧ#KWԦ;pGc櫊֌eR%.ф偧VJ}L"pQ=[@>?Wu#sގf#9C>7"\~l)k򽽂ߜlذ}K+ϱho<-!$ TdvK^fRUhDv ̺ ϮQfկ^63w4ugV0á4#< Yq!n:|PvzAXAʖn bNo;(E.A@ ]Ѕ ƍ=Xue2B>OI^JYjo|=f0{l΁F%w5Wz!NFRӼ;D{!\qCC"twiDqs7u;f Նz^r\QEY6P~D^#aժ6f Ewez7\QJAxucR ش`m3GZ;~ E&gvP{R[SfǤԍ{Q{xQϢFV\t\U ,Q}VLCiFï]r[V_PG>qxoJR{͎U +wH6d ש8|곛&t5c{Sa4z#Dwip7*$v~N{rf~y YTr'?5p):ߋ+ҽeEa>0=8o%bW-j{aj?lL}U=u'Y/K֎{0ޝҦ$47n~rMJ(y8el+贷*Yq,3dɇ^kqܿ_4֐' ]B_:JCCQqEll8-)@k4o׹c+1/Bɕ ̶k\Syk\A:WR6:[CTv2V_^984yiPQH\us2VcPQu e9Zk߆ʊ]i4z3-\⏶W+݅{i3]:2CN)#(.ifT} GN_ 5Wg~Hfq 6D?AzY;2(!j{<%J7G ҥ )Ny~ʔhX8u-(4HrZ7\rqV}$ԦkKOwxyXE}Pt71:2L箐~{?Pѻ"y: _wYR`ӝH$ j_}h4`aeUx>Ztc';W]\+{N˦lV3oUG;̽J@jX>> b]l: %"aLUj}:`WF+ OZ ,I. )5ͪ2G7"DZ!~q"xʕ6ޠ^4~tsܦ{L! *1vL8{ 钍jw1 Ny QLqMdJw2O~1FdXL9J7VXpeX*>HDe_prtY*7%W,O#r&L-z{V^݃ |Og﯆sG7s`^_`Yy,yĺV@.-<\O$WGloY`؋u{K]}\Y,?~98U\v!u.$ʼކ_ٞރ;꟨+./2#8WS&̾u~kj4\R6×{SM;[)cH Yˀn]L8Q6T}qi_RSk[Gcg8\tkgƒB$|t^7g0{Gv/[] Ψc)QƳՂ+A)aZW5`^\tVFHjh^5]Oqd}2JY<7#K/e/;7v76Uҫ\S妧ڲ!8))J\p9ү@aT78eWV@KGd\-QSzb6xv;*^5w37ߥ!t ĸ$tUPSt^Xd{A =,%[)GgGY]\7[SGJ-4lq~E\]51Q]&]V+8L 1s帗V6Ԕ ަpMdU5>X$d$0y{/5]֜}A/F{ 8nu&,"8mp8%Y =Q%aF꓾b+yҍ;[ԒkFJQnrnb=| f_|V((yg-IM|NIʵ{^d>#^W§PH*3 ]6 Ȣ~14}A؂ SНr ם]#+n6'fQrU{E4}NʄM_xpY%|ShG2CN<09#ܒ@ꖞ1ڦ~ѪY^q}"unzcޤ_d~1Lrf0'U\YS%?]0ptm9E彅\6CU[#/%|#0}X͊{RͻGktcܧW/٨[; hGmMێz2۽R2/נ+HLFB)1`\vWͣ דy՟'ffg [pf%揈Goz@oɱ_YK;N#o@ ] vG }&`gqT/)Ӥ$>ǻ3{T̬8*Zu/ &eP?yǻ-@IA*!l/cj T61N)eviiGywK>n a35-|)?IwYUA=C(ou6G'R!]׍}cC Lew\5ƫ_?HmpB8؅ U`u*-pCN+fIf.:vůfdG:Pd_FZ'5^9XU+y['0!f۾6CFgUxuSݮMM寽7$^0봞0X8_C2]3~C9B]蛫5ޛ>+]' ψ j'枒{U60Sr8Ϫ}?x'~ P|\7(F&u} rkֱkCznU(-o[NwK0d} [@88h[[a@,B`]L]RfF.:I55{YȜOē[ˌLx;I dW p @0 ADͅ '_AEOڦ~=%I3 + qCB%, Z<`#~t/ɴw47Nf,"Z4x۷{rHyM8cdf0N.\5)X LN<\'J=\DsV;tgcD6qgHHm44>{^Wܗ} '[ ?};jl:|%#_H?j 8:}LSqU؟X&U:.ד1A6.q'K6͞\)%HS@$H(|C @I|L"]Fx KYn3)6, 9S :+ a AQa!9(,@?BQ,!]^*@h`u]JT>h05a'9ڭ 6UoՋʆd„zSֽMffY".Yd>΁UJ[BTUAދ#ɜh\sNRm_BO-m XRZ^gzeٝ|;iҬtQH Ӿ59Uw./M/$\wa/KoeP^\й/g[^&M utAON$"^ݑr Vvm jOrE (N,!T3`2D#XhH>2åd/N 8aӾvޝ@}6A}JAJLz*J3lóHy.] vAS,+C*&O9|) Ïwf$*< ;Dx9r'.xКʶ5:/IUH:o>q,NaQh:ϗҶޕfQ6 rod{v`j%O-rDV|D=H=>uh~޹ǖy+5JhIQDq?VQYB俀 C9Y A@Q @@(0ͅ--~Oyo/i?M.9>z!JK4-~t\k٥foxS&>ol;=Yv^3$pi:`eȹ1&9c>]dS<`(=yNiLgcʸNsoaJ‘ }H!]K .Ol3;VAjFjf 5\Rݗ7ʩ#;jȺ2/OKrV/tt75Іr^4 :LvtCAnQc}$K`u<fbh&;.?vYR*|`- -\Ʀu~aڻB!ig! FM_Sx>V橒칬N{MTxned?'An@pXD ۃ0fiߞ \N@b|vwK+jʐ&H`eYd>qoQK-bzKAyq S,Ak}i}'ϋ|KC3r (_1;^Po?V=|ѸjGšUsݗ 6@BօJ.ϰy`OzOsGzWVJ'2J/ 'rŤqwR;>+V1HN^г0.Z7Ou\4>w,OY %__<}aQ蹝n6#41FC8azEvk7c?> ;rC=y ?jq7:[ {## ymJ|)ֿ.0K_(!//"|NFjs!7q}O!4F-ma.0+B ׄ*C"W j"uBߧxz;;?}}2^#ߎ~N{TGɜY)9iP2ꚨq;;)gm``{38ꯎ/G tAtOWt Ol ) ' !o(-Prk#y5Hy7wq? BhHGhwpBua8Bm]a.H@=@\a,ޞڂK U_^s8~nn p=jgE]ur#wfWy 9hw 5Ol-h~y%~u'7 _ωdawDp\EB>̅ #xR^P%yfqC]a^6V֮aprT!!(.].[Nt6j^1/Wk##baC!dB'acaA ~l{sh?=AMuG9Bq "/kDA;(7yhic悞okaS<wsur;jeѧQUדUCuh A"E8!%K4ŚCѷ;A, VFx!\a5CxQðqDJ{PyxO0W7,{z# )(d0j0$=xá^ȧoAmWQtqsqJ;Cϔ$g"qs" -C PHwuAO~6eY}i"쎰rDR(Ivvh,Htك<ngCsX@\qIgͽ]6 ŏ>udtˆ֏OuOB. ~z^x 6WqyOϘ#M1 rbh8! /lw9Q,;o#9+leBey=t(_C7DS60Gi_w7рA9G٨ppwqBZꮨnXX3bwD!$,wD݋Z"W14__p3z^N0FTtH1B>:a]qIiN.pwdatCAT>{k#!.gg;Z!iIQSWMFU<򋔹 * wXIR ((DCet@@A(h?8fw:X!>'8ґ@PyCTE@ .0 sٷ= _(˨ohr6x2z@`.?9%F 2<R3p7 6p C+u$o.;H/,8!iQfg2Φ˝~ v S;txN0\-8$kT6HHm+B79UvC09"!y"Wu/uDh|"g(otpG!EA"hG<4ʑ (, ˨$DGT``D8wFAm@vhd$TW$5#B3ₔF6(ʳAJJBq)@mBؠ@f;@@ (p&~[L@R0B]!aŃBWY "x7GFKRnϟtS/ 6!o@mVrCQ&˙/9"tHKR=r.#rc *JL98@Paod'9R DT]Q!=IsVy82:"-h,FJ$3E rw(6J{1CъKCGA @!H4Th@(Y@ȹ#MAX(" b»!9䄹ߺDZ.xQ5Xi"ũ9sBd@>FRBA8X!sRoSfƟ/N eVcHnFBAi#6A^93/Vf0{=c@hPUN~#A;! Zu,hG2z] RθYlQ4SY7LT`RCڰBK䁒H j~&ċ .p3=n)39&dp(/r!QF9*؎Jh@ovRi0@ .eX̯v!MuMiFT <√-RݹM_2d} O9 ~~,h%Ni֤_  "urHNFTfG> Ry̧ό#rPR-h'IthA5 R6TH2@jIX0sS9SVNH7+9/$QÄFR%4FRY"GZ~Fqnn NTG(O  W<@HW r5}99(,lNEl2/=P6C i%~7K˟GrAE;<:hTT񻵋rf6 }J# qd*D$*̈.MBG6x5PEH 17Br \Q! mxfe@g;؈0BCō[! Xoa?xY< ?9/J0Z#*B*1_#Y<-A֔:tZ2?NU)S|:{Q-{rj P+rĹ jteNjG@~C~e: AY@ 1994ѪGL{FrU6)A>P6 =Ya#a"?IEy*FPˆ$_Hk!{\xdz< 4ѣ8C?aH"E]E\Gz`G)Й+"e.a۸Ӄ hmB@`m#!lл|P&)g۸"`{> 0i*: K$ĩO`AOg=271~:E4#[OP"yH{p?d/AhڱusC&F'I^h-6v:lt] ?bޓcВ̤Hc lL>t(`KcR6$ꎩRIOOOד(+g[Ђ8="l·p[Ț)wwn9QPGVE8eW|DsaОVaf+oފ'cG *)J;z`kJL]լAk7(J<gV1_.;'o[Ò]mW ݝ=`;Uwj9.6?zZ=j,=3?WqEVI:+f-dM9巙}ʂY-W̛w∢c p6uBL%i= [BaͶB8,}Vr-^nWq`MSw7`/wSD 3&̰_ʗvvpw-rɱ.v9tP,)+\RsawD7)/6&ik9>"k=Qǧ1245 )XpgR- >+B(b?a Ů슕+N+Kaqwc+xqmʫܬO,E:?@J5ѹ|ɊKx~ל^}.Y.m y@]([07N6!}F JjN[kgXa~.vPؾw+r+J2Wڬpjm;7 f}"x7+a]haY)JBQx怌┠{xVSǾ%c:_' qk)O͈*sZP5YfaS? KSN(^ J4lkw /Vbn?Kxh벸@DfkNYwf7ߵAϦ2rf?GxpsP1$\3(LCϛB-!> %ۅGx ʒM$Ό|koDӬ WR7# Ż]sTkfbASg~}B۽r9Jn"v/Yh7nVKӮ@U!HLjjFz` *OԿBIB؊m MSp:nm(ڥWYR z,x BE 9;OT^z&!BbxzFMUͰbo : 8(JX)RF:dg9\/p ;OhX P6ޢӽeB;$U` *aȁ3U|<3o*g d_$%̿]֙|S,\"jrX8m%@~4_hX_0^OF3;H6<& 4O4TxV陼Ciè q/7;Q\ʷǙrTX"&$14MhW+JRLX&Q_b^[%_U& i -њCՙ!25׸JN߯Q&\IH$ 5w4K_xRf/}yqbE #?_U51PSܘ^R1;ZjHd(B%"3@)l,Րb/gb/)V5 aƹE5 >/bڸ.=G[Řw_М'$)y86+ׂ\=F6ذ?6,bRfog{y"nٳiQ(gPHn#@eN[ޢZ$8|oHzLIA>-:QК<)x;IffBdNzέ4!1su~#w2WNQm6{AVeKPClfZ }\(әh:M' 5flwIDª?(y Mo!B160v` ).LsF̔צ Z}*($zMLpMpA_:r"\ @QrpTCMӔ)9"ɇoY@9`جQ"θqѺZ+Mi{l!B,5H% 4d1^q(!> N2*u )ρxVg3k c+ rI fMtNQ-zVmx#'ﳇ04R cݐGDc^p|/`DRV%Oq,@VB^{τ| @:ʟ$:J >:Yᯟ,|aA<-u? afᗺvǷ0z-SM=SKap 4aW,٬2 L='PB`)|I^mZ2٤_s#/T*q, kU3F* hnM#D.'tŃ3I9k ]?KOqwO7oo$?0$C\Q3Jj;ZŃHQN%'0% ЇײP6-9AJY@azMaJ$ oFbi r4E891܄OM"02}/j9bb ьrQ]s8'qB~=-RK->L2&( B&(@w@$a$ڰVÂQ_ =bX 4U"r|r@ܒM_,$ZҢ|2f3fuM&RqG(=#/Y ?v)L ,c f{ ;,.GĻIO2(pɿP~Hhyפw9BzDY'Dl*b:> 5 Sr|ka2óN˜rBxƠ8nZw,xo}:`~|^ >jKJ)=JQV7lyӄ)[|p/DCNW@' u6,!v;.Re$I #rl<r/nBC]FÚXS9G5 }¤-t/;"5hݷ˜1oCe/x50ЛFgg&̛g ɏ2֫UV$$A[`DOzd:)n΂Ƴ$\{=A  Y@i/.u iMUMԹ?b1\TD΃طy?3?Є4.PNa!YoAXxh:'I(DL2rvg{d=p'hC;b} O7Wl >Ǎc>F9l (3fM W51xa!JXI2[$vt4RGe< tБZ Vc$FE-hr)yl6?V<֘|X)+^"ċ' !׏j0.YL GI˜Yhzs? f} I׬9^U`)%E4BCzK+4@AI鳯o&zHX7o6il6LbՈRG3xqi5̭?c")s>zぉFӠJ\rJA\gR<UCDZ7'&{Td2E["6K;bƹp{0+ fC$]loeK#8yus E`< i~ʷ9xy :&1Ի wmIoSLʒtHHrgXNGqN7UG2H"V r=/{ub%ykf!m'բGħ"XfDFmzC>2bb]T 3‹dH6MI_"W5h-3U2\ $@gyqW!b|^ꥢ?)shUrJʕꥪ:-ŢV=8ǃ٫A☖h&InEfyPJtY(0ɫP \wARI~?;/o%/:Z?j^ud`@$X_DUG1Zr/F(xz'1Zf2 Ghvv&fp1֌H9"MȭV!p&?J1OT?A1ݮ;׷FXHs<8Tǃx}%L)Vɹ i­useMtWr NG[گ>}m#0ŭ5ݷQ)! j9P:ʡIK-`m[ډw8|6"FB?UٔK*!HM0+=)aQ_|+&=h"Ph% 1^( )޼~:GYr/zaSl:w-ʁer_kL$ avS BJKl=veE޾ԑYNzYe7RXmOU%>h(>pd"Lxs*fEi|})A/T4pdjK(5*ͼIWF3>ǝdƆKo5! \Oe:m~3v Lp ojl$Qy̗ =x] _x1zaXih-Vr~Q,%Fb$`TI4";L$\J~E9F! &0/5kKZ9-ajStgk(L}kBzB~N~`aB zϝW(bDǤ N\WIave eg.c>'ezFGH}Qp7 P[w.{aTIZm= $}pF0V"Obmk2b1Xb5~ȥW-$k:N=Y;˫E'Gƚld姚mbEQI(aAD2w^'C+:&ʴ+ 9k"8hQ/FAakJVL)O.W!TFh#kQkwam>{ۼ?w_=9B!y޺lEiz]tdkeIZWG4{âXK??Gh6DgC !ϐ XWj=*8L߈Z(b9gI'"n@Ry+hnE$l2FyY9K3=UUWʩbKs>3Kh6g| hdNLsWAKmFH.:_oާ_zdj eb{p=OߒdpkBj0*L1LH.g(ub?]$Dī[½8eA_C|67R} 1'_ET@\er]D NH;C߭;{\8=Ms5늄&' +=?O3~7?/S7~,=M@J{Rd㲋ݻq&]ae,nY.lͲ!.A-+(>Ojj^;^"Ig@(o }OY}M31kwN&o<ó+59ߍ~cFho?t ɸ͜سHXa~8HFK< ?N)l`x4:o@Wfp}m.u'mVQg]<[-bmP}8I9Б).3+\ub=hDڤw>,O;:+~j^ğ}EXǟ nӁâ7?MD"37P-("pC˰T `Wl?Ƥ>g1֠PQ{ދjΓ<"`c冥>gmIϕg^U_0fxz߂[FZY pخsi̋lHO4@quV5qq%pX:.Y]ir'ur@EBZH5ŕ9$хR_˅,kkIZbDŽ6 E¹?-a_/V+>&^.b.FKVj(Xɚ~cS9)ƴr.B-_E>7{.6R#1bWa'/C5aK'P^Dk6֊[}s9K؄-nܚ-#FTdrպj ?ָ[X`CW{&ܖu9Q8Q6jA0tRv.HxaJX9҅puܫm>c R+CIr;>?%3 i_%CKh*DD8t@`P]Nq u5MM 2 tRxlCH@ŦfzXv)1Bw'g % tW~Χ1B}m& %ZKӕjJEU4W8abvoT,W BC$|QOؑ}('vϜQ 6]ļ5 -b|=.OS억T !$nߌI/^2e&Yb%W͞j^]g܌(#`_,}ڡNRjNRWSRN75r: Xwe6͚75rlB^i#l`:9W"^{?matɍC:K0Kvㄋr|~A'T'DsF]\tK$zk _<(oӁln٭kLjq}~AԔ}tHkR!=#u½pk6{zʸxyyp2\mkkd]њFk7GSFFebT/o6nlF.yǣd1Y+k25H7O$|5'S;I,= |Z[ϲ2م-*1pqO+K09RSn?'<މL @Γh f(Aː;olXL&n!39Qc z:(y%lMލ")k4f݊ k|-W``,()E'}RHPA ,бZpb J{ʘP}ȼ]Uo48zӈ?dgdŐmt;*הyלZ}ds]{{\-osU+{4 w !Pb$+/71!I&?Rn˚dd;ILn/n+ߟiNp}ޒ>ũ7u{imfթjp`s(Շ>=?:,f3mFlvt[F!)D,/clpn1-8oC;Tq׹Ž}גuFny؍|+sUU ˭_݆]BqQbWƹF uxkZ-a; l#ImQ{٪K <;I-Z2&pM|:v P q}ĺl)b䲗{QVpi.X_Rh LJ+MJ{sYNoQ@saй!^͇=gqe/fح^s~'2WhkMuC%3V. bYZaN5x>{[flZOΰϫ'M]+ؓOlx %\ZY蚛9ڐm]hw֕a4Ș.E ނVr>̐}N9 Ф׏2c ]XӜ槭msWkPq]}ޗ8P 6b3Խ;2T#-bITӵsǦFq{+TTk@,oo@̐kWV8<<[c͔^,yi=IБ=5K4y?N߫O:곝}mM3ehRG= ԭƙ=78PmOqZryn|I>r{2X&S7z1#K3n{g=܉)WOH|Ͼ;F dDf^ǃa*2A҉rgaȥZs>|”`JoJi^3BhKc}A?^![T۹$:udݙaARmQS[܈ a퍐LC{+j<ǝ!N4n#,!2O2Jێ]#8qұ&_x?aonZ feՍ+?f:s<ˉmNQc忯Ѝ@k&K'f٩9+9,ap+(,ۙf]zf{et`w9A\`6`\r9ZU OlV }6i3~7'Ł}飻_.]w?X%cn}یh.ßSω pwZ޲qKLpclg o\. }LP, ƬI\Z8ip$G8@0Q5-h4#-qAʻG]{nA)|4c/$`244>ğSczL=e5q[2*Jy!eh%1ĞcU&"KRvԦ2{|#.W  9xvs=>np7[B,y w;3&. cH=~Uv1"4:{e i쯨UQW 8\i]̎EH5&kr"QJbT9iuJ=:ƪ p2F_ִ_U)_Љѩ-WtS[hbKZ,S0ZSE:)$lôA!˒-BeшUGi (fڞ:8IM!D ؆@DVeU+N\ACDHM5bDPF40tbJ !rRj$҂֢)XZ s7'Ǵ ř V|Љxf*g^Nz?34ܳI;w+7XvKϞ82%;:@ y Ͽ ZJ\ .2Ƕċ3.I,g g4{|ڸc! y;TBvZ~K4{1ȑel"`y?_e)e1#^*俦?U{Ҏ(c]TwT[u`NL0R}HZKaBNw(߻h^~narS6L p%0?,dgo-SJLHT7Dǃ8%#O#Q1UKrL$u?#0yZ,k2>ngCn6Cbh;.(=!nGAcdz}Ɯ606,t}ћzD ԥGnYR'*+q*MF:IP4ON19-1 u/!A+Z,q:iG+&87-xA${sWxh_V%0 i N\ 2zm>PUoG~܃?\ IGnֺKN 3 A?mdצg@G1Ql㍖fc;#I[]mF|,l6j@bփn e ?GPvTqjaeSM'P Pm/p O]Q0:4$']`([ױB?m֩9I4p>h>q|O\O0 ZY^0g`͟Qr#BzH6N%Y l 9ꛙЂYN;j;,O< A!Lr ӹq49] Yk9|-^Rb7Q)&xg?XZ"(0xb$:i{ɬAAG{Vh="//%5xJ!7.|M9Rr:TgL.l`NdAL;QKI7̸=Ҡ$]兟G Hr`[YO[]35y݁{ 4U~/gJs%KH Ҳrfe9ۡߥYBK3AMXֱNPa,j6ym} :DfЄrO~Þͥ8 ĝP[ _zzaueH"i/0wDIӼRRS7ɩjgu;l?wUQ9E`_qb{1`$'rxb6 قbb S -L$]3lEVdlY;eOn.Ȳ`5Eò$˪ ?JZ˔%2-I=}V]Z_]y_"3w%V-Ԓw `_y_% L^'CQ9Åcy|tJ{?סG~ j/뿣۞4|4Sמu'$#߂|AEU'6}v2*HV9O%v\_e b?Lޘ7 ~%kZg;$<jok7?x1o[k}ѷ>?f}'VN%H qs?2F ;R͎{;/T_qRh?>Ё$AR-cr8?tKB#;yݷ~Ux賿;د]_oW>߭/o?wN4i_.{/GP@_T6KQ$e[%*M[Z٦!)3HM1LCV,@S C4*-e}'r_i$ʚ)bpkd)q"T{;]"?_6&Ȃ$r/QD{4xdarcs-2.14.5/tests/data/minimal-darcs-2_4.tgz0000755000000000000000000000656307346545000017010 0ustar0000000000000000{.L[yl7 X |$$N8؎f;3 @ӐBUJ" U=BQBpV (m T$ffk֞w~}{Mōs b0$ȿ,ϰ '1"OJLƟw=)=V8F9(iq:I`nv8ͱiN0&I)rIg$䕔HTJ̊4#0I-jAf‭d9y6Z2&Dqz*JT))fS&ʧ| Ũ ֣:㬤 <q<F)r@&US0fRcÑQ_7U?>}?Ex_dۼ;2}ռ ~{k/zȮvU͉Ua.3tZko~ƔקO=| _o~{}sya 8Ss:>J#8#/ ɘOxbQʁQocOɎ'Vx)90:[#J<8a"$|׈cO%EI}\q^dL"7F( =RIG&||p3)헟M4bǽO޽|򎗷_p??Qn{tGXV{~ͼ4.^}{Ų.zk]tvOرE(iQSyUK Ij `r,NI&Iȩ,aVd49^"/?;m=3gf/͝vKnm7^ysK/oi~{=7/?w۞wor7{{3mҽPsłK~+U:qTL$!e^f$'F 2l*`MM1>J&i/&GY0 IRf)MaOcM K7I,E>-!|ZHYBCNN GKIܤ_M:?eb 0!(+&G g9i?I?9nz{T [[, 8J(!{YdHAMyYcǮ7yςF/tHFզ!ȨdӣܺD E)Eպtpk1oAP+8eטf?6$&@&ςVh?ͤҖ DY̢J\mF[j2D5.4Tٰ m Wh TK)4/j HN)YP|'9+]+k> ]Uhi_?)H Q_Yn~n},VYIaCEBAl#~EzH.3Y&(a:Y-ˣVxW,y5Qs;\۱ vwМmU flѽ:N kA75 yz_iu0Ԟݰ|G=1 H_b+ u5ЪawC)$<  RWaPMHF4A Qp?@zPQ&h>xK*Lj:8CXwbϣ]%tEG΃^ÜpC(;G 2O4.mZ@;԰[\PiAy=m mwAH2! x<RvO& .vA 6tNm5D[aJ:y-ujT!+TQy#`@x{X, :!L?8ki# ns[ (XuvzzbvzBa Ď;ibVP4~ 941D T?s@To8e0a̽nCUBSz+!QPqqSXwr[Q^~q\1/)fetTyߴR쳽i%]ca Q\2L\U,2HgWu 2fLUw^V u]( OuCӺd8khεÒ4%{=РoԽ:M``23],6 :J{襱aoh@@q.0* 5^ jZxrピDp:eb0F2 oI6o.̭LEp&dM5r^;U9+|VLvPЙQBsTf UoYlX$0`.[ZVZPAP:jl",a]rüOt]. GUx_U+ȢP?XqDgXV?#N{7d3}?'#1+ ^y#gqSrW3Hܶje;ŧܰkC w=kh'vj֛{_m[o3sk^ }]?޾O?w*>hxn{v'>xߜy&ywXsV=8id7-߲`Mlmvx?qvIx(e8#)$G{߅d# Q̇KU5ځ%^ ir~a(,7B&4z%Ǫޒ> K۱9;W4Ò /tn.fJDKF%2ub*6 q[LECi"de|A1 ȈgY$y_*s )@FQ#لP:(!Z$IRAZ$e y*NP*ӡEh!D$"CH?C)V >(mbEcu#OJ}Hs>Fb?@>kV_S?]id}N_P a[ !&ODU0\*I$rQL 0r #iaN@_LN m8Ga )Ѩ5 Lh0!"'+uv5RB*.!: QW4fj1>^m-^\^8iShDR % ɓf/T꜄9>lt5>fsjjs2c&&N44"[Y:bSlVBZ]$^YSQ<dмmFP L VwpԦ=J0:f;a-L4"=,ҍIp35^ Fzkl(C3*CL±#B؆d>$1K[j0qU+5#̛v! PᰔZ}9{Z BEEg&Vp5QfJHD@A#DXuJx;Aa+FCB@880gtG"Z+J(9ƭEe@JBZ, v --JdEU~qC%Ǜ $mbJعx Ym&Xk$>Gy-6 1i|U(6ӒYK8$EsFXi -!au"R *A:S϶Ah8cFX(x9c8aa5̘amDuPe6IDѤ10cdv|hUKMR/FAC6Đc^5IHב=SPX 2+րSkyB 39T7%\rg3MsPNډYP8$1joĄMѤE.t'Bɪb& 0Y*4JD;(:Nl#Z'Ց:S%0}-?+|Di55  E x9y & m5k S^ݖVڙmVI"qJb6"d%v}bO)BU(0P#!HYt&0{-(.g!+'@Ttd;CydӬƓ0?(:G` )˕G2jbMJRcL>MuI*\©ZPg%bR,9m\1}NLŲm]mD 7E+4ѐ KoṼI 4‚zC Z+H 矕nX~[M8G,3ȟ\Eئϋj]FL{NՔc@*[vs$s!ϴ?+߯pz8􁞞_/,ao`x5D"I'I$E8C9IUgRMI|Y >_(Eُ@@|#EZXYgi? yȄ[/41:Oi>73d8|SѕsN 8adn| 3\V1g[b53F{|1km'җy xZ}ѣo?gNJ^qF/b[>^wBز<=eUw>/_̩cU@9sښcL]}K<͚)ۃ\{/휹xqkW)6tͪ5ߨ^^[tmo_^'\׳=.*_HohW77p4h6IY?2b@XZ?$$/]!l? sm<*}?8/=8 .=fk! e7ʁv{Ӛn>;oW7y_Y+{BɰC7.hy| nj]_=Ĥ;YNN8;sl\yqTr(Y}<%2 Ӕ 38_pC)?ot=Np߼ϼϬf/*b>d[Ck?Yzxy 4Zls37|ޣX/lcMGݓ=//5`^??=g싻)U S.=jx?ISVJtW4 -[q?:/i'WPwktOgSvgl?GWyuot@?ۿh߭oU4p.7}SiI?6B]*yϾeVXxޫ&>۟[<*tן~zpہGX?O=g$Ffow7F9-uk,704{]=~sS;fݴl bEX%c?L<⺗6-7hď2nC19kz. Rڿrg#s4f]Uelx~¨z/jϭ?ytaCo<؇ZP9w%3Ln͊<ōOe;5;ʟ=+n9ۯg~IOUi0Į7o6WyF 6|^{G+?\Ɣc][y~7w;uovtğbߒ{gn޼qtӡ)y]:4zdO4P+2^&_roo?54Rؿ׽))1W༏x[-y'q/9rv kv PYIj@8EE 2mhKa(LnN)Uߐ6-^*"$vEUC eϛZnw:[* ]&V^b$]e fP4Yaz:moWu)&*7eQ15BI9s:@*\YU:_?;qsJ[Lߛnl-Yˎ=cS{t_~g|FyWٟ8{NsSEoy[?]}WmzM=nڝ)uk̞֞߭v)Q;uO&>G?b~z_<% |")2|FDD?Hܷ ?Pi+wܸkU.3}}vfٌϷ>3ki|y^~g>Y"{O>kY~]]W ֔ٻزܿ׷=3'.쒽_|'j>]Ώ?zuÑw[& >g,ʂe>(d,0u2laD)~9'ge7nsOywݿnU߃Oׇ'|gN၍wX"~Mb0wɤl[GX9ov:Gc Y-o͋昶IºwE]wt yEL9!V\t.ЩSg =zSw} ;cW~aξogNwZ7/lov}c14A(fhDcc~W:Vbh.`QɅ5b_0sPf~ld,ryKD0_xD] :sI1Xv!Nd1"$X!&8A&#: ^\:إTE"Q>Ɖ.bD9[zG_Mۥ1?e<2f ~#1?2oe$_?h=nY80J[Iuyqb%P_G󟣏a?*E</Ձ0eL?J@Qǻ_Y0L<󿉍!_7 P\Qgx>|Ç>|x'xdarcs-2.14.5/tests/data/patch-index-v2.tgz0000755000000000000000000001111607346545000016425 0ustar0000000000000000][] |չR#>KU8ByĈhA̜3łUU+?jW[??ED^תF+k;3$G *cg;||gg-@HP@4# ,9gh0' H431p%dUGi$ (Ӎ$fn{ ,ǟv0,'J}ꎃ|T38!E??A l9n`?Q8Z kuN2 >@Nk Dl⿯ F<:z]D'_^`نi<2#"Iʌ(,-jĉHy$"˚$$$1 H(o9YX%Uk.JY(R'bdh8sXfb ȠRUi㈛0αRLeU^u&2V B " -"ӜDYZ (&jXb5]FdteXM8E 3wyBLJ*C kR),YA"2Hr404k/#d]21 bXĴw[<aYUk?\svSGfST%ewI勗xH)т|6l ٧̗'}%~:ו?(?J3m%Zu+=xCcm>W<,Mh؏xǵw-#+7:iȱK߹vˆ#V=c˝_rʙ?Z}~кno;;!J>>rxT;:h/T;ON/ ]vަ G}?aU $luA`uqr^+k1uDZFWiYSuI:u?+ ?h0qaomڹܛoq6nzZ}_e븦i_S`C/W U›~V5䯿(8auXqonUڕԦ⡫˭鼱Ok&kg\;곕/n}뱿Z29yÒ&\S>uz՛~zS{+o;wus/Nk>RUy|ٲ?~u\Y1;9-gܹ9t] VtËܾf4[hwvn{}`FcPѫw z}S[o>9;*A:1>4c7m}5O|G_++"3_#1n~<>Wí%Zꞏ>9}JyYń.}RUy5ƭex ~=,mtZ{Zpлɋ_[vqe'uѿe`; žpZ3~=CҐC?1(y F+uO_^F7{O ??d<`Zs YTGC#{:h?Qo]qׯ+iUrkV짖vߥW3hs[/9ȑf5? >o# .|#'7;ߛwZ(|?'lO>q޸Gvbe61ow3 ӓ<^ rDQB#Ѽ1hEh1%ӑ c9tZ؀"78%@|b.c:ķG7X?0o˄iD:z`K\x?/M% {o iBTp\)b4L: 8aRLcvhHQDJH) E )9N&Ż&Oy:AiETqt)(? ٩jjLtj9ե J3\ PNƲ8yA nQH (ҚH)8nӤm4 )SuM(Ŷ0U7wVwZ i%n55 Ni5=[3%ׂjr%Xj@V"'p0[Qrg몦M+:ALaegWh}7}WK?φ~}3mF2 q1O(̸!H]i%4m TdSm L6.DXg 'QL&&^1ޖ@mc<~U>x,NO$G5ed'n?@7؁*i0&Z'ё QфQ(C381Sb /14k&ĐfCg5Eݪq@Vl8icE`uFIv׆LZ&wEbfکl1%' dJԔ zW\Ay, $Rb(`eUMRFPt)SH ZzjA5H `'jk$@N<4DmqQŐ-q 9 phT A7kȮ>lSI 3sjkL VxDsH:r:M϶D4VIKn!Io;STnK$Z_Tvr)HvkA!~EaFG-a":}PLre^ 0:񕇜xP 5}bʡI3%3׷)CM] +x[JNs܌fT sANZVhVӠ1N^5)_ƨ[5lEl4:OraL!؎J σ1h6Jo \qALhs㛭"?AvjWhg<"XJ;%-C5_ *L(KsQqa.TA ꬭU:=F ~ $ͷ")d$ #~ڙk0i7 LM7˖e:4zuڬTu`>ݸ[PD mQR c2z ww-O8Ax2,x9f ߀ L j!'MaQ7*6 1^)\xBp"霑"*lWȤV!y[Ƹ( M19Ae-K08 sʚ<VLˤ,?m1Z5mf*^52YX7`[djCZʈM3:X2 ҕ#]cm A͟=#2s6׺A#pP+J0xFǒL^BB]/دoˡt}ޟy7+}Èy_RU$q+@-:cx<+1NV0#s2y]ut9MUgs㪞W퐂qw⻎}nUGogitksz衛_?_^W_5Ӷ|bǼygz{f Date: Wed Oct 20 07:12:31 BST 2010 * wibble New patches: [wibble Ganesh Sittampalam **20101020061231 Ignore-this: f4ff110805aca7a2d8805acf18605523 ] { addfile ./wibble hunk ./wibble 1 +wibble } Context: Patch bundle hash: 3c6e5041f7e4b286c8884247a155a5d80d0dd77b darcs-2.14.5/tests/data/simple-v1.tgz0000755000000000000000000000606607346545000015521 0ustar0000000000000000[L[yl%Q%ڨO[Ļ޹vvB 8erқ7f@=Fn PE$V@[DAZ@!HC$m73kokѼ_w{ޛYNG" %~sD Dg|E(j*`ŏn7W=_05yK? vB]&Aŏ??'f&#(Uk"HFU^҉jEI0dbUnXWU I06bτ] CpU3B=i$ˊ7ͨ+72A)I_J577#ͱ\(ud@C3N[D7q@~?AJ%Z(jmqkP5)-gZu&$ՌuтdjG2Zsx<;Ԑ[tx@⻙Lp[`NFv7/,G/ б<&gJzY-ֱ Fq뛎@t^}FbB؉%(!.E2,P Jf#e/ EV4khŦc#baoGp={jXsF HI_Z $H%SgLTrL'A+)0P-!$%mtDwt4!cfEYmXnGN9pˉ6PѠ2w^J~K2|ƪeG]M]mEH*. PVD! > n5ی ^RO K fU”u0:aPC֊$֞&&S.9~yNT N5UL AY7d8OCfIb6bF2M{$ifU,+B ubktLOdzԬ%rWiœ+YA[iP)8Нtl~YMUЯU󳈧=uB`BHVKihhJsJEq2.cf`h qXRi T:.QA;֌D`ȴb<^=0Q٬Mp'Ims&HPs;̧zKN۱lIT wMGuJ$vU=tzVZM8@g9)r5`~^ a 1)ǘc|OlhFCEӏwccC\%XhQWmHx "* =E ltj# {2b;mFQGhᇊ0DNҎΨ,j5 4  BnX ;@ g-u[fSw?h˦nt`@ Q)-02:a"Va z7n\LIʹYlPo9^_sz#JbFSM8?9vN}$E^"<"eQW.o9yȪ$uk$/e9M^5.јy^u'{]7_՞WOXW\f/o;'sYv}.Q?̩#AIpd\mb33|BY󿆀э@"D9p?)'?#?o5Ec@* CBFyX󆢊ĐU%5 JcN/d^``-}_\#?Ԭ&74ND!jyE‹1'*"IQ8UKf_{C/ 0, d*\Y?Υ%=pOW N{k7>1{6;{_9cizUm߷yŝ |QkqӮYGz, AcO MՋ\9e_cP o7UDR=BA3xB3%U,xP \ F/RYk!eY kXƼe%R(Eu @Yw@>(W Ky#r^\NEu8!'0+ 㵬A42tk,fRt~tc47蛕{w{ڋ|}ߞe;߸3UVW^{Ż_}k~O?3Sӏٷi|ه/<WnI<鍝{|mum5zlܻ¶[՟&]{te7<Ң?,.-jp< 19'0o=ѹa8hircs{gi&IwyZgwwt_͖[w^Ɂ], Ed}h# 9Zpd$6LiGxdarcs-2.14.5/tests/data/simple-v2.dpatch0000755000000000000000000000066507346545000016160 0ustar00000000000000001 patch for repository /home/ganesh/darcs-comp/temp/empty: patch 060052b3182f512c548d15dc6789228178cd9a4e Author: Ganesh Sittampalam Date: Wed Oct 20 07:12:31 BST 2010 * wibble New patches: [wibble Ganesh Sittampalam **20101020061231 Ignore-this: f4ff110805aca7a2d8805acf18605523 ] addfile ./wibble hunk ./wibble 1 +wibble Context: Patch bundle hash: 497c8eb610ad9a25b30ceafd3b4f5c1ff744d21d darcs-2.14.5/tests/data/simple-v2.tgz0000755000000000000000000000546607346545000015525 0ustar0000000000000000{L\]lG(hSE*B( _wn!n:[Shk;9nCUB@*@BPԇHUH}hBJ| Kٍ/NYUnv(tMcߒ $z5d'I |!2󕡓P#IooP1c3ljsZ.? ˟bvZ u2L U}[KM URp_W IO)UubVՒ5(-hJ)N lXZSl[aCpƶ xW(&;"+ !(pYM2TM6j'5Z3#~it.L[nBBONlaz/+?MKG&w`&אָp'\hF3L_ѥvgGBa#l#(&9%Sbv 1܀4>y')&1:+FRV  Ĥ$АTMbQB c/Z5>]N}`Kb찵$Qo7CFShg01Z.Y+ B$#^pux|"M~t7 8TПOpLPM =gg񠆘Dۤ|iSht, pXK:60Ѡ103ř㌠~4kf׳6ױv;%ypZ֝ gB;Qq9O^',7RCAȄYHN@zFh` Mh3MLK_D6ړpd/tR`vlo}׌$) Ug7nڱb SцL.unf )[ƤklXB ,l+U~ 7&t7_̗2auq!\P;s={ !8w'1rj&ݠ0?f'vWqiQ Ţ،!̦6 31I^cf`X D^SaQǮ7^-/OY.00z A#3|ʁt2$PXlg~{Z眒uyKe}cf8d w,DiƓcl#80Aq0㙒dB a}PS%vs\9X_Z-;ll-4b'MӥC\r,f~ #7]N;.8\'Bcswˆp0e٠ l󞓰ڔFSsU' T֢zʖ쫫*pJ13l$fF9X) 5`~qŵE-b"Hy?Iʞc -ɎgccCO( m.yzfNǃڊ6a@s%YDAU` Ht# Gb163(@ȑX*J ~ @T0N׸=iP  H& BDG|Ch*ipk `I<"Ds][ ˁ+ A屉,b3-<.YqpepfVYjC/ ?JM9GVh1/ K/. ;|a~v:;w$LgE;IGݙ_D䠓]8|pW^\d[r`8Ѫ.,>=:W[vpkN7.ܝ \LΙR+um`4wA^-n3Ƕg} ~4a C1_]~!)?W6.?pi Q5M? \6NZs.+AWm_KGSZp #lТK)#a7~n~1A1$YJh.K+,7BjےTo5lbV3+RQ4Y)S)T!zE!J bIZK6TP$I]ӛ0U+!аh-jZCұڼ2y\??Dh 'ׅ>y>ޯ?z?ڽ5_Q^??,|k7>g^ہ''_{U?3Oy/,Im?'>}'?~u^mW7?r~?q/o~>7ݭ"q1gs#C2 YʏCwi MHp)72pkAiÁP E.nMe֍VNkb-KS-4Eٖ鲢 ? l^:~s`Rƅ.W¥(FTUմMɔ [5V6Z*똨Qjh)ՖjIds_ޖ7lUˈR?? d.[C{AW3?#no?6isRfo|Vz;K?z薳g޺ӿ}wW#SpmaF] ?!?|$t4+FK?yl4?n&w4ȓfC@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`?\xdarcs-2.14.5/tests/data/split--darcs-1.dpatch0000755000000000000000000000062507346545000016776 0ustar00000000000000001 patch for repository /home/ganesh/temp/empty-old: Tue Nov 16 07:15:41 GMT 2010 Ganesh Sittampalam * add files New patches: [add files Ganesh Sittampalam **20101116071541 Ignore-this: 2a86fa7deae02f1c98d578077ee5f8a9 ] { addfile ./file1 ( addfile ./file2 addfile ./file3 ) addfile ./file4 } Context: Patch bundle hash: 947100f54fce0fb3cb5debeca8702b119ee17d8a darcs-2.14.5/tests/data/split--darcs-2.tgz0000755000000000000000000000552707346545000016346 0ustar00000000000000001L\klGwUB%b];Hc1nƪMvٻۖgBU@ BP@"BJ Gg񣎯N.kBķg; * fTkuSuQפ@]j%ymF  G΅jBmM({.koFvvKqQom_JYQ/;˟aFWR҈Q\ ^/IVu. /|GmĘH RmYǖ4ITU42eXZJuejZ]n`C/DV}_ػW"M! 4z6/iJC:Kj AmFAˊ?I.de.p? ^UϊGV˸~Ha ]Ҷۿ`%RF I Ripp@mg!1^%Ō$ h8*;p>J J~V gϞo&&&ujo BZ8{,K&еb^!!nDAu Գ}d4{CE g2 =I/%yT>׆aV7X<U0O'D8$M 5dw!&FYC.mw 4:Ef|ZbBWhHYʸϙKvlu|o:W01EM8&0Ea;qHIt3rE0 Ua1G~?F+$%dp$|.\œuf>eшk e>(U^tF@T{8,10Q.5C?mV`Aչ捠uu-#0la9 Z JbmS(el$+H{e1)"'RHҦf8o;|GVȡv|ġɴy!ih =,c3Ye3fta&!X3㙻2^ >p XyeԶsSGJ+e)=m>Wdl[lKfiz넨vJusfBTY!0h֛Mef&0,uզ&S 1[6|\Hn]M AVrǨ|h2'[ޢ T1]&~ l~گPn}PQ{?@Yץ.;[qO1qkn1L_#}>t_}{9FN^*zcgǭ WVE!Wn/wW,;CTE4җm;W4zNUO!A~Ӹ({;:Yxdarcs-2.14.5/tests/data/split--hashed.tgz0000755000000000000000000000611607346545000016342 0ustar00000000000000001L\ U*Jb ;3=}̬HH6]fw~=IviRpUJB !T\-5XHQJJLf~{|lt %gpE'Hpbyeç0IɨW6KW  LĆӠEq6Wy4`"4K9&f`ti~(!3Ѩg<I875wb.1s*W A$d^%ɲk*k0K<'4YVeW°?] RNofG\o_N"Y*lɱH6^}u`v4N/)E=#liimmEcP!lȴb" [Z0)QX.֠i S2ۢiqz$WQ-H&u Y:mu=Z({ӹCNеa Z|73a6POxFWdP0 &p\ֆvro:j*<"WPC4\ JdYf@G+ʚ_L< < 1K t)sю%@š߁*z & ]H F?2qI˦a$Pىk0]m LBF`XCn%Q0/ZȞ=]ў]eAe=ȩn%*USV~k%h`?wYᆼlHcՊY֣.ֆq?C\{a')/eôմ;\LǬBO[+"csԓIbBuRCCY0e>>pJe68tXyhZaeAŏ25#@뉊`AթuW;?覃,` u@[9٠[ g~A1cTu=43?L:5:ځL\NdzLjս2aU,ڠmqDsAhV+QP١_kgOx&.JZS jpYUG=`FSk5]5( qu*'H Ь9]ԤiZYnkI5*hgM`spHvL+ ; iet2&m{j`yT0 Ldc"ZT($ah @+!80A\G"C<ԷEJvăAM&(E:gZԕ[-1{}*[5kb" vRsIӿ6;%bzr@]KI`Ra)Zl rG؁Toig:h=6JAvffS, x¬~ٚuz\5aJQ3H5t#rRk4ZŽCA?ucxAQ %&L?81 S-VʰQ4ޱ $JHD`%PUp4b{N $:# Gb16#(R<ȑhJ0}_ &J amviPXuĂA@0,-8}"pk `IqwtMX$]Ps JGPt:S/I%wIl4 MmpŔjᢕ=IaThU]qRpɊZR%, E-M a҄$mY視{ /J .YP Y;bZ!j]9jž u Lu#Yua |11:a"Vja,-]  Q ,3 ?9Єh"6f И rOS7Ұo?Ya53ʟiW/$fe-8#d]=|h|>>b8IIٿ8L@1'/qp% \NtSr ȲjX/pH<'26 H^u2Lfȿ^rS?A9uG O;qKooO1Ksݰ%#~7_2ձkv-}Y涗;3ozOoM=|ڒś=v|W<ֽ7ʷ?z\o_{z哻voXM_rs|䅯_?kץRx/fGc 93Cikr}q2;5IN4Q yC5^,`C5D-_(ȆZDAD(5,BW$y)v̰_hOv)?10 Xg?wz DS_'^e=WrЏ4Ǜ#?mH,E;'~v[uaw=77C_>SDžWm9߸o?ـ^mkn*6kci?. v z/"G?䅠hPrq[x% JyW^x9D-O;` 9E!D22ZvZiԇiffc_Yf/ndTD0IBK">T-W lXV9B 9σSx%'Y% ͐O?Ab?~;騱^:y/oVuz * wibble Tue Nov 16 18:32:38 GMT 2010 Ganesh Sittampalam * 'nums' New patches: [wibble Ganesh Sittampalam **20101116183225 Ignore-this: 5e5df9907f191511650c2ed66754d17 ] { addfile ./wibble hunk ./wibble 1 +A +B +C +D } ['nums' Ganesh Sittampalam **20101116183238 Ignore-this: e865de7aa7e896c759dabccf510c59bf ] { hunk ./wibble 1 +1 A B C ( hunk ./wibble 3 +2 hunk ./wibble 5 +3 ) hunk ./wibble 7 B 3 C +4 D hunk ./wibble 9 +5 } Context: Patch bundle hash: cdfc4f7087525b0298d4f08e6e497f925f85e406 darcs-2.14.5/tests/devnull.sh0000755000000000000000000000255107346545000014245 0ustar0000000000000000#!/usr/bin/env bash ## Test that non-interactive darcs commands work when stdin is /dev/null ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repo. cd R touch wibble darcs rec -lam"wibble" < /dev/null darcs-2.14.5/tests/diff.sh0000755000000000000000000000560207346545000013504 0ustar0000000000000000#!/usr/bin/env bash . ./lib export DARCS_TMPDIR=`pwd`/tmp mkdir tmp rm -rf temp1 darcs init temp1 cd temp1 echo text > afile.txt darcs record -lam init darcs diff darcs diff --no-unified -p . --store-in-mem > diffinmem darcs diff --no-unified -p . --no-store-in-mem > diffondisk diff diffinmem diffondisk echo text >> afile.txt darcs diff | sed 's/afile\.txt.*//'> diffnoarg darcs diff . | sed 's/afile\.txt.*//' > diffdot diff diffnoarg diffdot cd .. rm -rf temp1 # issue966 darcs init temp1 cd temp1 echo "aaa diff" > file darcs record -lam "aaa" echo "bbb diff" >> file darcs record -a -m "bbb" darcs diff --patch "aaa" | grep "aaa diff" darcs diff --patch "bbb" | grep "bbb diff" darcs tag release-1 darcs optimize clean echo "ccc diff" >> file darcs record -a -m "ccc" darcs diff --patch "ccc" | grep "ccc diff" # here is where we have a problem darcs diff --patch "aaa" | grep "aaa diff" darcs diff --patch "bbb" | grep "bbb diff" cd .. rm -rf temp1 # issue1139 diff last darcs init temp1 cd temp1 echo text > foo darcs rec -lam 'add foo' echo newtext > foo darcs record -am 'modify foo' darcs diff --no-unified --store-in-mem --last=1 > out1 grep text out1 grep foo out1 darcs diff --no-unified --last=1 > out grep text out grep foo out diff -u out1 out cd .. rm -rf temp1 # issue 1139 diff with no args darcs init temp1 cd temp1 echo text > foo darcs record -lam 'add foo' echo newtext > foo darcs diff --no-unified --store > out1 grep text out1 grep foo out1 darcs diff --no-unified > out grep text out grep foo out diff out out1 cd .. rm -rf temp1 # issue1290 - darcs diff --index darcs init temp1 cd temp1 echo '1' > f darcs record -lam 'one' echo '2' > f darcs record -lam 'two' echo '3' > f darcs record -lam 'three' echo '4' > f darcs record -lam 'four' # in the following outputs of `darcs diff`, we delete the # lines "diff -rN old-... new-..." since they can be different # if tests are run in parallel darcs diff --no-unified --from-patch one --to-patch two | sed /^diff/d > d1 darcs diff --no-unified --index=3-4 |sed /^diff/d > d2 # the numbers go backwards diff -q d1 d2 cd .. rm -rf temp1 # issue2052 - Ensure we use unified Diff by default. darcs init temp1 cd temp1 touch a darcs record -lam 'Add a' echo testing > a test `darcs diff | grep -c "diff -rN -u"` -eq 1 test `darcs diff --no-unified | grep -c "diff -rN -u"` -eq 0 test `darcs diff --no-unified | grep -c "diff -rN"` -eq 1 cd .. rm -rf temp1 # issue2067: inexistant files result in empty lines in darcs darcs init temp1 cd temp1 darcs diff a b c d 2> /dev/null | wc -l | grep "^ *0$" cd .. rm -rf temp1 # issue2179 - darcs diff on a dir should diff everything in and below # that directory darcs init temp1 cd temp1 mkdir dir touch dir/file darcs rec -alm 'Add dir/file' echo testing > dir/file darcs wh | grep testing darcs diff | grep testing darcs diff dir/file | grep testing darcs diff dir | grep testing cd .. rm -rf temp1 darcs-2.14.5/tests/disable.sh0000755000000000000000000000165007346545000014176 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 mkdir temp1 cd temp1 darcs init all_commands=$(darcs --commands | grep -v -- --) for cmd in $all_commands; do # --disable works on command line not darcs $cmd --disable 2> log grep disable log rm log # --disable works from defaults sub_commands="$(darcs $cmd --list-options | grep -v -- -- | cut -f ';' -f 1 || true)" # disabling super commands in the defaults file is broken if test -z "$sub_commands"; then echo "$cmd --disable" > _darcs/prefs/defaults not darcs $cmd 2> log rm _darcs/prefs/defaults grep disable log rm log elif test $cmd != "setpref" -a $cmd != "help"; then # setpref and help are not proper super commands for scmd in $sub_commands; do echo "$cmd $scmd --disable" > _darcs/prefs/defaults not darcs $cmd 2> log rm _darcs/prefs/defaults grep disable log rm log done fi done cd .. rm -rf temp1 darcs-2.14.5/tests/dist.sh0000755000000000000000000000130007346545000013526 0ustar0000000000000000#!/usr/bin/env bash # run darcs dist, then extract the resulting archive # and compare it to the original repository content . lib rm -rf temp1 mkdir temp1 cd temp1 darcs init for (( i=0 ; i < 5; i=i+1 )); do echo $i >> file-$i; mkdir dir-$i; echo $i >> dir-$i/file-$i; darcs add file-$i; darcs add dir-$i/file-$i done darcs record -a -m add_foo | grep -i "finished recording" darcs dist darcs dist --zip mv temp1.tar.gz .. mv temp1.zip .. cd .. rm -rf temp1/_darcs mv temp1 temp_orig tar xzf temp1.tar.gz diff -r temp_orig temp1 rm -rf temp1 # Only do following if unzip is present unzip >& /dev/null && ( unzip temp1.zip diff -r temp_orig temp1 rm -rf temp1 ) rm -rf temp_orig darcs-2.14.5/tests/emailformat.sh0000755000000000000000000000226307346545000015074 0ustar0000000000000000#!/usr/bin/env bash . ./lib switch_to_latin9_locale rm -rf temp1 rm -rf temp2 rm -rf temp3 mkdir temp1 mkdir temp2 mkdir temp3 cd temp1 seventysevenaddy="" darcs init echo "Have you seen the smrrebrd of Ren avsant?" > non_ascii_file darcs add non_ascii_file darcs record -am "non-ascii file add" -A test cd ../temp2 darcs init cd ../temp1 # long email adress: check that email adresses of <= 77 chars don't get split up darcs send --mail\ --from="Kjlt berstrm $seventysevenaddy" \ --subject "Un patch pour le rpositoire" \ --to="Un garon franais " \ --sendmail-command='tee mail_as_file %<' \ -a ../temp2 cat mail_as_file # The long mail address should be in there as a whole grep $seventysevenaddy mail_as_file # Check that there are no non-ASCII characters in the mail cd ../temp3 cat > is_ascii.hs <>= print . not . any (> Data.Char.chr 127) EOF ghc --make is_ascii.hs -o is_ascii ./is_ascii < ../temp1/mail_as_file | grep '^True$' cd .. rm -rf temp1 rm -rf temp2 rm -rf temp3 darcs-2.14.5/tests/external-resolution.sh0000755000000000000000000000153007346545000016613 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init echo "Conflict, Base ." > child_of_conflict darcs add child_of_conflict darcs record -am 'Conflict Base' cd .. darcs get temp1 temp2 # Add and record differing lines to both repos cd temp1 echo "Conflict, Part 1." > child_of_conflict darcs record -A author -am 'Conflict Part 1' cd .. cd temp2 echo "Conflict, Part 2." > child_of_conflict darcs record -A author -am 'Conflict Part 2' cd .. cd temp1 echo | darcs pull -a ../temp2 --external-merge 'cp %2 %o' cd .. grep "Part 2" temp1/child_of_conflict diff -u temp1/child_of_conflict temp2/child_of_conflict cd temp1 darcs wh darcs rev -a echo y | darcs unpull --last 1 -a echo | darcs pull -a ../temp2 --external-merge 'cp %1 %o' cd .. cat temp1/child_of_conflict grep "Part 1" temp1/child_of_conflict rm -rf temp1 temp2 darcs-2.14.5/tests/failed-amend-should-not-break-repo.sh0000755000000000000000000000411407346545000021216 0ustar0000000000000000#!/usr/bin/env bash ## Test for keeping the repository in consitent state in case ## of a test failure on amend-record. The bug was almost introduced ## when trying to fix issue 1406. ## ## Copyright (C) 2009 Kamil Dworakowski ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib rm -rf R mkdir R cd R darcs init # first patch: new file A touch A darcs add A darcs record -a -m 'A' # second patch: mv A to B darcs mv A B darcs record -a -m 'move' # third patch: modify B echo "content" > B darcs record -a -m 'add content' # amending 'move' results in commuting 'move' patch # to the end for removal. The commute changes the "add content" # patch to modify A instead of B. But the amend is interrupted # because of test failure. Check the consitency after the operation. darcs setpref test false echo yy | not darcs amend -p move --test darcs check # Note: Amend-record in case of test failure is broken as described in issue1406, # though when trying to fix it I almost managed to break darcs even more. # This test is to guard against such regressions in the future. cd .. rm -rf R darcs-2.14.5/tests/failing-index-argument.sh0000755000000000000000000000321507346545000017130 0ustar0000000000000000#!/usr/bin/env bash ## Currently tests if --index works on every command that is supposed to ## support it. The information about what command should support --index is ## taken from http://darcs.net/manual/Darcs_commands.html ## ## Copyright (C) 2011 Andreas Brandt ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf temp mkdir -p temp cd temp darcs init touch a darcs add a echo "test" >> a darcs record -a -m "record a" a darcs changes --index 1 darcs diff --index 1 darcs dist --index 1 darcs show contents --index 1 a #### failing tests darcs show files --index 1 a darcs-2.14.5/tests/failing-issue1014_identical_patches.sh0000755000000000000000000000214107346545000021357 0ustar0000000000000000#!/usr/bin/env bash . ./lib # Set up a base repo. Our experiment will start from this point mkdir base cd base darcs init printf "Line1\nLine2\nLine3\n" > foo darcs rec -alm Base cd .. # Now we want to record patch A, which will turn "Line2" into "Hello" darcs get base a cd a printf "Line1\nHello\nLine3\n" > foo darcs rec --ignore-times -am A cd .. # Make B the same as A darcs get base b cd b printf "Line1\nHello\nLine3\n" > foo darcs rec --ignore-times -am B cd .. # Now we make a patch C that depends on A darcs get a ac cd ac printf "Line1\nWorld\nLine3\n" > foo darcs rec --ignore-times -am C cd .. # Merge A and B darcs get a ab cd ab darcs pull -a ../b darcs revert -a cd .. # And merge in C too darcs get ab abc cd abc darcs pull -a ../ac darcs revert -a cd .. # Now we can pull just B and C into base darcs get base bc cd bc darcs pull ../abc -ap 'B|C' cd .. # Now we have base, B and C in a repository. At this point we're correct. # Let's try merging AC with BC now, here we discover a bug. darcs get ac abc2 cd abc2 darcs pull -a ../bc darcs changes test `darcs changes | fgrep -c '* C'` -eq 1 darcs-2.14.5/tests/failing-issue1190_unmarked_hunk_replace_conflict.sh0000755000000000000000000000343507346545000024137 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1190 - conflicts between HUNK and REPLACE are not ## marked by --mark-conflicts. ## ## Copyright (C) 2009 Trent W. Buck ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf d e # Another script may have left a mess. darcs init --repo d/ printf %s\\n foo bar baz >d/f darcs record --repo d/ -lam f1 darcs get d/ e/ darcs replace --repo e/ --force bar baz f darcs record --repo e/ -lam replacement printf %s\\n foo bar quux >d/f # replace baz with quux darcs record --repo d/ -am f2 ## There ought to be a conflict here, and there is. darcs pull --repo e/ d/ -a --mark-conflicts ## The file ought to now have conflict markers in it. grep 'v v v' e/f rm -rf d/ e/ # Clean up after ourselves. darcs-2.14.5/tests/failing-issue1316-2.sh0000755000000000000000000000334107346545000016003 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1316 - junk left in pending ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. # this test is a slightly more complicated variant on failing-issue1316 # it also uses darcs commands to test rather than grepping pending. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R touch X darcs rec -lam 'X' darcs mv X Y darcs rec -am 'Y' rm Y echo 'y' | darcs amend -a # the bug is that addfile Y shows up in pending # if pending is empty as it should be, then since # whatsnew doesn't have -l, it shouldn't report anything # even after we touch Y. touch Y not darcs whatsnew darcs-2.14.5/tests/failing-issue1316.sh0000755000000000000000000000276107346545000015651 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1316 - Removing a directory ## ## Copyright (C) 2009 Nathan Gray, Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. mkdir R darcs init --repo R # Create our test repos. cd R mkdir d # Change the working tree. darcs record -lam 'Add a directory' rm -rf d echo y | darcs amend-record -m 'initial' --all not grep adddir _darcs/patches/pending darcs-2.14.5/tests/failing-issue1317_list-options_subdir.sh0000755000000000000000000000257307346545000021747 0ustar0000000000000000#!/bin/sh # Test for issue1317 - darcs mv --list-options returns results from root, and # not from the current directory # Copyright 2009 Marco Túlio Gontijo e Silva # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. . lib rm -rf R mkdir R cd R darcs init touch abcd mkdir foo darcs add foo cd foo touch abcc mkdir bar darcs mv --list-options | grep -x abcc cd ../.. rm -rf R darcs-2.14.5/tests/failing-issue1325_pending_minimisation.sh0000755000000000000000000000354507346545000022136 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1325 - hunk patches interfere with pending patch ## minimisation ## ## Copyright (C) 2009 Marco Túlio Gontijo e Silva, Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo=R darcs init --repo=S # this is expected to pass regardless of issue1325 # and is here to provide contrast cd R touch file darcs add file darcs record -am ' file' mkdir b darcs add b darcs mv file b rm -r b darcs whatsnew | not grep adddir cd .. # this is/was the failing part of issue1325 cd S echo file > file # we need a hunk to make this interesting darcs add file darcs record -am ' file' mkdir b darcs add b darcs mv file b rm -r b darcs whatsnew | not grep adddir cd .. darcs-2.14.5/tests/failing-issue1327.sh0000755000000000000000000000141707346545000015650 0ustar0000000000000000#!/usr/bin/env bash . ./lib # See issue1327. # results in the error: # patches to commute_to_end does not commutex (1) at src/Darcs/Patch/Depends.hs:452 rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init echo fileA version 1 > fileA echo fileB version 1 > fileB darcs add fileA fileB darcs record --author foo@bar --ignore-times --all -m "Add fileA and fileB" echo fileA version 2 > fileA darcs record --author foo@bar --ignore-times --all -m "Modify fileA" cd .. darcs get temp1 temp2 cd temp2 darcs obliterate -p "Modify fileA" --all darcs unrecord -p "Add fileA and fileB" --all darcs record --author foo@bar --ignore-times --all fileA -m "Add just fileA" cd ../temp1 darcs pull --all ../temp2 echo yy | darcs obliterate --dont-prompt-for-dependencies -p "Add fileA and fileB" darcs-2.14.5/tests/failing-issue1396_changepref-conflict.sh0000755000000000000000000000075007346545000021636 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp1a temp1b mkdir temp1 cd temp1 darcs init darcs setpref test 'echo nothing' darcs record -am 'null pref' cd .. darcs get temp1 temp1a cd temp1a darcs setpref test 'echo a' darcs record -am 'pref a' cd .. darcs get temp1 temp1b cd temp1b darcs setpref test 'echo b' darcs record -am 'pref b' cd .. cd temp1 darcs pull -a ../temp1a --dont-allow-conflicts not darcs pull -a ../temp1b --dont-allow-conflicts cd .. rm -rf temp1 temp1a temp1b darcs-2.14.5/tests/failing-issue1401_bug_in_get_extra.sh0000755000000000000000000000331207346545000021222 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1401 - when two repos share a HUNK patch, but that ## patch's ADDFILE dependency is met by different patches in each ## repo, it becomes impossible to pull between the two repos. ## ## Copyright (C) 2009 Trent W. Buck ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib darcs initialize --repodir d/ darcs initialize --repodir e/ touch d/f d/g e/f darcs record --repodir d/ -lam 'Add f and g' darcs record --repodir e/ -lam 'Add f' echo >d/f darcs record --repodir d/ -am 'Change f' darcs pull --repodir e/ -a d/ --allow-conflicts #no conflict mark-up echo y | darcs obliterate --repodir e/ -ap 'Add f and g' darcs pull --repodir e/ -a d/ darcs-2.14.5/tests/failing-issue1406.sh0000755000000000000000000000436207346545000015650 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1406 - failed test on amend unrecords the ## original patch ## ## Copyright (C) 2009 Adam Vogt, Kamil Dworakowski ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. darcs init --repo S mkdir R/d/ R/e/ # Change the working tree. echo 'Example content.' >R/d/f darcs record --repo R -lam 'Add d/f and e.' darcs mv --repo R d/f e/ darcs record --repo R -am 'Move d/f to e/f.' darcs push --repo R S -a # Try to push patches between repos. darcs push --repo S R rm -rf R/ S/ # Clean up after ourselves. #!/bin/sh . ./lib rm -rf temp1 darcs init --repodir temp1 cd temp1 echo "test exit 1" > _darcs/prefs/prefs echo "a" > a darcs record --look-for-adds --no-test --all --name=p1 echo "b" >> a echo "y" | not darcs amend-record --all --patch=p1 # There should be one patch in the repo test 1 -eq `darcs changes -a --count` || exit 1 # Another check: there should be nothing new after a is restored echo "a" > a not darcs whatsnew -l cd .. rm -rf test1 darcs-2.14.5/tests/failing-issue1442_encoding_round-trip.sh0000755000000000000000000000416007346545000021675 0ustar0000000000000000#!/usr/bin/env bash ## -*- coding: utf-8 -*- ## Test for issue1442 - if we disable Darcs escaping and don't change ## our encoding, the bytes in a filename should be the same bytes that ## "darcs changes -v" prints to the right of "addfile" and "hunk". ## ## Copyright (C) 2009 Trent W. Buck ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R # Another script may have left a mess. ## Use the first UTF-8 locale we can find. export LC_ALL=$(locale -a | egrep --text 'utf8|UTF-8' | head -1) export DARCS_DONT_ESCAPE_ANYTHING=True ## If LC_ALL is the empty string, this system doesn't support UTF-8. if test -z "$LC_ALL" then exit 1 fi darcs init --repo R echo '首頁 = א₀' >R/'首頁 = א₀' darcs record --repo R -lam '首頁 = א₀' '首頁 = א₀' darcs changes --repo R -v '首頁 = א₀' >R/log #cat R/log # Show the humans what the output was. grep -c '首頁 = א₀' R/log >R/count echo 5 >R/expected-count cmp R/count R/expected-count # Both count files should contain "5\n". rm -rf R # Clean up after ourselves. darcs-2.14.5/tests/failing-issue1461_case_folding.sh0000755000000000000000000000401607346545000020342 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1461 - patches to files whose names only differ by ## case can be wrongly applied to the same file in the working directory. ## ## Copyright (C) 2009 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. touch casetest test -e CASETEST || exit 200 rm -rf lower upper joint # Another script may have left a mess. mkdir lower upper cd lower darcs init cat > a << EOF 1 2 3 EOF darcs add a darcs record -am 'lower init a' cd .. cd upper darcs init cat > A << EOF 1 2 3 EOF darcs add A darcs record -am 'upper init A' cd .. darcs get lower joint cd joint darcs pull -a ../upper cd .. cd lower cat > a << EOF one lower 2 3 EOF darcs record -am 'lower modify' cd .. cd upper cat > A << EOF 1 2 three upper EOF darcs record -am 'upper modify' cd .. cd joint darcs pull ../lower -a darcs pull ../upper -a grep one a && not grep three a grep three A && not grep one A cd .. # clean up after ourselves rm -rf lower upper joint darcs-2.14.5/tests/failing-issue1522_trailing_slash_borkage.sh0000755000000000000000000000241207346545000022416 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1522 - Trailing slash borkage ## ## Copyright (C) 2012 Andreas Brandt ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init --repo R touch R/d darcs record --repo R -lam Yow! d/ cd .. darcs-2.14.5/tests/failing-issue1577-revert-deletes-new-files.sh0000755000000000000000000000256407346545000022502 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1577 - revert deletes unadded files. ## ## Copyright (C) 2013 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R darcs init --repo R # Create our test repos. cd R echo 'Example content.' > f darcs add f darcs rev -a [[ -e f ]] darcs-2.14.5/tests/failing-issue1579_diff_opts.sh0000755000000000000000000000351707346545000017721 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1579 - the diff-opts parameter with multiple parameters ## separated by space are passed like an one parameter to diff. ## ## Copyright (C) 2013 dixiecko ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. abort_windows # No diff command available darcs init --repo R # Create our test repos. cd R echo 'Example content line 1.' > f darcs record -lam 'Add f.' echo 'Example content line 2.' >> f # Darcs passes the parameters to diff like [ "-wpurNd -U 999" ] # instead of [ "-wpurNd","-U","999" ] darcs diff --diff-opts '-wpurNd -U 999' > result # Darcs doesn't indicate the error in return error code, # when diff command didn't work the result is empty. if [ -z "$(cat result)" ]; then exit 2 fi darcs-2.14.5/tests/failing-issue1610_get_extra.sh0000755000000000000000000000400507346545000017701 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1610 - another bug in get_extra problem ## This is an offshoot of the issue1609 test ## ## Copyright (C) 2009 Eric Kow ## Copyright (C) 2009 Pascal Molli ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. # this test fails only for darcs 2 repositories rm -rf S1 S2 S3 # Another script may have left a mess. darcs init --repo S1 # Create our test repos. cd S1 cat > f << END 1 2 3 4 5 END darcs add f darcs record -am init cd .. darcs get S1 S2 darcs get S1 S3 cd S1 cat > f << END 1 2 X 3 4 5 END darcs record -am 'insert X before line 3' cd .. cd S2 cat > f << END 1 2 4 5 END darcs record -am 'delete line 3' cd .. cd S3 cat > f << END 1 2 3 Y 4 5 END darcs record -am 'insert Y after line 3' cd .. # please compare this with the issue1609 test darcs pull -a --repo S1 S2 darcs pull -a --repo S1 S3 darcs pull -a --repo S2 S1 darcs pull -a --repo S2 S3 darcs-2.14.5/tests/failing-issue1790_darcs-send.sh0000755000000000000000000000506007346545000017755 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1790 - darcs send --context foo should not require ## a remote repository ## ## Copyright (C) 2009 Loup Vaillant ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. darcs init --repo S cd R # populate R (optional) echo foo > foo.txt darcs add foo.txt darcs record -a -m "foo" # create a context file to represent R's state darcs changes --context > ../R.context cd .. # copy the repository the hard way. # normally one would use `darcs get A B` to do that, # but when no central server is available, this sort of # hard copy may be perceived as simpler: Just tar xcfz # the repository and send it via email. cp -r R S cd S # Make sure there is no _darcs/prefs/defaultrepo file # If there is one even on new repositories, that would # appear to solve the issue, but I think this is not a # good solution: the absence of the defaultrepo file # is useful to indicate the absence of interaction with # remote repositories. # # Of course, at the time of this writing, the following # line has no effect rm -rf _darcs/prefs/defaultrepo # make some further modifications (optional) echo bar > bar.txt darcs add bar.txt darcs record -a -m "bar" # try to send a patch to the first repository, # using its context file darcs send -a -o ../bar.patch --context=../R.context cd .. darcs-2.14.5/tests/failing-issue1819-pull-dont-allow-conflicts.sh0000755000000000000000000000151407346545000022666 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1819 - pull --dont-allow-conflicts doesn't work ## ## Dave Love , Public domain . lib rm -rf R S for repo in R S; do darcs init --repo $repo cd $repo echo 'Example content.' >x darcs add x darcs record -lam 'Add x' echo $repo >x darcs record -lam 'Change x' cd .. done darcs get S S0 cd S0 # the 'echo |' is for the external merge prompt 'hit return to continue' prompt echo | darcs pull --all --allow-conflicts --external-merge 'cp %2 %o' ../R cd .. darcs get S S0b cd S0b echo | not darcs pull --all --dont-allow-conflicts ../R cd .. darcs get S S1 cd S1 echo | not darcs pull --all --external-merge 'cp %2 %o' --dont-allow-conflicts ../R cd .. darcs get S S2 cd S2 echo | not darcs pull --all --dont-allow-conflicts --external-merge 'cp %2 %o' ../R cd .. darcs-2.14.5/tests/failing-issue1829-inconsistent-conflictor.sh0000755000000000000000000000402307346545000022531 0ustar0000000000000000#!/usr/bin/env bash ## Leads darcs into creating an inconsistent conflictor. ## Public Domain, 2010, Ganesh Sittampalam, Ian Lynagh and Petr Rockai # This file is included as part of the Darcs test distribution, # which is licensed to you under the following terms: # ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib grep darcs-2 $HOME/.darcs/defaults || exit 200 rm -rf r1 r2 mkdir r1 cd r1 darcs init echo Line BB > file darcs add file darcs rec -a -m "Main patch 1" echo Line DDDD >> file darcs rec -a -m "Main patch 2" echo Line A > file echo Line BB >> file echo Line CCC >> file echo Line DDDD >> file echo Line EEEEE >> file darcs rec -a -m "Main patch 3" cd .. mkdir r2 cd r2 darcs init darcs pull -a -p "Main patch 1" ../r1 echo Line TTTTTTT >> file darcs rec -a -m "Alternate patch 1" darcs pull -a -p "Main patch 2" ../r1 darcs revert -a echo Line XXXXXXXXX >> file darcs rec -a -m "Alternate patch 2" echo Line XXXXXXXXX > file darcs rec -a -m "Alternate patch 3" cd .. cd r1 darcs pull -a ../r2 darcs-2.14.5/tests/failing-issue1926_amend-record_ignores_--index.sh0000755000000000000000000000415007346545000023341 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1926 - amend-record --index ## ## Copyright (C) 2010 Iago Abal ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. #darcs init --repo S cd R echo 'Example content 1.' > f darcs record -lam 'Add file f' echo 'Example content 2.' > g darcs record -lam 'Add file g' darcs get . ../S # S as a copy of R echo "y" | darcs amend-record --index=2 -m 'A new file f' # Since --index is ignored this command works in # interactive mode, and the amended patch is the one # with index 1. darcs changes > changes cd .. cd S echo "y" | darcs amend-record -p 'Add file f' -m 'A new file f' # -p works as expected and amends the right patch. darcs changes > changes cd .. diff R/changes S/changes # Shows us the differences between both 'darcs changes'. darcs-2.14.5/tests/failing-issue1959-unwritable-cache.sh0000755000000000000000000000247307346545000021101 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1959 - if the index becomes unwritable, darcs should not die. ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R cd R echo test > test darcs rec -alm 'testing' chmod a-w _darcs/index darcs wh darcs-2.14.5/tests/failing-issue2047_duplicate_conflictor_recommute_fail.sh0000755000000000000000000000657107346545000025205 0ustar0000000000000000#!/usr/bin/env bash ## Test that shows failing commute of conflictors/duplicates. ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. # We want to create this situation: # # Context: [adddir "./dir1", addfile "./file1.txt"] # # (ParTree # (ParTree (DP "./dir1" RmDir) # (Move "./file1.txt" "./dir1/file3.txt") # (SeqTree (DP "./dir1" RmDir) (Move "./file1.txt" "./file2.txt"))) # # And then create the merged tree consisting of merging the second "branch" of # a par tree into the first, depth-first. # # Finally, we show that commute is broken for certain combinations of # conflictors/duplicates, since we can commute out one way, but not the # other. We do so, by creating both orderings of the final two patches, and # show that only in one case can we obliterate the penultimate patch alone (due # to non-commutation). # # See issue2047 on the BTS for more information. . ./lib rm -rf R1* R2 R3* darcs init --repo R1 cd R1 mkdir dir1 touch file1.txt darcs rec -alm 'Init' darcs get . ../R2 darcs get . ../R3 rmdir dir1 darcs rec -am 'Remove dir1' cd ../R2 darcs mv file1.txt dir1/file3.txt darcs rec -am 'Move 1 -> 3' # Create the first merged ParTree. cd ../R1 darcs pull -a ../R2 # Revert conflict-markup darcs rev -a # Create a copy of R1, so we can show the effect of commuting out the final two # patches, when we create a different ordered R3... darcs get . ../R1_OTHER cd ../R3 # Copy R3, so we can create the other ordering for its patches. darcs get . ../R3_OTHER #### In R3 we do rmdir; move file rmdir dir1 darcs rec -alm 'Rmdir' cd ../R1 darcs pull -a ../R3 darcs rev -a cd ../R3 darcs mv file1.txt file2.txt darcs rec -alm 'Move 1 -> 2' cd ../R1 darcs pull -a ../R3 darcs rev -a #### In R3_OTHER we do move file; rmdir cd ../R3_OTHER darcs mv file1.txt file2.txt darcs rec -alm 'Move 1 -> 2' cd ../R1_OTHER darcs pull -a ../R3_OTHER darcs rev -a cd ../R3_OTHER rmdir dir1 darcs rec -alm 'Rmdir' cd ../R1_OTHER darcs pull -a ../R3_OTHER darcs rev -a # Now, to show the bug, we can ob the penultimate patch from R1, but not # R1_OTHER cd ../R1 darcs ob -p 'Rmdir' -a [[ $(darcs changes --count) -eq 4 ]] cd ../R1_OTHER echo y | darcs ob -p 'Move 1 -> 2' -a # There should be 4 changes remaining, but due to the failure to commute, we'll # actually obliterate 2 patches, leaving 3. [[ $(darcs changes --count) -eq 4 ]] darcs-2.14.5/tests/failing-issue2100-add-failures.sh0000755000000000000000000000313107346545000020167 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2100 - darcs add should not fail on first failure ## ## Copyright (C) 2011 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R mkdir d echo 'Example content.' > d/f not darcs add d/non-existent not darcs whatsnew not darcs add d/non-existent d/f > log1 2>&1 darcs whatsnew > log2 2>&1 grep "./d/non-existent does not exist" log1 not grep "addfile ./d/non-existent" log2 grep "adddir ./d" log2 grep "addfile ./d/f" log2 darcs-2.14.5/tests/failing-issue2138-whatsnew-s.sh0000755000000000000000000000331307346545000017744 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2138 - whatsnew --summary does not show conflicts ## ## Copyright (C) 2012 Lele Gaifax ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S darcs init --repo R cd R echo 'Example content.' > f darcs record -lam 'Add f' cd .. darcs get R S # Create a deliberate conflict cd R echo "Conflict on side R" >> f darcs record -am 'CR' cd ../S echo "Conflict on side S" >> f darcs record -am 'CS' darcs pull -a ../R darcs whatsnew > out cat out grep "side R" out | wc -l | grep 1 grep "side S" out | wc -l | grep 1 darcs whatsnew --summary > out grep "^M!" out | wc -l | grep 1 cd .. rm -rf R S darcs-2.14.5/tests/failing-issue2186-apply--reply-conflict.sh0000755000000000000000000000417707346545000022012 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2186 - If a patch fails (e.g. because of a conflict), ## "apply --reply" does not email a status report. ## ## Copyright (C) 2012 Ilya Perminov ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Create a script that will be used instead of sendmail. It simply saves its # input to file "message". echo "#!/usr/bin/env bash" >dummy-sendmail echo "cat >message" >>dummy-sendmail chmod a+x dummy-sendmail darcs init --repo R darcs get R S # Create an email message with a patch cd R echo 'Example content.' >file1 darcs add file1 darcs rec -a --name patch1 darcs send --dont-edit-description --to noreply@example.net --mail --sendmail-command '../dummy-sendmail %<' -a ../S mv message patch-set1 # Create the same file in the target repository to trigger a conflict. cd ../S echo 'Some text.' >file1 darcs add file1 darcs rec -a --name patch2 # Apply the patch set. darcs should email a report. If it does our dummy-sendmail script will # create file "message". darcs apply --reply noreply@example.net --mail --sendmail-command '../dummy-sendmail %<' ../R/patch-set1 || true; test -f ./message darcs-2.14.5/tests/failing-issue2186-apply--reply-ok.sh0000755000000000000000000000373707346545000020623 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2186 - If patchs are applied successfully, ## "apply --reply" does not email a status report. ## ## Copyright (C) 2012 Ilya Perminov ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Create a script that will be used instead of sendmail. It simply saves its # input to file "message". echo "#!/usr/bin/env bash" >dummy-sendmail echo "cat >message" >>dummy-sendmail chmod a+x dummy-sendmail darcs init --repo R darcs get R S # Create an email message with a patch cd R echo 'Example content.' >file1 darcs add file1 darcs rec -a --name patch1 darcs send --dont-edit-description --to noreply@example.net --mail --sendmail-command '../dummy-sendmail %<' -a ../S mv message patch-set1 # Apply the patch set. darcs should email a report. If it does our dummy-sendmail script will # create file "message". cd ../S darcs apply --reply noreply@example.net --mail --sendmail-command '../dummy-sendmail %<' ../R/patch-set1 test -f ./message darcs-2.14.5/tests/failing-issue2187-apply--test-non-interactive.sh0000755000000000000000000000314307346545000023133 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2187 - "darcs apply --test file1 darcs add file1 darcs rec -a --name patch1 darcs send --dont-edit-description --output=./patch1 -a ../S # Setup a test that fails, apply the patch set, check for an unhandled exception. cd ../S darcs setpref test false not darcs apply --test <../R/patch1 > log 2>&1 not fgrep -q "illegal operation" log darcs-2.14.5/tests/failing-issue2203-only-list-toplevel-deleted-dirs.sh0000755000000000000000000000301007346545000023754 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2203 - darcs should only list toplevel deleted directories ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib rm -rf R darcs init --repo R cd R mkdir -p dir1/dir2 touch dir1/file1 touch dir1/dir2/file2 darcs rec -alm 'Add dirs/files' rm -r dir1 # Darcs should only report that the top-level dir has been removed, rather than # each dir/file (i.e 4 changes in this case, not 1). [[ $(darcs wh | grep '^rm' | wc -l) -eq 1 ]] darcs-2.14.5/tests/failing-issue2213-lastregrets-dependencies.sh0000755000000000000000000000270007346545000022620 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2213 - last regrets should respect patch dependencies when ## going back through patches ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R S darcs init --repo R darcs init --repo S cd R echo 'a' > file darcs rec -alm a echo 'b' > file darcs rec -alm b # Darcs shouldn't ask about b before asking about a. echo nkd | darcs push ../S | not grep b darcs-2.14.5/tests/failing-issue2219-no-working.sh0000755000000000000000000000441107346545000017736 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2219 - the --no-working-dir flag ## ### Copyright (C) 2011 Eric Kow ## ## Permission is hereby granted, free of charge, to any person o ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # getting a --no-working-dir repo should not create any of the wd files mkdir R1 cd R1 darcs init echo "howdy" > a darcs add a darcs record -a -m 'a file' a cd .. darcs get --no-working-dir R1 R2 test -e R1/a test ! -e R2/a # absence of a working dir should not result in a pull conflict # or a diff for that matter ## 2011-12-27: darcs failed: error opening _darcs/pristine.hashed/7cb4df6851fc86f51ee33ff490a85c9f4f5cc31f7c7d9977c50942453a1a94a9 darcs get R1 R1b cd R1b echo "more stuff" > a darcs record -a -m 'modify a' cd ../R2 darcs pull ../R1b -a # NB: not sure if this test expresses what I really intend DIFFCOUNT=$(darcs diff | wc -l) test $DIFFCOUNT -eq 0 # add should not work mkdir S1 cd S1 darcs init --no-working-dir echo "bonjour" > a not darcs add a cd .. # move and remove should not work darcs clone R1 R1m --no-working-dir cd R1m not darcs remove a not darcs move a b # --no-working-dir --working-dir flags should trump each other in the # same fashion as the rest of darcs not darcs clone --no-working-dir --with-working-dir R1 R3 not darcs clone --with-working-dir --no-working-dir R1 R4 darcs-2.14.5/tests/failing-issue2234-rollback-under-tag-with-filename.sh0000755000000000000000000000332107346545000024044 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2234 - darcs doesn't ignore tags when rolling back, so tagged ## patches can't be selected. ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib darcs init --repo R cd R echo -e "line1\nline2" > f1 cp f1 f2 darcs rec -alm 'Add files' # Make a couple of changes to two files sed -i -e 's/1/a/' f1 sed -i -e 's/2/b/' f2 darcs rec -am 'change 1' # Make another change to one file sed -i -e 's/1/A/' f2 darcs rec -am 'change 2' darcs tag footag # we'd like to cut down the presented patches, by giving a filename should ask # us about the changes in the first patch darcs rollback -p '1' f1 | not grep -i 'no patches selected' darcs-2.14.5/tests/failing-issue2256-diff-empty-argument.sh0000755000000000000000000000266407346545000021541 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2256 - Passing an empty string as an argument to darcs diff ## causes a failiure in updateIndex. ## Copyright (C) 2013 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R cd R echo foo > foo darcs rec -alm 'add foo' echo bar >> foo # This should not do anything. darcs diff '' 2>&1 > output # We don't want any output. [[ ! -s output ]] darcs-2.14.5/tests/failing-issue2257-impossible-obliterate-subset.sh0000755000000000000000000000435207346545000023453 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2257 - impossible case encountered when obliterating a subset ## of patches ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf issue2257 mkdir issue2257 cd issue2257 darcs init --repo single-patch darcs init --repo duplicate-patch cd single-patch mkdir dir touch dir/file1 darcs record -alm 'dir and file1' touch dir/file2 darcs record -alm 'addfile file2' cd ../duplicate-patch # Split the dir/file patch into the dir add, and then the file add. darcs pull -a ../single-patch -p 'dir and file' darcs unrecord -a # Only record 'adddir ./dir' echo yny | darcs record -m 'adddir dir' # Now record the addfile in a separate patch. darcs record -am 'addfile file1' # Pull in the other patches we don't have (which will include the original # "add dir/file1" patch again since we've amended it to no longer exist, and # the "addfile file2" patch) darcs pull -a ../single-patch # Attempt to obliterate 'addir dir' (but not 'addfile file1'). This seems to be # a problem with the patch selection, since without -p, we aren't able to # obliterate 'adddir dir', if we say no to 'addfile file1' (which is # sensible!). echo nyy | darcs obliterate -p 'adddir dir' darcs-2.14.5/tests/failing-issue2272-rebase-unsuspend-copes-with-unrecorded-changes.sh0000755000000000000000000000365507346545000026755 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2272 - darcs rebase unsuspend should cope with unrecorded changes. ## ## Copyright (C) 2013 Mark Stosberg ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R touch t.txt darcs add t.txt darcs record -am 'initial record' t.txt echo 'original line' > t.txt darcs record -am 'adding original line' t.txt # Now make an unrecorded change that's unrelated. touch 2.txt darcs add 2.txt # Suspend the initial patch darcs rebase suspend -a -p 'adding original line' # Now, unsuspend that patch. It should succeed despite unrecorded changes being present. darcs rebase unsuspend -a # Additional case: An unrecorded change that conflicts with the suspended patch # This should succeed, but leave conflict markers. echo 'modified line' >t.txt darcs rebase unsuspend -a cd ../ darcs-2.14.5/tests/failing-issue2275_follows-symlinks.sh0000755000000000000000000000361007346545000021264 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2275 - darcs follows symbolic links instead of properly ## ignoring them. ## When substituting a recorded file with a symbolic link, darcs becomes ## confused and associates the filename label to the content of the file ## pointed by the link. ## ## Copyright (C) 2017 Gian Piero Carrubba ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. abort_windows # Skip test on Windows darcs init --repo R # Create the test repo. cd R touch g # Change the working tree. echo 'This line should not appear in g.' > f darcs record -lam 'Add f and g.' rm -f g # Remove g and create a link with the ln -s f g # same name ponting to f darcs diff g | not grep -F '+This line should not appear in g.' cd .. darcs-2.14.5/tests/failing-issue2293-laziness-amend.sh0000755000000000000000000000244307346545000020563 0ustar0000000000000000#!/bin/sh -e ## ## Test that amend-record doesn't read too much of the repository ## ## Copyright (C) 2013 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib gunzip -c $TESTDATA/laziness-cut.tgz | tar xf - cd repo echo 'baz' > bar echo yyyy | darcs amend darcs-2.14.5/tests/failing-issue2303-diagnostic-for-bad-patch-index-permissions.sh0000755000000000000000000000334707346545000026054 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2303 - diagnostics for patch index should be clear there's a permission problem ## ## Copyright (C) 2013 Mark Stosberg ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R touch t.txt darcs add t.txt darcs record -am 'initial record' t.txt darcs optimize enable-patch-index chmod -w _darcs/patch_index # We expect this command to fail because the patch index isn't writable # and give a reasonable diagnostic that explains this. It should mention that # the permission problem is the _darcs/patch_index directory. not darcs oblit -a | grep '_darcs/patch_index'; cd ../ darcs-2.14.5/tests/failing-issue2310-rollback-doesnt-readd.sh0000755000000000000000000000277207346545000022004 0ustar0000000000000000## Test for issue2310 - darcs rollback of rmfile doesn't add to pending ## ## Copyright (C) 2013 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R darcs init --repo R cd R echo foo > foo darcs rec -alm 'add foo' rm foo darcs rec -am 'remove foo' echo ynya | darcs rollback # If the file hasn't been re-added in pending, this line will be missing from # the output of whatsnew darcs wh | grep 'A ./foo' darcs-2.14.5/tests/failing-issue2383-hunk-edit-fails.sh0000755000000000000000000000442407346545000020636 0ustar0000000000000000#!/bin/bash ## Test for issue2383 hunk-edit/last-regrets being able to put darcs into a ## state that it can't apply the recorded patch ## ## Copyright (C) 2013 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R darcs init --repo R cd R cat << EOF > file -- a comment data D = C Int deriving (Eq, Show) EOF darcs rec -alm 'Add file' cat << EOF > file -- another comment -- a comment data D = C !Int deriving (Eq) EOF # Massive hack! cat << EOF > change ========================== BEFORE (reference) ========================== data D = C Int deriving (Eq, Show) ============================= AFTER (edit) ============================= data D = C !Int deriving (Eq, Show) ============================= (edit above) ============================= EOF # Shell script "editor" that makes the change cat << EOF > foo #!/bin/bash cp change darcs-patch-edit-0 EOF chmod +x foo export DARCS_EDITOR='./foo' # Don't pick the first comment, do initially pick the data type change, then at # last regrets, go back (k) and edit the hunk (e), before accepting (y) the new # hunk change (keeping the Show instance). echo nykeyy | darcs rec -m 'Add strictness annotation to C Int' darcs-2.14.5/tests/failing-issue2386-no-trailing-EOL.sh0000755000000000000000000000303507346545000020512 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2386 - no trailing EOF produces spurious diff output ## ## Copyright (C) 2014 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib darcs init --repo R cd R # foo will contain "1\n2\n3" echo '0: 310a 320a 33' | xxd -r > foo darcs add foo # Bad output looked like: # # addfile ./foo # hunk ./foo 1 # - # +1 # +2 # +3 darcs wh | not grep '^-$' darcs rec -am 'Add foo' rm foo # Bad output looked like: # hunk ./foo 1 # -1 # -2 # -3 # + # rmfile ./foo darcs wh | not grep '^+$' darcs-2.14.5/tests/failing-issue2443-timestamp_index_keeps_unrecorded_addfile.sh0000755000000000000000000000307607346545000026114 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2443 - timestamp index keeps information about files ## added by unrecorded patches ## ## Copyright (C) 2017 Guillaume Hoffmann ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init R # Create our test repos. cd R touch a b c # add some files darcs record -lam "Add a b c" touch d darcs record -lam "Add d" # add another file echo yd | darcs unrecord not darcs whatsnew # d is not supposed to be tracked darcs-2.14.5/tests/failing-issue2548-inconsistent-pending-after-merge.sh0000755000000000000000000000156207346545000024213 0ustar0000000000000000. lib darcs init r1 cd r1 touch f darcs record -lam 'added f as file' cd .. darcs init r2 cd r2 mkdir f darcs record -lam 'added f as dir' darcs pull -a ../r1 # darcs-1 and darcs-2 resolve the conflict # differently, we allow both if cd f && cd ..; then rmdir f else rm f fi mv f.\~0\~ f # darcs whatsnew at this point reports nothing not grep . ../whatsnew # so revert should do nothing darcs revert -a # at this point pending should definitely be empty # and the following should fail (nothing to record) if not darcs record -lam 'resolve conflict'; then exit 0; else # check that what we record is at least consistent # i.e. we have either addfile or adddir for f, but not both darcs log -v --last=1 > ../log if grep 'addfile ./f' ../log; then not grep 'adddir ./f' ../log fi if grep 'adddir ./f' ../log; then not grep 'addfile ./f' ../log fi fi darcs-2.14.5/tests/failing-issue390_whatsnew.sh0000755000000000000000000000113607346545000017505 0ustar0000000000000000#!/usr/bin/env bash # For issue390: darcs whatsnew somefile" lstats every file in the working copy and pristine/ directory . ./lib if ! test -x "$(which strace)" then echo skipping test since strace was not found exit fi rm -rf temp mkdir temp cd temp darcs init date > file1 date > file2 darcs add file* darcs record -am "test" strace darcs whatsnew file1 &> out # we should be accessing file1 grep file1 out # but shouldn't be accessing file2 if grep file2 out then echo A whatsnew for file1 should not involve a 'stat' call to file2 exit 1 else echo Yay. We pass. fi rm -rf temp darcs-2.14.5/tests/failing-look_for_replaces1.sh0000755000000000000000000000273107346545000017754 0ustar0000000000000000#!/usr/bin/env bash ## Failing test for --look-for-replaces ## ## Copyright (C) 2013 Jose Neder ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R # forced replace (the word is in the file) (amend-record) # amending an addfile patch with a forced replace fails darcs init cat > file < file < _darcs/prefs/defaults # note: to make this pass, change echo to echo -n # is that right? echo "from temp1" > one.txt darcs add one.txt darcs record -A bar -am "add one.txt" echo >> one.txt darcs wh -u cd .. darcs get temp1 temp2 cd temp2 # reality check darcs show files | grep one.txt echo "in tmp2" >> one.txt darcs whatsnew -s | grep M darcs record -A bar -am "add extra line" darcs push -av > log cat log not grep -i conflicts log # BUG HERE # after a conflict, darcs mark-conflicts should report a conflict darcs mark-conflicts > log 2>&1 cat log not grep -i 'no conflicts' log cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/failing-newlines.sh0000755000000000000000000000071407346545000016026 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 # set up the repository mkdir temp1 cd temp1 darcs init cd .. cd temp1 echo -n "from temp1" > one.txt darcs add one.txt darcs record -A bar -am "add one.txt" echo >> one.txt cd .. darcs get temp1 temp2 cd temp2 echo "in tmp2" >> one.txt darcs record -A bar -am "add extra line" lines_added=`darcs changes -a -v --last=1 | grep '\+' | wc -l` echo $lines_added test $lines_added -eq 1 cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/failing-nice-resolutions.sh0000755000000000000000000000107507346545000017505 0ustar0000000000000000#!/bin/sh . ./lib mkdir temp1 cd temp1 darcs init echo a > foo darcs add foo darcs record -am addfoo cd .. darcs get temp1 temp2 cd temp2 echo B > foo darcs record -am B cd ../temp1 echo b > foo darcs record -am b echo c > foo darcs record -am c cd ../temp2 darcs pull -a cat foo grep b foo && exit 1 grep a foo && exit 1 grep B foo grep c foo echo C > foo darcs record -am C cd ../temp1 echo d > foo darcs record -am d cd ../temp2 darcs pull -a cat foo grep b foo && exit 1 grep a foo && exit 1 grep B foo && exit 1 grep c foo && exit 1 grep C foo grep d foo darcs-2.14.5/tests/failing-pristine-problems.sh0000755000000000000000000000356407346545000017666 0ustar0000000000000000#!/usr/bin/env bash ## Check for correct behaviour with missing files in pristine ## ## Copyright (C) 2010 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf foo mkdir foo cd foo darcs init echo 'wibble' > wibble darcs rec -lam 'wibble' darcs check roothash=`darcs show pristine | grep ' ./$' | cut -d' ' -f1` wibblehash=`darcs show pristine | grep ' wibble$' | cut -d' ' -f1` rm _darcs/pristine.hashed/$roothash not darcs check not darcs check # At the time of writing this test goes wrong at the line above # I'm not 100% certain if the rest of it is right. darcs repair | grep -v 'The repository is already consistent' darcs check rm _darcs/pristine.hashed/$wibblehash not darcs check not darcs check darcs repair | grep -v 'The repository is already consistent' darcs check darcs-2.14.5/tests/failing-record-scaling.sh0000755000000000000000000000330307346545000017073 0ustar0000000000000000#!/usr/bin/env bash ## Test for issueN - darcs record shouldn't access old inventories! ## ## Copyright (C) 2008 David Roundy ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. which strace || exit 200 # This test requires strace(1). rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repo. touch R/a-unique-filename strace -eopen -oR/trace \ darcs record --repo R -lam 'A unique commit message.' grep a-unique-filename R/trace grep _darcs/hashed_inventory R/trace not grep _darcs/inventories/ R/trace rm -rf R # Clean up after ourselves. darcs-2.14.5/tests/filename_with_spaces.sh0000755000000000000000000000032307346545000016740 0ustar0000000000000000. lib darcs init R cd R filename="file with spaces in its name" echo xxx > "$filename" darcs record -lam "comment" darcs log -s | grep -c "$filename" | grep -w 1 darcs log -v | grep -c "$filename" | grep -w 2 darcs-2.14.5/tests/filepath.sh0000755000000000000000000000543007346545000014367 0ustar0000000000000000#!/usr/bin/env bash # Some tests for proper handling of filepaths . lib DIR=`pwd` rm -rf temp1 temp2 # Make sure that init works with --repodir darcs init --repodir=temp1 test -d temp1/_darcs # add some meat to that repository cd temp1 touch baz darcs add baz darcs record -m moo -a cd .. # ---------------------------------------------------------------------- # local vs remote filepaths # ---------------------------------------------------------------------- # trick: OS-detection (if needed) if echo $OS | grep -i windows; then echo This test does not work on Windows else darcs get temp1 temp2 cd temp2 mkdir -p dir darcs add dir cd dir touch foo:bar darcs add --reserved-ok foo:bar cd ../.. rm -rf temp2 fi # ---------------------------------------------------------------------- # repodir stuff # ---------------------------------------------------------------------- mkdir -p temp1/non-darcs # FIXME: This test does not seem to make much sense # --repodir is not recursive not darcs get temp1/non-darcs 2> log grep "Not a repository" log rm -rf temp1/non-darcs rm -rf non-darcs # get accepts --repodir. darcs get --repodir=temp2 temp1 | grep -i "Finished cloning" test -d temp2/_darcs rm -rf temp2 # get accepts absolute --repodir. darcs get --repodir="${DIR}/temp2" temp1 | grep -i "Finished cloning" test -d temp2/_darcs # changes accepts --repodir. darcs changes --repodir=temp1 | grep -i "moo" # changes accepts absolute --repo. darcs changes --repo="${DIR}/temp1" | grep -i "moo" # changes accepts relative --repo. darcs changes --repo=temp1 | grep -i "moo" # [issue467] context --repodir darcs changes --context --repodir=temp1 | grep 'Context:' # dist accepts --repodir. darcs dist --repodir=temp1 | grep -i "Created dist" # optimize accepts --repodir. darcs optimize reorder --repodir=temp1 | grep -i "done" # repair accepts --repodir. darcs repair --repodir=temp1 | grep -i "already consistent" # replace accepts --repodir. darcs replace --repodir=temp1 foo bar baz # setpref accepts --repodir. darcs setpref --repodir=temp1 test echo | grep -i "Changing value of test" # test --linear accepts --repodir. darcs test --linear --repodir=temp1 | grep -i "Success!" # ---------------------------------------------------------------------- # converting between absolute and relative paths # ---------------------------------------------------------------------- rm -rf temp3 darcs get temp1 temp3 cd temp3 mkdir -p a/b cd .. cd temp2 echo hello 1 >> baz darcs record -m hello1 -a echo hello 2 >> baz darcs record -m hello2 -a cd .. # can handle .. path cd temp3 darcs pull ../temp2 --set-default -p1 --all | grep -i 'Finished pulling' darcs pull --dry-run | grep hello2 cd a/b #[issue268] repodir with subdir darcs pull --dry-run | grep hello2 cd .. cd .. rm -rf log temp1 temp2 temp3 darcs-2.14.5/tests/git_import_delete_empty_directories.sh0000755000000000000000000000727207346545000022112 0ustar0000000000000000#!/usr/bin/env bash ## ensure empty directories get deleted when importing from git ## ## Copyright (C) 2014 Owen Stephens ## 2016 Guillaume Hoffmann ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R1 R2 ! read -r -d '' DATA <<'EOF' blob mark :1 data 0 reset refs/heads/master commit refs/heads/master mark :2 author test 1500000000 +0000 committer test 1500000000 +0000 data 19 Add files and dirs M 100644 :1 file M 100644 :1 foodir/foo1 M 100644 :1 foodir/foo2 commit refs/heads/master mark :3 author test 1500000000 +0000 committer test 1500000000 +0000 data 12 remove foo2 from :2 D foodir/foo2 commit refs/heads/master mark :4 author test 1500000000 +0000 committer test 1500000000 +0000 data 21 Delete foo1 and file from :3 D foodir/foo1 D file EOF echo "$DATA" | darcs convert import R1 darcs init --repo R2 cd R2 echo yydy | darcs pull ../R1 # Ensure we delete the file (but not the directory!) [[ -d foodir && ! -e foodir/foo2 ]] darcs pull -a ../R1 # Make sure the folder is now deleted. [[ ! -d foodir ]] cd .. # only continue if git present git --version | grep -i "git version" || exit 200 git init gitsource cd gitsource mkdir -p dir1/dir2/dir3 echo "i am so deep" > dir1/dir2/dir3/f mkdir dir4 echo "blabla" > dir4/g echo "some other file" > h git add . git commit -m "blabla" rm dir1/dir2/dir3/f git add --all . git commit -m "deleted f" rm dir4/g git add --all . git commit -m "deleted g" git clean -fd # delete dir1 and dir4 cd .. (cd gitsource && git fast-export --all) | darcs convert import darcsmirror function wcDiff() { diff --exclude=_darcs --exclude=.git "$1" "$2" } wcDiff gitsource darcsmirror darcs check --repodir=darcsmirror # ensure repo is consistent # ensure dir is deleted after a file move out of it (a common case) # and that a dir is created when moving to it (also a common case) git init gitsource2 cd gitsource2 mkdir -p dir1/ echo "i want to move" > dir1/f echo "me too!!" > g echo "12345" > h echo "67890" > i git add . git commit -m "initial commit" mv dir1/f f git add --all . git commit -m "move dir1/f to f" mkdir dir2 mv g dir2/g git add --all . git commit -m "move g to dir2/" # the following commit could be problematic with darcs import, # with the addfile hunk ending up between both move hunks. mkdir dir3 mv h dir3/h mv i dir3/i git add --all . git commit -m "move h and i to dir2/" git clean -fd cd .. (cd gitsource2 && git fast-export --all -M) | darcs convert import darcsmirror2 # -M to generate file moves data wcDiff gitsource2 darcsmirror2 darcs check --repodir=darcsmirror2 # ensure repo is consistent darcs-2.14.5/tests/git_quoted_filenames.sh0000755000000000000000000000534007346545000016762 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2489 - convert import/export with spaces in paths ## ## Copyright (C) 2014 Owen Stephens ## 2016 Guillaume Hoffmann ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. # test http://bugs.darcs.net/issue2489 : # correctly import quoted paths function createFiles () { mkdir "i have spaces" echo "some contents" > "i have spaces/me too" echo "other contents" > "more spaces please" newline=$(echo -e 'a\nb') quoted='"quoted' echo testing1 > "$newline" echo testing2 > $quoted } function wcDiff() { diff --exclude=_darcs --exclude=.git "$1" "$2" } commitMsg="some files and dirs that need quoting" # Filenames containing double quotes are forbidden in Windows 10 # Although they can be written using raw NTFS APIs, it's probably # not worth trying to support them. IO operations in the standard # Haskell library don't support them either. # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx abort_windows # only run if git present git --version | grep -i "git version" || exit 200 git init gitsource cd gitsource createFiles git add . git commit -m "$commitMsg" cd .. (cd gitsource && git fast-export --all) | darcs convert import darcsmirror # working copies should be the same wcDiff gitsource darcsmirror # darcs to git direction darcs init darcssource cd darcssource createFiles # TODO: check this for testing on windows. darcs add --reserved-ok $quoted darcs rec -lam "$commitMsg" git init ../gitmirror darcs convert export | (cd ../gitmirror && git fast-import && git checkout) cd .. # working copies should be the same wcDiff darcssource gitmirror darcs-2.14.5/tests/git_rename_and_copy_files.sh0000755000000000000000000000354307346545000017746 0ustar0000000000000000#!/usr/bin/env bash ## ensure empty directories get deleted when importing from git ## ## Copyright (C) 2014 Owen Stephens ## 2016 Guillaume Hoffmann ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib ! read -r -d '' DATA <<'EOF' blob mark :1 data 8 testing reset refs/heads/master commit refs/heads/master mark :2 author CommiterName 1307452813 +0100 committer CommiterName 1307452813 +0100 data 6 add a M 100644 :1 a commit refs/heads/master mark :3 author CommiterName 1307452821 +0100 committer CommiterName 1307452821 +0100 data 19 Copy, rename, copy from :2 C "a" "c" R "a" "b" C b d C b a path/with spaces EOF rm -rf R echo "$DATA" | darcs convert import R cd R [[ -e c && -e b && -e d && ! -e a && -e "a path/with spaces" ]] [[ $(darcs log --count) -eq 2 ]] darcs-2.14.5/tests/git_rename_dir.sh0000755000000000000000000000362707346545000015551 0ustar0000000000000000#!/usr/bin/env bash ## ensure empty directories get deleted when importing from git ## ## Copyright (C) 2014 Owen Stephens ## 2016 Guillaume Hoffmann ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib ! read -r -d '' DATA <<'EOF' blob mark :1 data 8 testing reset refs/heads/master commit refs/heads/master mark :2 author CommiterName 1307452813 +0100 committer CommiterName 1307452813 +0100 data 10 add dir/a M 100644 :1 dir/a commit refs/heads/master mark :3 author CommiterName 1307452821 +0100 committer CommiterName 1307452821 +0100 data 24 copy, rename, copy dirs from :2 C "dir" "dir2" R "dir" "dir3/dir4" C "dir3/dir4" "dir4" EOF rm -rf R echo "$DATA" | darcs convert import R cd R [[ -e dir2 && -e dir3 && -e dir4 && (! -e dir) && -e dir2/a && -e dir3/dir4/a && -e dir4/a ]] [[ $(darcs log --count) -eq 2 ]] darcs-2.14.5/tests/gzcrcs.sh0000755000000000000000000000313207346545000014063 0ustar0000000000000000#!/usr/bin/env bash ## Test for gzcrcs command - check and repair corrupted CRCs on ## compressed files ## ## Copyright (C) 2009 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. # need to do this before loading lib as that sets -e darcs gzcrcs --help > /dev/null if [ $? == 2 ] ; then echo gzcrcs not supported by this darcs ; exit 0 ; fi . lib # Load some portability helpers. rm -rf maybench-crc gunzip -c $TESTDATA/maybench-crc.tgz | tar xf - cd maybench-crc not darcs gzcrcs --check darcs gzcrcs --repair darcs gzcrcs --check cd .. rm -rf maybench-crc darcs-2.14.5/tests/harness.sh0000755000000000000000000000143607346545000014240 0ustar0000000000000000#!/usr/bin/env bash . ./lib # Print some stuff out for debugging if something goes wrong: echo $HOME echo $PATH which darcs command -v darcs # Check things that should be true when all the testscripts run test -f "$HOME/lib" password="AKARABNADABARAK-KARABADANKBARAKA" grep $password "$HOME/test" || grep $password "$HOME/harness.sh" if echo $OS | grep -i windows; then if echo $OSTYPE | grep -i cygwin ; then real=$(cygpath -w $(command -v darcs.exe) | sed -e 's,\\,/,g' | tr -s '[:upper:]' '[:lower:]') else real=$(cmd //c echo $(command -v darcs.exe) | sed -e 's,\\,/,g' | tr -s '[:upper:]' '[:lower:]') fi wanted=$(echo "$DARCS" | sed -e 's,\\,/,g' | tr -s '[:upper:]' '[:lower:]') test "$real" = "$wanted" else command -v darcs | fgrep "$DARCS" fi darcs-2.14.5/tests/hashed_inventory.sh0000755000000000000000000000567707346545000016161 0ustar0000000000000000#!/usr/bin/env bash . ./lib # We'd just use `diff -x _darcs -r' if -x was portable. diffx () { { find $1 -type f; find $2 -type f; } | sed -e '/.*\/_darcs\//d' -e 's;^[^/]*;;' | grep -v darcs.tix | sort | uniq | { while read part; do diff -c $1$part $2$part done } } makepristine () { rm -rf pristine mkdir pristine for i in `darcs show files --no-files --no-pending`; do echo mkdir -p pristine/$i; mkdir -p pristine/$i; done for i in `darcs show files --no-directories --no-pending`; do echo darcs show contents $i ">" pristine/$i; darcs show contents $i > pristine/$i; cat pristine/$i; done } mkdir temp1 cd temp1 darcs init touch foo darcs add foo darcs rec -m t1 -a -A tester echo 1 >> foo darcs what -s | grep -v No\ changes darcs what -l | grep -v No\ changes darcs what -sl | grep -v No\ changes makepristine cd .. darcs get temp1 temp2 cd temp2 darcs changes makepristine cd .. darcs get temp1 temp3 cd temp3 darcs changes cp _darcs/hashed_inventory inv darcs optimize clean diff -c inv _darcs/hashed_inventory rm inv makepristine cd .. cat temp3/pristine/foo diffx temp2 temp3 diff -rc temp1/pristine temp3/pristine diff -rc temp2/pristine temp3/pristine cd temp1 darcs record -a -A tester -m t2 darcs push ../temp2 -a darcs push ../temp3 -a makepristine cd .. cd temp3 makepristine cd .. cd temp2 makepristine cd .. diffx temp2 temp3 diff -rc temp1/pristine temp3/pristine diff -rc temp2/pristine temp3/pristine cd temp1 date > foo darcs record -a -A tester -m t3 makepristine cd ../temp2 darcs pull -a makepristine cd ../temp3 darcs pull -a darcs check makepristine cd .. diffx temp2 temp3 diff -rc temp1/pristine temp3/pristine diff -rc temp2/pristine temp3/pristine cd temp1 darcs get . ../temp4 cd .. cd temp4 makepristine cd .. diffx temp2 temp4 diff -rc temp2/pristine temp4/pristine cd temp1 darcs tag -A tagger -m atag darcs check darcs optimize clean darcs check darcs changes | grep t1 cd .. cd temp3 date > foobarpatch darcs add foobarpatch darcs record -a -A silly -m foobarpatch darcs check darcs optimize clean darcs check darcs pull -a ../temp1 darcs check darcs optimize reorder darcs check grep 'Starting with inventory' _darcs/hashed_inventory cd .. cd temp1 darcs pull -a ../temp3 cd .. diff -c temp1/_darcs/hashed_inventory temp3/_darcs/hashed_inventory cd temp4 darcs pull -p foobarpatch -a ../temp3 darcs pull -a ../temp1 darcs optimize reorder darcs check darcs push ../temp1 cd .. diff temp1/_darcs/hashed_inventory temp4/_darcs/hashed_inventory darcs get temp1 temp5 cd temp5 darcs obliterate --last 3 -a darcs pull ../temp1 -a darcs obliterate --last 3 -a darcs pull ../temp2 -a darcs check darcs obliterate --last 3 -a darcs pull ../temp4 -a cd .. cd temp4 darcs obliterate --last 3 -a darcs pull ../temp5 -a cd .. cd temp2 darcs obliterate --last 3 -a darcs pull ../temp5 -a cd .. cd temp1 darcs obliterate --last 3 -a darcs pull ../temp5 -a cd .. darcs-2.14.5/tests/hidden_conflict.sh0000755000000000000000000000067507346545000015715 0ustar0000000000000000#!/bin/sh . ./lib # this test fails for darcs-1 repos skip-formats darcs-1 mkdir temp1 cd temp1 darcs init echo first > a darcs add a darcs record -am 'first' cd .. darcs get temp1 temp2 cd temp1 echo second > a darcs record -am 'first to second' echo first > a darcs record -am 'second back to first' cd .. cd temp2 echo third > a darcs record -am 'first to third' cd .. cd temp1 darcs pull -a ../temp2 | grep conflict grep third a cd .. darcs-2.14.5/tests/hidden_conflict2.sh0000755000000000000000000000153007346545000015766 0ustar0000000000000000#!/usr/bin/env bash . ./lib # A test for a missed resolution, inspired by bug #10 in RT rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init cd .. mkdir temp2 cd temp2 darcs init cd .. # set up temp1 cd temp1 cat > A << FOO i m b v FOO darcs add A darcs record -m 'add' --all cd .. # set up temp2 cd temp2 darcs pull --all ../temp1 cat > A << FOO J i C2 m D b v FOO darcs record -m 'change2' --all cd .. # generate a conflict cd temp1 cat > A << FOO I i C1 m b FOO darcs record -m 'change1' --all darcs pull --all ../temp2 # we should have a marked conflict now. grep 'v v' A # we resolve it simply by removing conflict markers. sed -e '/\^ \^\|\*\*\|v v/d' A > temp mv temp A darcs record -m resolution --all # now mark-conflicts shouldn't find any unmarked conflicts darcs mark-conflicts | grep "No conflicts to mark" cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/hijack.sh0000755000000000000000000000565307346545000014033 0ustar0000000000000000#!/usr/bin/env bash # Testing patch hijack interactions . lib rm -rf temp1 # set up the repository mkdir temp1 cd temp1 darcs init cd .. # create some simple patches by somebody else cd temp1 touch 1 2 3 4 5 darcs add * darcs record -a --author you 1 -m 'patch1a' darcs record -a --author you 2 -m 'patch2a' darcs record -a --author you 3 -m 'patch3a' darcs record -a --author you 4 -m 'patch4a' darcs record -a --author you 5 -m 'patch5a' cd .. # try amending a patch cd temp1 echo yn | darcs amend -p patch5 -m 'patch5b' | grep "Amend anyway" darcs log | grep patch5 darcs log | not grep patch5b echo yy | darcs amend -p patch5 -m 'patch5b' | grep "Amend anyway" darcs log | grep patch5b cd .. # try some unsuspending cd temp1 # ...hijack one # abort everywhere: need selectchanges for smarter behaviour echo yyn | darcs rebase suspend --all darcs log | grep 'patch1a' # nothing suspended darcs log | grep 'patch5b' # nothing suspended not darcs rebase unsuspend --all # not in progress # ...hijack all echo ya | darcs rebase suspend --all darcs log | not grep 'patch1a' darcs log | not grep 'patch5b' darcs rebase unsuspend --all darcs log | grep 'patch1a' darcs log | grep 'patch5b' cd .. # make some conflicting patches in another repo mkdir temp2 cd temp2 darcs init touch 1 2 3 4 5 darcs add * darcs record -a --author thirdperson 1 -m 'patch1c' darcs record -a --author thirdperson 2 -m 'patch2c' darcs record -a --author thirdperson 3 -m 'patch3c' darcs record -a --author thirdperson 4 -m 'patch4c' darcs record -a --author thirdperson 5 -m 'patch5c' cd .. # try suspending via rebase pull cd temp1 # first 'y' is for a "repositories seem to be unrelated" prompt echo yayyn | darcs rebase pull ../temp2 --all darcs log | grep 'patch1a' # nothing suspended or pulled darcs log | grep 'patch5b' # nothing suspended or pulled not darcs rebase unsuspend --all # not in progress echo yayyyyyy | darcs rebase pull ../temp2 --all darcs log | not grep 'patch1a' darcs log | not grep 'patch5b' darcs obliterate -a -p 'patch1c' darcs obliterate -a -p 'patch2c' darcs obliterate -a -p 'patch3c' darcs obliterate -a -p 'patch4c' darcs obliterate -a -p 'patch5c' darcs rebase unsuspend --all darcs log | grep 'patch1a' darcs log | grep 'patch5b' cd .. # try suspending via rebase apply cd temp2 darcs obliterate -a -o c.dpatch cd .. cd temp1 echo ayyn | darcs rebase apply ../temp2/c.dpatch --all darcs log | grep 'patch1a' # nothing suspended or pulled darcs log | grep 'patch5b' # nothing suspended or pulled not darcs rebase unsuspend --all # not in progress echo ayyyyyy | darcs rebase apply ../temp2/c.dpatch --all darcs log | not grep 'patch1a' darcs log | not grep 'patch5b' darcs obliterate -a -p 'patch1c' darcs obliterate -a -p 'patch2c' darcs obliterate -a -p 'patch3c' darcs obliterate -a -p 'patch4c' darcs obliterate -a -p 'patch5c' darcs rebase unsuspend --all darcs log | grep 'patch1a' darcs log | grep 'patch5b' cd .. darcs-2.14.5/tests/hunk-editor.sh0000755000000000000000000000310407346545000015020 0ustar0000000000000000#!/usr/bin/env bash ## Test for hunk editor ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R cd R echo 'version1' > file darcs record -lam "version1" echo 'version2' > file echo eyny | DARCS_EDITOR="sed -i -e s/version2/version1.5/" darcs record -m "version1.5" cat > expected < log < out cat out grep Proceed out darcs whatsnew echo y | darcs record -a --logfile log not darcs whatsnew darcs changes > out cat out not grep 'My private secret' out darcs changes --xml > out cat out grep 'My private secret' out cd .. rm -rf temp1 darcs-2.14.5/tests/ignoretimes.sh0000755000000000000000000000110207346545000015110 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 mkdir temp1 cd temp1 darcs init echo -e 'foo\nbar\nbaz' > f darcs rec -Ax -alm p1 echo -e 'foo\nbar\nwibble' > f darcs rec -Ax -alm p2 sleep 1 # ensure the timestamps would differ after this change alone echo -e 'baz\nbar\nwibble' > f # check that wh (without --ignore-times) sees the change now darcs wh > whatsnew grep 'foo' whatsnew # the problematic unpull darcs unpull --last 1 -a --ignore-times # whatsnew will now think there are no changes without --ignore-times darcs wh > whatsnew grep 'foo' whatsnew cd .. rm -rf temp1 darcs-2.14.5/tests/init.sh0000755000000000000000000000135007346545000013533 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init test -d _darcs not darcs init cd .. # Some tests for the repodir flag mkdir temp2 darcs init --repodir temp2 test -d temp2/_darcs # Checking that `darcs init x` works not darcs init x y # refuse when 2 arguments are given not darcs init x --repodir y # refuse for the same reason darcs init x rm -rf temp1 temp2 x ## issue1266 - attempting to initialize a repository inside ## another repository should cause a warning, because while perfectly ## legitimate, it is likely to be accidental. rm -rf out darcs init --repodir temp1 darcs init --repodir temp1/temp2 2>&1 | tee out grep -i WARNING out # A warning should be printed. rm -rf temp1 out darcs-2.14.5/tests/invalid_absolute_paths.sh0000755000000000000000000000356307346545000017323 0ustar0000000000000000#!/usr/bin/env bash ## ## Regression test for patch178 ## ## Copyright (C) 2010 Alexey Levan ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R if darcs move /non_existent_path/a /non_existent_path/b 2>&1 | grep 'bug'; then echo 'Not OK 1: darcs move causes a bug' exit 1 else echo 'OK 1' fi if darcs move /non_existent_path/a /non_existent_path/b /non_existent_path/c 2>&1 | grep 'Prelude.init: empty list'; then echo 'Not OK 2: darcs move causes an error' exit 1 else echo 'OK 2' fi if darcs annotate /non_existent_path/a 2>&1 | grep 'Pattern match failure'; then echo 'Not OK 3: darcs annotate causes an error' exit 1 else echo 'OK 3' fi cd .. rm -rf R darcs-2.14.5/tests/invalid_pending_after_mv_to_self.sh0000755000000000000000000000043507346545000021323 0ustar0000000000000000#!/usr/bin/env bash # A regression test for issue567 . ./lib rm -rf temp mkdir temp cd temp darcs init mkdir dir touch dir/t.t darcs add dir darcs add dir/t.t darcs record -am 'initial add' # grand finale? Can we move the file to itself? darcs mv dir/t.t dir/ cd .. rm -rf temp darcs-2.14.5/tests/issue1017_whatsnew_stack.sh0000755000000000000000000000037507346545000017344 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 mkdir temp1 cd temp1 darcs init printf "File contents" > foo darcs add foo darcs record -a -m 'foo' foo for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do cat foo foo > foo2; mv foo2 foo; done darcs what cd .. darcs-2.14.5/tests/issue1039.sh0000755000000000000000000000242007346545000014234 0ustar0000000000000000#!/usr/bin/env bash . lib # pull from not empty repo to empty repo rm -rf temp1 temp2 mkdir temp1 temp2 cd temp1 darcs init echo a > a darcs add a darcs record --all --name=a cd ../temp2 darcs init darcs pull --all --dont-allow-conflicts ../temp1 test `darcs changes --count` = "1" cd .. # push from not empty repo to empty repo rm -rf temp1 temp2 mkdir temp1 temp2 cd temp1 darcs init cd ../temp2 darcs init echo a > a darcs add a darcs record --all --name=a darcs push --all ../temp1 cd ../temp1 test `darcs changes --count` = "1" cd .. # send from not empty repo to not empty repo rm -rf temp1 temp2 mkdir temp1 temp2 cd temp1 darcs init echo a > a darcs add a darcs record --all --name=a for i in 1 2 3 4 5 6 7 8 9; do echo Change number $i >> a darcs record -a -m "change a $i" done cd ../temp2 darcs init echo b > b darcs add b darcs record --all --name=b for i in 1 2 3 4 5 6 7 8 9; do echo Change number $i >> b darcs record -a -m "change b $i" done echo no | darcs send --mail --all --to=random@random --sendmail-command=false ../temp1 echo yes | not darcs send --mail --all --to=random@random --sendmail-command=false ../temp1 not darcs send --mail --all --to=random@random --sendmail-command=false --allow-unrelated-repos ../temp1 cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/issue1043_geteff_a.sh0000755000000000000000000000211307346545000016046 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 # creating the fork point mkdir temp1 cd temp1 darcs init cat > foo << FOO original - apple original - banana FOO darcs add foo darcs record -am init cd .. darcs get temp1 temp2 # do some work in the mainline cd temp1 cat > foo << FOO conflict 1 - artichoke original - banana FOO darcs record -am 'conflict 1a' cat > foo << FOO conflict 1 - artichoke conflict 1 - brocolli FOO darcs record -am 'conflict 1b' cd .. # do some work in the branch cd temp2 cat > foo << FOO conflict 2 - aardvark original - banana conflict 2 - cougar FOO darcs record -am 'conflict 2' cd .. # in the branch, pull from the mainline and resolve the conflict cd temp2 darcs pull -a ../temp1 --allow-conflicts cat > foo << FOO resolution original - apple original - banana FOO darcs record -am 'resolve conflicts 2,1a,1b' cd .. # do some extra work in the mainline cd temp1 cat > foo << FOO original - apple FOO darcs record -am 'conflict 1c' cd .. # in the branch, pull from the mainline again cd temp2 darcs pull -a ../temp1 --allow-conflicts cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/issue1043_geteff_b.sh0000755000000000000000000000210507346545000016050 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 # creating the fork point mkdir temp1 cd temp1 darcs init cat > foo << FOO original - apple original - banana FOO darcs add foo darcs record -am init cd .. darcs get temp1 temp2 # do some work in the mainline cd temp1 cat > foo << FOO original - apple conflict 1 - brocolli FOO darcs record -am 'conflict 1b' cat > foo << FOO conflict 1 - artichoke original - banana FOO darcs record -am 'conflict 1a' cd .. # do some work in the branch cd temp2 cat > foo << FOO conflict 2 - aardvark original - banana conflict 2 - cougar FOO darcs record -am 'conflict 2' cd .. # in the branch, pull from the mainline and resolve the conflict cd temp2 darcs pull -a ../temp1 --allow-conflicts cat > foo << FOO resolution original - apple original - banana FOO darcs record -am 'resolve conflicts 2,1a,1b' cd .. # do some extra work in the mainline cd temp1 cat > foo << FOO original - apple FOO darcs record -am 'conflict 1c' cd .. # in the branch, pull from the mainline again cd temp2 darcs pull -a ../temp1 --allow-conflicts cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/issue1057.sh0000755000000000000000000000275307346545000014245 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1057 - when pulling from a symlink to the current ## repository, Darcs should detect that it *is* the current repo. ## ## Copyright (C) 2008 Thorkil Naur ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf temp mkdir temp cd temp mkdir repo cd repo darcs init cd .. ln -s repo srepo cd srepo DIR=`pwd` echo $DIR not darcs pull --debug -a "$DIR" 2> out cat out grep 'Can.t pull from current repository' out cd .. cd .. rm -rf temp darcs-2.14.5/tests/issue1078_symlink.sh0000755000000000000000000000066307346545000016014 0ustar0000000000000000#!/usr/bin/env bash . lib if echo $OS | grep -i windows; then echo this test does not work on windows because echo windows does not have symlinks exit 0 fi rm -rf temp1 temp2 mkdir temp1 ln -s temp1 temp2 cd temp2 darcs init touch a b DIR=`pwd` darcs add "${DIR}/../temp1/a" # should work, just to contrast with the case below darcs add "${DIR}/b" # this is the case we are testing for cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/issue1101.sh0000755000000000000000000000117607346545000014231 0ustar0000000000000000#!/usr/bin/env bash . ./lib DARCS_EDITOR=echo export DARCS_EDITOR export SENDMAIL=`which true` rm -rf temp1 temp2 mkdir temp1 temp2 cd temp2 darcs init # setup test cd ../temp1 darcs init touch foo bar darcs add foo bar darcs record -a -m add_foo_bar -A x # Test that --cc is also printed as recipient in case of success darcs send --mail --author=me -a --to=random@random --cc=foo@example.com ../temp2 2>&1|grep -i foo@example.com # Test that --cc is also printed as recipient in case of error darcs send --mail --author=me -a --to=random@random --cc=foo@example.com ../temp2 2>&1|grep -i foo@example.com cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/issue1105.sh0000755000000000000000000000147207346545000014234 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp mkdir temp cd temp darcs init darcs changes echo changes summary > _darcs/prefs/defaults darcs changes echo changes summary arg > _darcs/prefs/defaults not darcs changes echo ALL summary > _darcs/prefs/defaults darcs changes echo ALL summary arg > _darcs/prefs/defaults not darcs changes echo changes last 10 > _darcs/prefs/defaults darcs changes echo changes last > _darcs/prefs/defaults not darcs changes echo ALL last 10 > _darcs/prefs/defaults darcs changes echo ALL last > _darcs/prefs/defaults not darcs changes echo changes author me > _darcs/prefs/defaults not darcs changes echo changes author me > _darcs/prefs/defaults not darcs changes echo ALL author me > _darcs/prefs/defaults darcs changes echo ALL unknown > _darcs/prefs/defaults not darcs changes cd .. rm -rf temp darcs-2.14.5/tests/issue1196_whatsnew_falsely_lists_all_changes.sh0000755000000000000000000000024307346545000023436 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 mkdir temp1 cd temp1 darcs init echo utrecht > aargh darcs add aargh not darcs wh foo foo/../foo/. cd .. rm -rf temp1 darcs-2.14.5/tests/issue121.sh0000755000000000000000000000340307346545000014145 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue121 - amend-record --ask-deps ## ## Copyright (C) 2009 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R darcs init --repo R # Create our test repos. cd R touch a darcs add a darcs rec --ignore-times -am 'add a' (echo '1' ; echo '1' ; echo '1') > a darcs rec --ignore-times -am 'patch X' (echo '2' ; echo '1' ; echo '1') > a darcs rec --ignore-times -am 'patch Y' (echo '2' ; echo '1' ; echo '2') > a darcs rec --ignore-times -am 'patch Z' darcs obliterate --dry-run --patch 'patch Y' | not grep 'patch Z' echo 'yYyY' | tr '[A-Z]' '[a-z]' | darcs amend --ask-deps darcs obliterate --dry-run --patch 'patch Y' | grep 'patch Z' darcs-2.14.5/tests/issue1210-no-global-cache-in-sources.sh0000755000000000000000000000255407346545000021231 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1210 - 'global cache gets recorded in _darcs/prefs/sources' ## ## Copyright (C) 2010 Adolfo Builes ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib cacheDir=$HOME/.darcs/cache rm -rf R S darcs init --repo R darcs get R S not grep "$cacheDir" S/_darcs/prefs/sources not grep "cache:" S/_darcs/prefs/sources darcs-2.14.5/tests/issue1224_convert-darcs2-repository.sh0000755000000000000000000000332207346545000021363 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1224 - Attempting to darcs convert a repository ## which is already in darcs-2 format leads to inconsistent result ## ## Copyright (C) 2009 Tomas Caithaml ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. # this test is not relevant for other than darcs 2 repositories grep darcs-2 $HOME/.darcs/defaults || exit 200 . lib rm -rf R darcs init --repo R echo File contents > R/file.txt darcs add R/file.txt --repodir R darcs record --name=add_file.txt --author=me --no-test -a --repodir R # This should fail with repository already in darcs-2 format. echo "I understand the consequences of my action" > ack not darcs convert temp/repo-2 temp/repo-2-converted < ack rm -rf R darcs-2.14.5/tests/issue1269_setpref_predist.sh0000755000000000000000000000077507346545000017536 0ustar0000000000000000#!/bin/sh . ./lib not () { "$@" && exit 1 || :; } rm -rf temp rm -rf dist1269.tar.gz mkdir temp cd temp darcs init printf "Line1\nLine2\nLine3\n" > foo darcs record -alm Base darcs setpref predist false # It is a bug in darcs if the dist succeeds. It should # fail with a non-zero exit code not darcs dist -d dist1269 # It is a bug in darcs if the dist file has been created # it should /not/ be created if the predist cmd returned # a non-zero exit code not test -f dist1269.tar.gz cd .. rm -rf temp darcs-2.14.5/tests/issue1277-repo-format.sh0000755000000000000000000000376407346545000016505 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1277 - repository format errors should be reported ## correctly (ie. not as some totally unrelated error) ## ## Copyright (C) 2010 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R darcs init --repo R2 # Protect the darcs darcs repo with R cd R2 echo impossible >> _darcs/format echo 'Example content.' > f not darcs add f > log 2>&1 grep -i "read repository.*unknown format" log not darcs whatsnew > log 2>&1 grep -i "read repository.*unknown format" log not darcs init > log 2>&1 grep "You may not run this command in a repository" log grep -i "read repository.*unknown format" log cd .. not darcs whatsnew --repodir R2 > log 2>&1 grep "R2 looks like a repository directory," log grep -i "read repository.*unknown format" log cd .. darcs-2.14.5/tests/issue1300_record_delete-file.sh0000755000000000000000000000351107346545000020022 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1300 - record --delete-file should only delete ## after a successful record ## ## Copyright (C) 2009 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R touch f darcs add f # no test touch log echo 'no test' > f darcs record -am f --logfile log --delete-logfile test ! -e log # passing test touch log darcs setpref test 'exit 0' echo 'test pass' > f darcs record -am f --test --logfile log --delete-logfile test ! -e log # failing test touch log darcs setpref test 'exit 1' echo 'test fail' > f not darcs record -am g --test --logfile log --delete-logfile test -e log # should *not* be deleted cd .. darcs-2.14.5/tests/issue1332_add_r_boring.sh0000755000000000000000000000324207346545000016724 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1332 - add -r ignores --boring ## ## Copyright (C) 2009 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R mkdir d touch core f # this is already known to work darcs add --boring core f darcs whatsnew > log grep 'addfile ./f' log grep 'addfile ./core' log rm _darcs/patches/pending touch _darcs/index_invalid # this fails for issue1332 darcs add -r --boring . darcs whatsnew > log grep 'addfile ./f' log grep 'addfile ./core' log darcs-2.14.5/tests/issue1344_abort_early_cant_send.sh0000755000000000000000000000467207346545000020647 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1344 - abort early darcs send if sendmail is not ## available ## ## Copyright (C) 2010 Gabriel Kerneis ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib # The mail sending code on Windows uses the MAPI API unconditionally # so this test fails. # If it's possible to discover in advance whether mail sending would work, # the code and this test could be improved to do that. abort_windows # Skip this test if sendmail is available if which sendmail ; then echo "Sendmail found (in path), skipping test." exit 200 fi if [ -f "/usr/sbin/sendmail" -o -f "/sbin/sendmail" -o \ -f "/usr/lib/sendmail" ]; then echo "Sendmail found, skipping test." exit 200 fi DARCS_EDITOR=echo export DARCS_EDITOR mkdir temp1 temp2 cd temp2 darcs init # setup test cd ../temp1 darcs init touch foo bar darcs add foo bar darcs record -a -m add_foo_bar -A x # If --mail and --sendmail-command is provided, no warning darcs send --mail --author=me -a --to=random@random --sendmail-command='true' ../temp2 # If --mail and --dry-run is provided, no warning darcs send --mail --author=me -a --to=random@random --dry-run ../temp2 # If --mail is not provided, no warning darcs send --author=me -a --to=random@random -O ../temp2 darcs send --author=me -a --to=random@random -o test.patch ../temp2 # Otherwise, fail early (darcs send --mail --author=me -a --to=random@random ../temp2 || true) | grep "No working sendmail" cd .. darcs-2.14.5/tests/issue1373_replace_token_chars.sh0000755000000000000000000000355007346545000020315 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1373 - check that --token-chars [^ \t] is allowed. ## While we're at it, check some other things *aren't* allowed. ## ## Copyright (C) 2009 Trent W. Buck ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf temp # Another script may have left a mess. darcs init --repodir temp replace () { darcs replace --repodir temp --token-chars "$1" x y; } ## These are not well-formed tokens. not replace '' not replace 'a' not replace ']a[' not replace '[]' not replace '[^]' ## These are well-formed, but allow tokens to contain whitespace. not replace $'[ ]' not replace $'[\t]' not replace $'[\n]' not replace $'[\r]' not replace $'[\v]' not replace $'[^ ]' not replace $'[^\t]' not replace $'[^\n]' not replace $'[^\r]' not replace $'[^\v]' rm -rf temp # Clean up after ourselves. darcs-2.14.5/tests/issue1392_authorspelling.sh0000755000000000000000000000336107346545000017363 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1392 - .authorspelling processing. ## ## Copyright (C) 2009 Tomas Caithaml ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R echo 'Bad\, Jr. , Foo' > .authorspellings echo 'Example content.' > f darcs record -lam 'Add f.' -A 'Foo' darcs show authors | grep -q 'Bad, Jr\. ' echo 'Bad\, Jr. , ^Foo\, Jr\..*$' > .authorspellings echo 'Ex. cont.' > f darcs record -lam 'Change f.' -A 'Foo, Jr. ' darcs show authors | tee output.txt | grep -q 'Bad, Jr\. ' cd .. #--rm -rf R darcs-2.14.5/tests/issue1446.sh0000755000000000000000000000443207346545000014243 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1446 - darcs amend-record -m foo destroys long description without warning ## ## Copyright (C) 2009 Dmitry Kurochkin ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repo. touch R/f darcs add f --repo R echo 'patch name' > R/patchinfo echo 'patch description' >> R/patchinfo darcs record -a --logfile=R/patchinfo --repo R darcs changes --repo R | grep 'patch name' darcs changes --repo R | grep 'patch description' echo 'y' | darcs amend-record -p 'patch name' -m 'new name' --repo R darcs changes --repo R | grep 'new name' darcs changes --repo R | grep 'patch description' echo content > R/f echo 'another name' > R/patchinfo echo 'another description' >> R/patchinfo darcs record -a --logfile=R/patchinfo --repo R darcs changes --repo R | grep 'another name' darcs changes --repo R | grep 'another description' echo 'y' | darcs amend-record -p 'another name' -m 'one more name' --repo R darcs changes --repo R | grep 'one more name' darcs changes --repo R | grep 'another description' rm -rf R/ # Clean up after ourselves. darcs-2.14.5/tests/issue1465_ortryrunning.sh0000755000000000000000000000555707346545000017115 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1465 - ortryrunning should try RHS if AND ONLY IF the ## LHS wasn't found or wasn't executable. ## ## Copyright (C) 2009 Trent W. Buck ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repo. FAKE_EDITOR_HOME=`pwd` cat < editor-good.hs import System.Environment import System.IO main = getArgs >>= \[name] -> writeFile name "fake" FAKE ghc -o editor-good --make editor-good.hs cat < editor-bad.hs import System.Exit main = exitWith (ExitFailure 127) FAKE ghc -o editor-bad --make editor-bad.hs cat < editor-gave-up.hs import System.Exit main = exitWith (ExitFailure 1) FAKE ghc -o editor-gave-up --make editor-gave-up.hs cat < vi.hs import System.Environment import System.IO main = getArgs >>= \[name] -> writeFile name "vi" VI ghc -o vi --make vi.hs cd R mkdir d unset TERM DARCSDIR=$(dirname $(which darcs)) # the /dev/null stdin redirection is to make vi or the fallback editor just fail DARCS_EDITOR=$FAKE_EDITOR_HOME/editor-good \ darcs record -lam 'Initial commit.' --edit log-1 darcs changes > changes-1 darcs unrecord -a grep fake changes-1 # Bad editor: fall through to the next choice DARCS_EDITOR=$FAKE_EDITOR_HOME/editor-bad \ PATH=.:$DARCSDIR \ darcs record -lam 'Initial commit.' --edit log-2 darcs changes > changes-2 darcs unrecord -a grep "Initial" changes-2 egrep -i 'vi|emacs|nano|edit' log-2 # Normal failure (eg. user hit ^-C) # If Darcs did the right thing, the output won't make any mention of # the fallback editors. DARCS_EDITOR=$FAKE_EDITOR_HOME/editor-gave-up \ darcs record -lam 'Initial commit.' --edit log-3 darcs changes > changes-3 darcs unrecord -a grep "Initial" changes-3 not egrep -i 'not found|vi|emacs|nano|edit' log-3 darcs-2.14.5/tests/issue1488_whatsnew-l.sh0000755000000000000000000000271207346545000016421 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1488 - whatsnew in non-added directory crashes on fromJust ## ## Copyright (C) 2009 Marnix Klooster ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R mkdir -p R/Foo/Bar # 2 directory levels needed cd R darcs init cd Foo/Bar # and now the real problem causer: darcs whatsnew -l . # a "fromJust error" in Whatsnew.lhs darcs-2.14.5/tests/issue1514-send-minimize.sh0000755000000000000000000000365407346545000017012 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1514: send --minimize ## ## Copyright (C) 2014 G. Hoffmann ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo SCREENED # Create our test repos. cd SCREENED touch a darcs rec -lam a touch b darcs rec -lam b cd .. darcs clone SCREENED LOCAL darcs clone SCREENED REVIEWED cd LOCAL touch c darcs rec -lam c darcs push --all # so SCREENED has c # now create a patch we'll send as bundle with full context touch d darcs rec -lam d darcs send --all -o bundle --no-minimize # check it cannot be applied to REVIEWED (which lacks patch c) not darcs apply bundle --all --repodir=../REVIEWED # now create bundle with minimal context (default option) darcs send --all -o bundle.min # this one lacks c in its context so it can be applied to REVIEWED darcs apply bundle.min --all --repodir=../REVIEWED cd .. darcs-2.14.5/tests/issue154_pull_dir_not_empty.sh0000755000000000000000000000313107346545000020141 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue154 - when applying a patch that removes a directory, ## don't remove the directory from the working tree unless it's empty. ## ## Copyright (C) 2008 Mark Stosberg ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf temp1 mkdir temp1 cd temp1 darcs init mkdir d darcs add d darcs record -a -m "Added directory d" darcs get ./ puller cd puller touch d/moo darcs add d/moo cd .. rm -rf d darcs record -a -m "Remove directory d" cd puller echo y | darcs pull -a .. > log grep -i "backing up" log grep -i "finished pulling" log cd .. rm -rf temp1 darcs-2.14.5/tests/issue1558_xml_output_gz_extension.sh0000755000000000000000000000275507346545000021351 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1558 - xml output for patch hash includes "gz" ## extension ## ## Copyright (C) 2010 Gabriel Kerneis ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R mkdir d e # Change the working tree. echo 'Example content.' > d/f darcs record -lam 'Add d/f and e.' darcs changes --xml | not grep "\\.gz" cd .. darcs-2.14.5/tests/issue1611_amend-tag.sh0000755000000000000000000000310607346545000016147 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1611 - amend-record should prevent adding new changes to a tag. ## ## Copyright (C) 2011 Iago Abal Rivas ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R # Creates a patch echo 'Example content.' > f darcs record -lam 'Add f' darcs tag V1 # Creates a tag echo 'Another example content.' > f # Edit repository # Amend the tag should be illegal echo y | darcs amend -ap 'V1' | not grep 'amending patch' darcs-2.14.5/tests/issue1618-amend-preserve-logfile.sh0000755000000000000000000000321407346545000020573 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1618 - amend should preserve the logfile ## in case of failure ## ## Copyright (C) 2009 Kamil Dworakowski ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib rm -rf R; mkdir R; cd R darcs init darcs setpref test false darcs record -am foo --no-test export DARCS_EDITOR="echo 'new log' > " echo yn | not darcs amend -p foo --edit-long-comment --test 2> out # the msg has the format: "Logfile left in filenamehere." LOGFILE=`grep "Logfile left in" out | sed "s/Logfile left in //" | sed s/.$//` echo $LOGFILE test -e "$LOGFILE" grep 'new log' $LOGFILE rm out; cd ..; rm -rf R/ darcs-2.14.5/tests/issue1620-record-lies-about-leaving-logfile.sh0000755000000000000000000000313107346545000022610 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1620 - record does not really leave logfile ## after a failure ## ## Copyright (C) 2009 Kamil Dworakowski ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib rm -rf R; mkdir R; cd R export DARCS_EDITOR="echo 'a log' > " darcs init darcs setpref test false echo yy| not darcs record -m foo -a --edit-long-comment --test 2> out # the msg has the format: "Logfile left in filenamehere." LOGFILE=`grep "Logfile left in" out | sed "s/Logfile left in //" | sed s/.$//` test -e "$LOGFILE" grep 'a log' $LOGFILE rm out cd .. rm -rf R/ darcs-2.14.5/tests/issue1636-match-hunk.sh0000755000000000000000000000341607346545000016302 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1636 - primitive match type: hunk ## ## Copyright (C) Kamil Dworakowski ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R darcs init --repo R # Create our test repos. cd R echo 'first line' > f darcs record -lam 'one' echo 'second line' >> f darcs record -am 'two' darcs changes --match 'hunk first' > log grep one log not grep two log darcs changes --match 'hunk line' > log grep one log grep two log darcs changes --match 'hunk one' > log not grep one log # test searching for lines in the remove part of the hunk echo 'first line' > f darcs record -am 'three' darcs changes --match 'hunk second' > log grep three log grep two log not grep first log darcs-2.14.5/tests/issue1640_verbose_stdin.sh0000755000000000000000000000416007346545000017163 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1640 - ## ## Copyright (C) 2011 Radoslav Dorcik ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. ####################################################### # Test preparation ####################################################### # Create repository darcs init --repo S darcs init --repo T darcs init --repo T2 cd S touch foo bar darcs add foo bar darcs record -a -m add_foo_bar -A x darcs send --author=me --output=funpatch -a ../T ####################################################### # Apply from stdin and check message ####################################################### # Message when --verbose cd ../T darcs apply --verbose < ../S/funpatch | tee output.txt grep "reading patch bundle from stdin..." output.txt || exit 1 # No message when no --verbose cd ../T2 darcs apply < ../S/funpatch | tee output.txt grep "reading patch bundle from stdin..." output.txt && exit 1 exit 0; darcs-2.14.5/tests/issue1645-ignore-symlinks-case-fold.sh0000755000000000000000000000621207346545000021225 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1645 - Since Darcs does not version-contol symlinks, ## it should not follow them, ESPECIALLY symlinks to directories ## outside the repository. All these tests are passed with darcs-2.2 ## ## See path_resolution(7) and symlink(7) for more info, especially ## the former. ## ## This only covers the case-folding test cases. ## See also the issue1645-ignore-symlinks for the main test ## ## Copyright (C) 2010 Trent W. Buck, Dmitry Astapov ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. darcs init --repo S add_to_boring() { echo "$1" >> _darcs/prefs/boring } ## These are the simple does-the-wrong-thing errors. cd R touch log add_to_boring '^log$' unset pwd # Since this test is pretty much linux-specific, hspwd.hs is not needed # Skip the case-folding tests on systems that don't support it touch cs-test ln -s cs-test cs-Test || exit 200 rm cs-test cs-Test # move file and symlink out of the way for real tests # Case 15: case-folding link to non-recorded file touch non-recorded-file2 ln -s ./non-recorded-file2 ./Non-Recorded-File2 ln -s "`pwd`"/non-recorded-file2 ./Non-ReCoRdEd-File2 darcs w -l >log 2>&1 # should report only "non-recorded-file" darcs rec -alm "added ./non-recorded-file2" >>log 2>&1 # should add only file, not symlink darcs changes -s --patches="added ./non-recorded-file2" >>log 2>&1 # should report only file, not symlink not grep -vE "(^patch|^Author|^ *$|^\+|[0-9]:[0-9][0-9]:[0-9]|./non-recorded-file2)" log rm Non-Recorded-File2 ./Non-ReCoRdEd-File2 # Case 16: case-folding link to recorded file ln -s ./recorded-file ./Recorded-File ln -s "`pwd`"/recorded-file ./ReCorded-File not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log rm Recorded-File ReCorded-File darcs-2.14.5/tests/issue1645-ignore-symlinks.sh0000755000000000000000000001707707346545000017405 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1645 - Since Darcs does not version-contol symlinks, ## it should not follow them, ESPECIALLY symlinks to directories ## outside the repository. All these tests are passed with darcs-2.2 ## ## See path_resolution(7) and symlink(7) for more info, especially ## the former. ## ## There's a second section to this test for systems that support ## case-folding. See issue1645-ignore-symlinks-case-fold.sh ## ## Copyright (C) 2010 Trent W. Buck, Dmitry Astapov ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. darcs init --repo S darcs --version add_to_boring() { echo "$1" >> _darcs/prefs/boring } ## These are the simple does-the-wrong-thing errors. cd R touch log add_to_boring '^log$' unset pwd # Since this test is pretty much linux-specific, hspwd.hs is not needed abort_windows # and skip if we are on win32... # Case 1: looping symlink to non-recorded non-boring dir mkdir non-recorded-dir ln -s ../non-recorded-dir ./non-recorded-dir/loop # relative symlink ln -s "`pwd`"/non-recorded-dir ./non-recorded-dir/loop2 # absolute symlink darcs w -l >log 2>&1 # should not loop darcs rec -alm "added ./non-recorded-dir" >>log 2>&1 # should not loop darcs changes -s --patches="added ./non-recorded-dir" >>log 2>&1 # should report only dir, not symlink not grep -vE "(^patch|^Author|^ *$|^\+|[0-9]:[0-9][0-9]:[0-9]|./non-recorded-dir)" log # Case 2: looping symlink to recorded dir mkdir recorded-dir darcs add recorded-dir darcs rec -am "added recorded-dir" ln -s ../recorded-dir ./recorded-dir/loop # relative symlink ln -s "`pwd`"/recorded-dir ./recorded-dir/loop2 # absolute symlink not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log # Case 3: looping symlink to boring dir mkdir boring-dir add_to_boring '^boring-dir$' ln -s ../boring-dir ./boring-dir/loop ln -s "`pwd`"/boting-dir ./boring-dir/loop2 not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log # Case 4: non-looping symlink to non-recorded non-boring dir mkdir non-recorded-dir2 ln -s ./non-recorded-dir2 link ln -s "`pwd`"/non-recorded-dir2 ./link2 darcs w -l >log 2>&1 # should report only "non-recorded-dir2" darcs rec -alm "added ./non-recorded-dir2" >>log 2>&1 # should add only dir, not symlink darcs changes -s --patches="added ./non-recorded-dir2" >>log 2>&1 # should report only dir, not symlink not grep -vE "(^patch|^Author|^ *$|^\+|[0-9]:[0-9][0-9]:[0-9]|./non-recorded-dir2)" log rm link link2 # Case 5: non-looping symlink to recorded dir ln -s ./recorded-dir ./link ln -s "`pwd`"/recorded-dir ./link2 not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log rm link link2 # Case 6: non-looping symlink to boring dir ln -s ./boring-dir ./link ln -s "`pwd`"/boring-dir ./link2 not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log rm link link2 # Case 7: symlink pointing outside the repo ln -s ../S link (cd ..; ln -s "`pwd`"/S ./R/link2) not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log rm link link2 # Case 8: symlink to non-recorded non-boring file touch non-recorded-file ln -s ./non-recorded-file ./link ln -s "`pwd`"/non-recorded-file ./link2 darcs w -l >log 2>&1 # should report only "non-recorded-file" darcs rec -alm "added ./non-recorded-file" >>log 2>&1 # should add only file, not symlink darcs changes -s --patches="added ./non-recorded-file" >>log 2>&1 # should report only file, not symlink not grep -vE "(^patch|^Author|^ *$|^\+|[0-9]:[0-9][0-9]:[0-9]|./non-recorded-file)" log rm link link2 # Case 9: symlink to recorded file echo "some content" > recorded-file darcs add recorded-file darcs rec -am "added recorded-file" recorded-file ln -s ./recorded-file ./link ln -s "`pwd`"/recorded-file ./link2 not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log rm link link2 # Case 10: symlink to boring file ln -s ./log ./link ln -s "`pwd`"/log ./link2 not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log rm link link2 # Case 11: dangling symlink ln -s /completely/bogus/path ./link ln -s ../../../../not/exist ./link2 not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log rm link link2 # Case 12: self-referencing link ln -s l l ln -s "`pwd`"/l2 ./l2 not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log rm l l2 # Case 13: link to device file outside the repo ln -s /dev/zero l not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log rm l # Case 14: link to fifo mkfifo f ln -s f l ln -s "`pwd`"/f ./l2 not darcs w -l >log 2>&1 # expecting "No changes!" not darcs rec -alm "should not happen" >>log 2>&1 # expecting "No changes!" as well not grep -vE "(^ *$|^\+|No changes!)" log rm f l l2 darcs-2.14.5/tests/issue1702-optimize-relink-vs-cache.sh0000755000000000000000000000604407346545000021046 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1702 - an optimize --relink does not relink the files ## in ~/.darcs/cache. ## ## Copyright (C) 2009 Trent W. Buck ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. ## Create a patch. echo 'Example content.' > R/f darcs record -lam 'Add f.' --repodir R ## Get a hard link into the cache. darcs get R S ## Are hard links available? x=(R/_darcs/patches/*-*) x=${x#R/_darcs/patches/} if [[ ! R/_darcs/patches/$x -ef ~/.darcs/cache/patches/$x ]] then echo This test requires filesystem support for hard links. echo This test requires the hashed or darcs-2 repo format. exit 200 fi ## IMPORTANT! In bash [[ ]] is neither a builtin nor a command; it is ## a keyword. This means it can fail without tripping ./lib's set -e. ## This is why all invocations below have the form [[ ... ]] || false. ## Confirm that all three are hard linked. ls -lids {~/.darcs/cache,[RS]/_darcs}/patches/$x # debugging [[ R/_darcs/patches/$x -ef ~/.darcs/cache/patches/$x ]] || false [[ S/_darcs/patches/$x -ef ~/.darcs/cache/patches/$x ]] || false [[ R/_darcs/patches/$x -ef S/_darcs/patches/$x ]] || false ## Break all hard links. rm -rf S cp -r R S rm -rf R cp -r S R ## Confirm that there are no hard links. ls -lids {~/.darcs/cache,[RS]/_darcs}/patches/$x # debugging [[ ! R/_darcs/patches/$x -ef ~/.darcs/cache/patches/$x ]] || false [[ ! S/_darcs/patches/$x -ef ~/.darcs/cache/patches/$x ]] || false [[ ! R/_darcs/patches/$x -ef S/_darcs/patches/$x ]] || false ## Optimize *should* hard-link all three together. darcs optimize relink --repodir R --sibling S ## Confirm that all three are hard linked. ls -lids {~/.darcs/cache,[RS]/_darcs}/patches/$x # debugging [[ R/_darcs/patches/$x -ef ~/.darcs/cache/patches/$x ]] || false [[ S/_darcs/patches/$x -ef ~/.darcs/cache/patches/$x ]] || false [[ R/_darcs/patches/$x -ef S/_darcs/patches/$x ]] || false darcs-2.14.5/tests/issue1726_darcs_always-boring.sh0000755000000000000000000000464107346545000020260 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1726 - Files whose names start with "_darcs" are considered ## boring, even if they don't match anything in the boring file, and even if ## you pass --boring to the command. ## ## Copyright (C) 2009 Daniel Dickison ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R ## First test expected failures with actual _darcs files/directories function bad_add { filename="$1" touch "$filename" not darcs whatsnew -ls --boring not darcs whatsnew -ls not darcs add --boring "$filename" } touch _darcs/foo bad_add _darcs bad_add _darcs/ bad_add _darcs/foo bad_add ./_darcs bad_add ./_darcs/ bad_add ./_darcs/foo bad_add "$PWD/_darcs" bad_add "$PWD/_darcs/" bad_add "$PWD/_darcs/foo" bad_add "../${PWD##*/}/_darcs" bad_add "../${PWD##*/}/_darcs/" bad_add "../${PWD##*/}/_darcs/foo" ## Then test expected successes with files that aren't in _darcs # Passing --boring should definitely succeed. touch _darcsfoo darcs whatsnew -ls --boring darcs add --boring _darcsfoo darcs record -am 'add _darcsfoo' _darcsfoo # Without --boring, this tests the default boring file. touch _darcsbar darcs whatsnew -ls darcs add _darcsbar darcs record -am 'add _darcsbar' _darcsbar darcs-2.14.5/tests/issue1727_move_current_directory.sh0000755000000000000000000000365207346545000021124 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1727 - darcs move . target' fails as an attempt to ## write an 'invalid pending. ## ## Copyright (C) 2009 Sean Erle Johnson ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. # Create repository R darcs init --repo R # Create the test repo. cd R mkdir d # Change the working tree. # darcs move empty current directory to existing directory d not darcs move . d # darcs move empty current directory to non-existing directory e not darcs move . e # Make file to be copied echo 'main = putStrLn "Hello World"' > hello.hs # darcs move non-empty current directory to existing directory d not darcs move . d # darcs move non-empty current directory to non-existing directory e not darcs move . e mkdir e cd e not darcs move .. edarcs-2.14.5/tests/issue1737-move_args.sh0000755000000000000000000000326307346545000016227 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1737 - command line filtering on darcs move ## yields suprising results with shell globs ## ## Copyright (C) 2010 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R mkdir d touch d.txt darcs record -lam 'Add d and d.txt' darcs move d d.txt d 2> log || : # this can happen if eg. you darcs move d* d # d.txt isn't a directory; we should probably just say that you # can't move a directory on to itself not grep "target directory d.txt" log darcs-2.14.5/tests/issue1739-escape-multibyte-chars-correctly.sh0000755000000000000000000000465507346545000022633 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1739 - "Char.intToDigit: not a digit" in darcs changes ## ## Copyright (C) 2010 Reinier Lamers ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # TODO: get this working on Windows # Seems to be a real bug - darcs doesn't record a patch with the # right characters. abort_windows # First, try to see if character set is UTF-8. If we can't find out or if it # isn't, we skip this test. if ! which locale ; then echo "no locale command" exit 200 # skip test fi charmap=`locale charmap` if [ $? -ne 0 ]; then echo "couldn't determine locale character set" exit 200 # skip test fi if [ "$charmap" != "UTF-8" ]; then echo "locale character set is not UTF-8, skipping" exit 200 fi # we want escaping, otherwise output of non-ASCII characters is unreliable export DARCS_DONT_ESCAPE_ANYTHING=0 # note default changed, DARCS_DONT_ESCAPE_8BIT is no longer recognized export DARCS_ESCAPE_8BIT=1 export DARCS_DONT_ESCAPE_ISPRINT=0 rm -rf R mkdir R cd R darcs init echo garbelbolf > aargh darcs add aargh echo -e '\xe2\x80\x9e\x54\x61\x20\x4d\xc3\xa8\x72\x65\xe2\x80\x9d' > message.txt darcs record --logfile=message.txt -a > rec.txt darcs changes > log.txt cat log.txt grep '' log.txt grep '' log.txt grep '' log.txt # locale should not matter LC_ALL=C darcs changes > log.txt grep '' log.txt grep '' log.txt grep '' log.txt cd .. darcs-2.14.5/tests/issue1740-mv-dir.sh0000755000000000000000000000303607346545000015433 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1740 - darcs mv on directories should work after the fact ## ## Copyright (C) 2009 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R mkdir d echo 'Example content.' > d/f darcs record -lam 'Add d/f' mv d d2 darcs mv d d2 # oops, I meant to darcs mv that darcs what | grep "move ./d ./d2" darcs-2.14.5/tests/issue174_obliterate_before_a_tag.sh0000755000000000000000000000071107346545000021043 0ustar0000000000000000#!/usr/bin/env bash # issue174: behave better when we want to obliterate a patch that comes before a tag. . lib rm -rf temp1 mkdir temp1 cd temp1 darcs init # Setup: Create a patch, a tag and another patch. touch a.txt darcs add a.txt darcs record -am 'adding a' a.txt darcs tag "first tag"; touch b.txt darcs add b.txt darcs record --ignore-time -a -m 'adding b' b.txt darcs obliterate -p "adding a" -a > log not grep "no patch" log cd .. rm -rf temp1 darcs-2.14.5/tests/issue1756_moves_index.sh0000755000000000000000000000340107346545000016642 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1756 - moving files between directories breaks index ## ## Copyright (C) 2010 Petr Rockai ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R mkdir d e # Change the working tree. echo 'a' > d/a echo 'b' > d/b echo 'c' > e/c darcs record -lam '.' darcs mv d/a e/ darcs check --no-ignore-times cd .. rm -rf R darcs init --repo R cd R mkdir d e # Change the working tree. echo 'a' > d/a echo 'b' > e/b darcs record -lam '.' darcs mv d/a e/ darcs check --no-ignore-times cd .. rm -rf R darcs-2.14.5/tests/issue1763-pull-fails-on-non-ascii-filenames.sh0000755000000000000000000000456007346545000022546 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1763 - When you pull in a conflicting hunk ## patch to a file with a non-ASCII name, and then pull from the same ## repo again, darcs crashes. ## ## Copyright (C) 2010 Reinier Lamers ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # This test should work on Windows because the codepoints in the filename # are all <256. However an equivalent test with codepoints >=256 would # likely fail. # abort_windows rm -rf R S darcs init --repo R export LC_ALL=C function check_consistent_filename { count=`darcs changes -v | grep 'hunk .*\.lisp' | sed -e 's/.*hunk //' -e 's/.lisp.*//' | sort | uniq | wc -l` test $count -eq 1 } # Set up a repo with 3 patches to a non-ASCII-named file cd R touch kitöltés.lisp darcs rec -l -a -m "Add" echo hi >> kitöltés.lisp darcs record -a -m "First edit" cd .. rm -rf S S2 S3 darcs get R S darcs get R S2 darcs get R S3 cd R echo hi >> kitöltés.lisp darcs record -a -m "Second edit" cd .. # From another repo, pull the first two, edit, pull the third to get a # conflict, pull again to get the crash cd S echo hello >> kitöltés.lisp darcs record -a -m "My edit" darcs pull -a ../R darcs pull -a ../R check_consistent_filename cd .. # duplicates cd S2 echo hi >> kitöltés.lisp darcs record -a -m "My duplicate edit" darcs pull -a ../R darcs pull -a ../R check_consistent_filename cd .. darcs-2.14.5/tests/issue1825-remove-pending.sh0000755000000000000000000000304707346545000017162 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1825 - buggy pending when reverting a removed ## directory and file. ## ## Copyright (C) 2010 Ferenc Wagner ## Copyright (C) 2010 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R mkdir -p a echo foo >a/b darcs add -r a darcs rec -am "add a/b" rm -r a not darcs remove blahblah darcs revert -a a/b darcs-2.14.5/tests/issue183_mv_order.sh0000755000000000000000000000320307346545000016050 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue183 - mv and other patches should be in replayable ## order ## ## Copyright (C) 2010 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R touch f darcs add f darcs record -am 'Create f' mkdir d darcs add d darcs mv f d darcs record -am 'Create d and mv f in it' cat > expected << EOF A ./d/ ./f -> ./d/f EOF darcs changes -s -p 'Create d' | grep "d/" > log diff -q expected log cd .. darcs-2.14.5/tests/issue1845-paths-working-copy.sh0000755000000000000000000000315407346545000020011 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1845 - darcs wants file paths from root of working copy ## ## Copyright (C) 2010 Guillaume Hoffmann ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R mkdir subdir touch subdir/subfile darcs add subdir subdir/subfile darcs record -am"add subdir and subfile" cd subdir rm subfile darcs record subfile -am"delete file in subdirectory" # fails because darcs wants subdir/subfile darcs-2.14.5/tests/issue1857-pristine-conversion.sh0000755000000000000000000000300007346545000020255 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1857 - upgrading the pristine format should either ## work or have no effect) even it happens before a failing operation ## ## Copyright (C) 2010 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf minimal-darcs-2.4 tar zx < $TESTDATA/minimal-darcs-2_4.tgz cd minimal-darcs-2.4 darcs check darcs setpref test false echo 'hi' > README not darcs record -a -m argh --test darcs check cd .. darcs-2.14.5/tests/issue1860-incomplete-pristine.sh0000755000000000000000000000316507346545000020235 0ustar0000000000000000#!/usr/bin/env bash ## Copyright (C) 2010 Petr Rockai ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R mkdir tools darcs rec -lam "add tools" mkdir tools/cgi echo bar > tools/cgi/README darcs rec -lam "add cgi" darcs move tools contrib darcs rec -lam "rename tools/ to contrib/" rm -rf contrib/cgi darcs rec -lam "drop cgi" cd .. darcs get R S cd S darcs show pristine darcs unpull --last 2 -a darcs show pristine cd .. darcs-2.14.5/tests/issue1875-honor-no-set-default.sh0000755000000000000000000000314507346545000020221 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1875 - corner cases in which darcs may accidentally ## set default even though it's not supposed to ## ## Copyright (C) 2010 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. darcs get R S --no-set-default not find S/_darcs/prefs/defaultrepo rm -rf S darcs init --repo S cd S darcs push ../R --dry-run not grep '/R$' _darcs/prefs/defaultrepo darcs push ../R cd .. darcs-2.14.5/tests/issue1877_noisy_xml_output.sh0000755000000000000000000000352507346545000017776 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1877 - pull --dry-run --xml-output is noisy ## ## Copyright (C) 2010 Lele Gaifax ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. darcs init --repo S cd R echo 'Example content.' > foo darcs record -lam 'Add foo.' cd .. cd S # This does the right thing... at least until the second command is executed darcs pull --dry-run --xml-output 2>&1 ../R | not grep "Would pull" # This does not, never darcs pull --summary --dry-run --xml-output 2>&1 ../R | not grep "Would pull" # From now on, this fails too! darcs pull --dry-run --xml-output 2>&1 ../R | not grep "Would pull" cd .. darcs-2.14.5/tests/issue1879-same-patchinfo-uncommon.sh0000755000000000000000000000166307346545000021005 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1879 - we should at least notice that when a patch claims ## to have the same identity (patchinfo) as one of ours, then it should not ## depend on anything we don't have. ## ## Public domain - 2010 Eric Kow . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. darcs init --repo S cd R touch x1 darcs add x1 darcs record -am 'x1' darcs changes --context > ctx echo hello > f echo world > x1 darcs add f darcs record -am 'hello world' darcs send -a --context ctx -o foo.dpatch ../S cd .. cd S touch x2 darcs add x2 darcs record -am 'x2' darcs changes --context > ctx # create an evil wrong patch sed -e '/Context:/,$d' -e 's/x1/x2/g' ../R/foo.dpatch > foo.dpatch cat ctx >> foo.dpatch darcs apply foo.dpatch cd .. cd R not darcs pull -a ../S 2>&1 | tee log cd .. darcs-2.14.5/tests/issue1898-set-default-notification.sh0000755000000000000000000000407007346545000021153 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1898 - set-default mechanism ## ## Copyright (C) 2010 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R0 R1 R2 S # Another script may have left a mess. darcs init --repo R0 # Create our test repos. darcs get R0 R1 darcs get R0 R2 darcs get R0 S cd S # default to no-set-default darcs push ../R1 > log grep '/R0$' _darcs/prefs/defaultrepo # notification when using no-set-default grep "set-default" log # set-default works darcs push ../R1 --set-default > log grep '/R1$' _darcs/prefs/defaultrepo # no notification when already using --set-default not grep "set-default" log # no notification when already pushing to the default repo darcs push > log not grep "set-default" log # no notification when it's just the --remote-repo darcs push --remote-repo ../R1 > log not grep "set-default" log # but... notification still works in presence of remote-repo darcs push --remote-repo ../R1 ../R2 > log grep "set-default" log cd .. darcs-2.14.5/tests/issue1909-unrecord-O-misses-tag.sh0000755000000000000000000000063607346545000020336 0ustar0000000000000000#!/usr/bin/env bash ## issue1909: unrecord -O in tagged repo makes a busted bundle . lib rm -rf R mkdir R darcs init --repo R echo a > R/a darcs rec -lam a --repo R --ignore-times darcs tag -m T --repo R echo b > R/a darcs rec -lam b --repo R --ignore-times echo c > R/a darcs rec -lam c --repo R --ignore-times darcs unpull -p c -a --repo R -O --no-minimize cat c.dpatch grep '^\[b' c.dpatch grep TAG c.dpatch darcs-2.14.5/tests/issue1913-diffing.sh0000755000000000000000000000301007346545000015635 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1913 - test for directory diffing ## ## Copyright (C) 2010 Ian Lynagh ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R mkdir foo touch foo/foofile darcs rec -l -a -m "foo patch" mkdir bar touch bar/barfile rm -r foo darcs rec -l -a -m "bar patch" not darcs whatsnew -l cd .. darcs-2.14.5/tests/issue1922-obliterate-o-context.sh0000755000000000000000000000333507346545000020311 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1922 - obliterate -o does not give the right context ## ## Copyright (C) 2010 Florent Becker ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. rm -rf x mkdir x darcs init --repo x echo a > x/a darcs rec -lam a --repo x --ig echo b > x/a darcs rec -lam b --repo x --ig echo a > x/b darcs rec -lam a2 --repo x --ig echo b > x/b darcs rec -lam b2 --repo x --ig echo c > x/a darcs rec -lam c --repo x --ig rm -f foo.dpatch darcs unpull -a -o foo.dpatch --match 'name a2' --repo x --last 3 cat foo.dpatch darcs changes --context --repo x darcs apply foo.dpatch --repo xdarcs-2.14.5/tests/issue1928-file-dir-replace.sh0000755000000000000000000000277307346545000017360 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1928 - removing a file and adding a directory with the same name ## ## Copyright (C) 2010 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R touch foo darcs rec -l -a -m "foo file patch" rm foo mkdir foo darcs rec -l -a -m "foo dir patch" cd .. darcs-2.14.5/tests/issue1932-colon-breaks-add.sh0000755000000000000000000000536107346545000017350 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1932 - "darcs add -qr ." should not break on files with colons ## ## Copyright(C) 2010 Dmitry Astapov ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. abort_windows # Windows doesn't support ':' in filenames at all rm -rf R # Another script may have left a mess. mkdir -p R # Create our test repo. cd R darcs init darcs --version # Colons could be in repo names and in file name. # Colon in repo name is an indication of special case - remote repo. # Colon in the file could be there under unix and requires no special treatment. # remote repos are tested by tests/network/issue1932-remote.sh # All following files should not be added unless "--reserved-ok" is specified, # but should be added with "--reserved-ok" just fine mkdir funny touch funny/0401:19d2 touch funny/c:src touch funny/c:\\src touch funny/user@invalid:path touch funny/droundy@invalid: touch funny/invalid:path # Try to add those files. None should be added, darcs should not fail darcs add -qr funny darcs wh -l > log 2>&1 # Check that darcs didn't drop dead as 2.4.4 does [ -z "$(fgrep 'fromJust: Nothing' log)" ] # Check that no funny files were added [ -z "$(grep '^A \./funny/.' log)" ] # Now let's allow colons and add those files darcs add --reserved-ok -qr funny darcs wh -l > log 2>&1 # This should add all those files [ -n "$(grep '^A \./funny/0401:19d2' log)" ] [ -n "$(grep '^A \./funny/c:src' log)" ] [ -n "$(grep '^A \./funny/c:\\src' log)" ] [ -n "$(grep '^A \./funny/user@invalid:path' log)" ] [ -n "$(grep '^A \./funny/droundy@invalid:' log)" ] [ -n "$(grep '^A \./funny/invalid:path' log)" ] darcs-2.14.5/tests/issue194.sh0000755000000000000000000000115207346545000014156 0ustar0000000000000000. ./lib rm -rf temp1 temp2 mkdir temp1; cd temp1 ; darcs init ; cd .. darcs get temp1 temp2 cd temp2/ ; echo 'x' > _darcs/prefs/author ; cd .. cd temp1/ ; echo 'x' > _darcs/prefs/author ; cd .. cd temp1/ touch test darcs add test ; darcs record -a -m 'test' darcs mv test best ; darcs record -a -m 'test -> best' darcs mv best test ; darcs record -a -m 'best -> test' cd .. cd temp2/ touch test2 darcs add test2 ; darcs record -a -m 'test2' darcs mv test2 best ; darcs record -a -m 'test2 -> best' darcs mv best test2 ; darcs record -a -m 'best -> test2' darcs pull ../temp1/ -a cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/issue1951-add-outside-repo.sh0000755000000000000000000001053307346545000017406 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1951 - darcs should refuse adds from outside the ## current repository ## ## Copyright (C) 2010 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R R2 R3 R4 R5 R6 R7 R8 R9 R10 darcs init --repo R # Create our test repos. darcs init --repo R2 darcs init --repo R3 darcs init --repo R4 darcs init --repo R5 darcs init --repo R6 darcs init --repo R7 darcs init --repo R8 darcs init --repo R9 darcs init --repo R10 # test if adding files outside the repository fails OUTSIDE=`pwd` cd R echo 'Example content.' > f echo 'Bad' > ../junk-for-issue1951 darcs add f not darcs add ../junk-for-issue1951 not darcs add $OUTSIDE/junk-for-issue1951 darcs whatsnew > log not grep junk-for-issue1951 log cd .. # test adding a file that: # * is in a subdirectory of the repository root # * is referred to with a path relative to the cwd, when the cwd is the # directory that the file is in cd R2 mkdir subdir cd subdir touch f darcs add f darcs whatsnew > log grep 'subdir/f' log cd ../.. # same as above, but now the relative path is valid both from the cwd and from # the repository root. Darcs should add the file in the cwd, not the one in the # repository root cd R3 touch f mkdir subdir cd subdir touch f darcs add f darcs whatsnew > log grep 'subdir/f' log cd ../.. # now test that adding fails on a file that # * is in the repository root # * is referred to with a path relative to the repository root, when the cwd is # not the repository root cd R4 touch myfilename mkdir subdir cd subdir not darcs add myfilename cd ../.. # test adding a file by relative path from the repo root, when the cwd is # outside the repo # It may seem counterintuitive that this succeeds and the cases above and below # do not, but that's the way it is. We use this feature ourselves in our test # suite. touch R5/myfilename darcs add --repo R5 myfilename darcs whatsnew --repo R5 > log grep 'myfilename' log not grep '\.\./myfilename' log # The case below makes the R4 case (of using a repo-root-relative path in a # subdir of the repo) look even more like the R5 case (of using a # repo-root-relative path outside the repo) by usign the --repo flag. It still # failed on darcs 2.4. cd R6 touch myfilename mkdir subdir cd subdir not darcs add --repo .. myfilename cd ../.. # Test adding a file by relative path from the repo root, when the cwd is # outside the repo, and the relative path also exists from the cwd touch myfilename touch R7/myfilename darcs add --repo R7 myfilename darcs whatsnew --repo R7 > log grep 'myfilename' log not grep '\.\.myfilename' log # Like the R4 case: try to use a path relative to the repo root from a cwd that # is a subdir of the repo root. In this case the path relative to the repo root # also includes a directory however. cd R8 mkdir subdir1 mkdir subdir2 touch subdir2/myfilename cd subdir1 not darcs add subdir2/myfilename cd ../.. # Try adding a non-repository file using a non-existent repo subdirectory name # followed by two ..'s touch myfilename cd R9 not darcs add nonexistentsubdir/../../myfilename cd .. # Try adding a non-repository file using an existing repo subdirectory name # followed by two ..'s touch myfilename cd R10 mkdir subdir not darcs add subdir/../../myfilename cd .. darcs-2.14.5/tests/issue1978.sh0000755000000000000000000000051007346545000014246 0ustar0000000000000000#!/usr/bin/env bash . lib mkdir future cd future darcs init touch titi darcs add titi darcs record -am titi cat > _darcs/format < f darcs add f darcs record -am 'Hello darcs.' # $PRISTINE_DIR_AFTER_RECORD should looks like: # 34e7e68e2ba4d79facc7ddffdab700608d4abceebbc8ff98d77479b8a5127820 # a8c49fa16eaed0a0a601834c98132a32c24f078e58fcba4d9e036fadb92ca91d # e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 # The third file represents the empty working copy and is no longer # needed. Therefore 'optimize' must remove it. PRISTINE_DIR_AFTER_RECORD=$(ls -1 $PRISTINE_DIR) EXPECTED_PRISTINE_AFTER_OPTIMIZE=`comm -13 <(echo "$PRISTINE_DIR_AFTER_INIT") \ <(echo "$PRISTINE_DIR_AFTER_RECORD")` darcs optimize clean PRISTINE_DIR_AFTER_OPTIMIZE=$(ls -1 $PRISTINE_DIR) [ "$PRISTINE_DIR_AFTER_OPTIMIZE" == "$EXPECTED_PRISTINE_AFTER_OPTIMIZE" ] cd .. rm -rf Rdarcs-2.14.5/tests/issue2012_send_output_no_address.sh0000755000000000000000000000315107346545000021060 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2012 - darcs send -o shall not print a "will be sent ## to" line ## ## Copyright (C) 2010 Gabriel Kerneis ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib DARCS_EDITOR=echo export DARCS_EDITOR mkdir temp1 temp2 cd temp2 darcs init echo "default@email" > _darcs/prefs/email cd .. cd temp1 darcs init touch foo bar darcs add foo bar darcs record -a -m add_foo_bar -A x darcs send -a -o test.patch ../temp2 2>&1 | not grep "Patch bundle will be sent to: default@email" darcs send -a -O ../temp2 | not grep "Patch bundle will be sent to: default@email" cd .. darcs-2.14.5/tests/issue2013_send_to_context.sh0000755000000000000000000000356507346545000017517 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2013 - darcs send --context --to shall not ask email address ## ## Copyright (C) 2010 Gabriel Kerneis ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib DARCS_EDITOR=echo export DARCS_EDITOR mkdir temp2 cd temp2 darcs init echo foo > a darcs record -alm add_a -A x # setup test cd .. darcs get temp2 temp1 cd temp1 darcs changes --context > context touch foo bar darcs add foo bar darcs record -alm add_foo_bar -A x # Test that --to works with send --context darcs send --mail --author=me -a --to=random@random --sendmail-command='grep "^To: random@random$" %<' --context context # Test that a default preference will NOT be used when no --to value is specified echo "default@email" > ../temp2/_darcs/prefs/email not darcs send --mail --author=me -a --sendmail-command='grep "^To: default@email$" %<' --context context cd .. darcs-2.14.5/tests/issue2035-malicious-subpath.sh0000755000000000000000000000244607346545000017670 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2035 - malicious subpaths ## ## Copyright (C) 2010 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. gunzip -c $TESTDATA/badrepo.tgz | tar xf - not darcs get badrepo darcs-2.14.5/tests/issue2041_dont_add_symlinks.sh0000755000000000000000000000411407346545000020015 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1645 - Since Darcs does not version-contol symlinks, ## it should reject them when a user is trying to 'darcs add' them. ## Thist must hold for both file and directory symlinks. ## ## Copyright (C) 2011 Alexey Levan ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repo. darcs --version cd R unset pwd # Since this test is pretty much linux-specific, hspwd.hs is not needed abort_windows # and skip if we are on win32... # test for file touch test-file ln -s ./test-file ./test-file-link1 # relative symlink ln -s "`pwd`"/test-file ./test-file-link2 # absolute symlink not darcs add test-file-link1 # darcs must fail to add symlinks not darcs add test-file-link2 # test for directory mkdir test-dir ln -s ./test-dir ./test-dir-link1 ln -s "`pwd`"/test-dir ./test-dir-link2 not darcs add test-dir-link1 not darcs add test-dir-link2 darcs-2.14.5/tests/issue2049-dir-case-change.sh0000755000000000000000000000321507346545000017151 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2049 - adding files inside a directory ## that's had a case change. ## ## This is not the exact failure reported in issue2049, ## but was reported by another user on IRC around the ## same time, and is closely related. ## ## Copyright (C) 2011 Sven Strittmatter, Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R darcs init --repo R # Create our test repos. cd R mkdir foo touch foo/bar darcs add foo -r # two stage case change so it works on Windows mv foo fox mv fox foO touch foO/bar2 not darcs add foO/bar2 darcs-2.14.5/tests/issue2049-file-in-boring-dir.sh0000755000000000000000000000257107346545000017620 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2049 - adding files inside a boring directory ## ## Copyright (C) 2011 Iago Abal, Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R darcs init --repo R # Create our test repos. cd R mkdir foo~ touch foo~/a.txt not darcs add foo~/a.txt darcs-2.14.5/tests/issue2066_add_and_remove.sh0000755000000000000000000000277407346545000017260 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2066 - darcs record fails when deleted file and added file are specified on the command line ## ## Copyright (C) 2011 David Caldwell ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init echo a > a darcs add a darcs record --all -m "a" rm -f a echo b > b darcs add b darcs record --all -m "-a+b" a b darcs changes -v | grep 'rmfile ./a' # the remove doesn't get recorded even though we told it to. cd .. darcs-2.14.5/tests/issue2076-move_into_dir.sh0000755000000000000000000000265507346545000017103 0ustar0000000000000000#!/usr/bin/env bash ## Copyright (C) 2011 Lennart Kolmodin ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo issue2076 cd issue2076 touch file1 darcs record -lam 'file1' mkdir dir1 mv file1 dir1 not darcs mv file1 dir1 # we require dir1 to be added first darcs add dir1 darcs mv file1 dir1 darcs whatsnew darcs-2.14.5/tests/issue2086-index-permissions.sh0000755000000000000000000000320007346545000017712 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2086 - _darcs/index permissions are not preserved ## ## Copyright (C) 2011 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. abort_windows # umasks don't really work there cd R echo 'Example content.' > f darcs record -lam 'Add f' --umask 022 ls -l _darcs/index | grep '^.rw..--...' chmod g+w _darcs/index ls -l _darcs/index | grep '^.rw.rw....' echo 'Example content 2.' > f darcs record -lam 'Tweak f' --umask 002 ls -l _darcs/index | grep '^.rw.rw....' cd .. darcs-2.14.5/tests/issue2125-always-warn-forced-replace.sh0000755000000000000000000000467607346545000021364 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2125 - darcs should not warn about forced replaces, if nothing ## needed to be forced. ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R cd R echo -e 'first line of file\nsecond line of file' > file darcs rec -alm 'Add file' # No occurences of 'entry' - shouldn't warn. darcs replace line entry file | not grep surprised # We have an occurrence of 'second' - should fail, but not change anything (no # --force) noForce=$(darcs replace first second file) echo "$noForce" | grep 'Skipping file' echo "$noForce" | not grep 'surprised' # Make sure nothing changed... whatsnew=$(darcs wh) echo "$whatsnew" | grep 'replace \./file \[A-Za-z_0-9\] line entry' [[ $(echo "$whatsnew" | wc -l) -eq 1 ]] force=$(darcs replace --force first second file) echo "$force" | grep 'surprised' darcs wh ! read -r -d '' EXPECTED <<'EOF' hunk ./file 2 -second line of file +first line of file replace ./file [A-Za-z_0-9] first second replace ./file [A-Za-z_0-9] line entry EOF echo "$EXPECTED" > expected_whatsnew.txt darcs wh > actual_whatsnew.txt # Ensure we have the right changes in working/pending. diff expected_whatsnew.txt actual_whatsnew.txt darcs rev -a # Test that unrecorded changes require --force, too. echo 'third line of file' >> file workingChangeNoForce=$(darcs replace second third file) echo "$workingChangeNoForce" | grep 'Skipping file' darcs-2.14.5/tests/issue2136-log_created_as_for_multiple_files.sh0000755000000000000000000000513707346545000023137 0ustar0000000000000000#!/usr/bin/env bash ## Ensure log --xml reports correct original filenames for multiple files. ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R cd R mkdir tldir touch tldir/f1 darcs rec -alm 'Add tldir/f1' echo foo >> tldir/f1 darcs rec -am 'Modify tldir/f1' darcs move tldir/f1 tldir/f2 darcs rec -am 'Move tldir/f1 -> tldir/f2' touch f3 darcs rec -alm 'Add f3' darcs move f3 f4 darcs rec -am 'Move f3 -> f4' darcs move f4 f5 darcs rec -am 'Move f4 -> f5' touch f6 darcs rec -alm 'Add non-changing file f6' mkdir tldir/d1 darcs rec -alm 'Add tldir/d1' darcs move tldir/d1 tldir/d2 darcs rec -am 'Move tldir/d1 -> tldir/d2' mkdir d3 darcs rec -alm 'Add d3' darcs move d3 d4 darcs rec -am 'Move d3 -> d4' darcs move d4 d5 darcs rec -am 'Move d4 -> d5' # Ensure all original names are reported, both forwards, and reversed. xmlLog=$(darcs log --xml tldir/f2 f5 tldir/d2 d5 f6) xmlLogRev=$(darcs log --reverse --xml tldir/f2 f5 tldir/d2 d5 f6) # xmlLog needs to be quoted everywhere, otherwise this hack to retrieve the # 2 following lines won't work. checkRename () { echo "$1" | grep "" -C2 | tail -1 | grep "$4" } checkInXML () { checkRename "$1" "d5" "d3" "Add d3" checkRename "$1" "f5" "f3" "Add f3" checkRename "$1" "tldir/d2" "tldir/d1" "Add tldir/d1" checkRename "$1" "tldir/f2" "tldir/f1" "Add tldir/f1" } checkInXML "$xmlLog" checkInXML "$xmlLogRev" # But don't mention unchanged files. echo "$xmlLog" | not grep "]*'\./f6'" darcs-2.14.5/tests/issue2153-allow-skipping-backwards-through-depended_upon-patches.sh0000755000000000000000000000117007346545000027042 0ustar0000000000000000#!/usr/bin/env bash # Testing amend . lib rm -rf temp1 # set up the repository mkdir temp1 cd temp1 darcs init cd .. # do some work here cd temp1 touch foo darcs add foo echo -e 'line1\nline2\nline3' > foo darcs record -a -m add_lines echo -e 'line1ch\nline2\nline3' > foo darcs record -a -m changedline1 echo -e 'line1ch\nline2changed\nline3' > foo darcs record -a -m changed_line2 echo -e 'line1ch\nline2changedagain\nline3' > foo darcs record -a -m changed_line2again echo successmarker >> foo echo jkya | darcs amend echo FOOOOOO darcs changes -v --patch "changed_line2again"|grep successmarker cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/issue2160_wrong_line_number_when_appending_empty_line.sh0000755000000000000000000000071007346545000025316 0ustar0000000000000000# Off-by-one error when reporting patches that append an empty line to a file. # An affected darcs would report 'hunk ./f 3' in the provided tests. . lib darcs init R cd R echo 'first line' > f darcs record -lam 'first line' echo '' >> f darcs whatsnew > wh darcs record -am 'appended empty line' darcs log -v --last=1 > log darcs annotate f > ann # these currently all fail: grep 'hunk ./f 2' wh grep 'hunk ./f 2' log not grep unknown ann grep '#2' ann darcs-2.14.5/tests/issue2200-darcs-replace-no-paths.sh0000755000000000000000000000272207346545000020462 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2200 - darcs should warn if no paths are given to replace ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R cd R touch file darcs rec -alm 'Add file' # Missing tokens not darcs replace not darcs replace foo # No files to replace in not darcs replace foo bar &> output.txt grep 'You need to supply a list of files to replace in!' output.txt darcs-2.14.5/tests/issue2204-send-mail.sh0000755000000000000000000000376407346545000016112 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2204 - darcs send --mail vs --output ## ## Copyright (C) 2012 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. # copied from issue2186 # Create a script that will be used instead of sendmail. It simply saves its # input to file "message". cat < dummy-sendmail.hs import System.IO main = hGetContents stdin >>= writeFile "message" FAKE ghc -o dummy-sendmail --make dummy-sendmail.hs cd R echo 'foo@example.com' > _darcs/prefs/email cd .. darcs get R S cd S echo 'send sendmail-command ../dummy-sendmail' > _darcs/prefs/defaults echo 'Example content.' > f darcs add f darcs record -lam p # no options (should generate a bundle) darcs send -a [ ! -e message ] [ -e p.dpatch ] # just --mail darcs send -a --mail [ -e message ] rm message # both mail and output darcs send -a --mail -O [ ! -e message ] [ -e p.dpatch ] cd .. darcs-2.14.5/tests/issue2208-replace-fails-with-resolving-unrecorded-change.sh0000755000000000000000000000324307346545000025276 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2208 - darcs shouldn't fail to replace if unrecorded changes ## would make the replace succeed ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R cd R echo -e 'foo\nbar' > testing darcs rec -alm 'Add testing file' echo -e 'baz\nbar' > testing # Darcs will complain here, since we've not recorded the fact that we've # removed the occurrence of foo darcs replace bar foo testing | not grep Skipping cat < ../expected hunk ./testing 1 -foo +baz replace ./testing [A-Za-z_0-9] bar foo EOF darcs whatsnew > ../actual cd .. diff actual expected darcs-2.14.5/tests/issue2209-look_for_replaces.sh0000755000000000000000000001774707346545000017744 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2209 - Automatically detect replace patch. ## ## Copyright (C) 2013 Jose Neder ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib darcs init R cd R # simple full complete replace (record) echo "foo" > file darcs record -al -m "add file" echo "bar_longer" > file # replace by token of different length echo yy | darcs record --look-for-replaces -m "replace foo bar_longer file" darcs changes --last 1 -v 2>&1 | tail -n +4 > log cat > log.expected < file darcs record -al -m "add file" echo "bar" > file echo yyy | darcs amend-record --look-for-replaces darcs changes --last 1 -v 2>&1 | tail -n +4 | grep -v "^ {\| }$" > log cat > log.expected < file darcs record -al -m "add file" echo "bar" > file darcs whatsnew --look-for-replaces 2>&1 > log cat > log.expected < file darcs record -al -m "add file" echo "bar foo" > file echo yyy | darcs record --look-for-replaces -m "replace foo bar file" darcs changes --last 1 -v 2>&1 | tail -n +4 | grep -v "^ {\| }$" > log cat > log.expected < file darcs record -al -m "add file" echo "bar foo" > file echo yyyy | darcs amend-record --look-for-replaces darcs changes --last 1 -v 2>&1 | tail -n +4 | grep -v "^ {\| }$" > log cat > log.expected < file darcs record -al -m "add file" echo "bar foo" > file darcs whatsnew --look-for-replaces > log cat > log.expected < file < file <&1 | tail -n +4 | grep -v "^ {\| }$" > log cat > log.expected < file < file < file <&1 | tail -n +4 | grep -v "^ {\| }$" > log cat > log.expected < file < file <&1 > log cat > log.expected < file < file <&1 | tail -n +4 | grep -v "^ {\| }$" > log cat > log.expected < file < file <&1 | tail -n +4 | grep -v "^ {\| }$" > log cat > log.expected < file < file <&1 > log cat > log.expected < file < file <&1 > log cat > log.expected < file < file <&1 > log cat > log.expected < f echo 'This is golden content , super interesting content' >> f echo 'Example content' > g echo 'This is golden content , super interesting content' >> g darcs record -lam 'Add f, g' sed -i "s/content/matter/g" f sed -i "s/content/topic/g" g darcs whatsnew --look-for-replace | grep replace # replace same token differently in different files is OK # 3 cd .. darcs init T cd T echo 'Example content' > f echo 'This is golden content , super interesting content' >> f cp f g cp f e darcs record -lam 'Add e, f, g' # change the file in the middle echo 'Example issue' > f echo 'This is golden matter , super interesting matter' >> f # create inconsistent replace in f sed -i "s/content/stuff/g" e # consistent replace in e sed -i "s/content/topic/g" g # consistent replace in g darcs whatsnew --look-for-replace > out grep "^replace ./e" out # 1 replace in e not grep "^replace ./f" out # 0 replace in f grep "^replace ./g" out # 1 replace in g darcs-2.14.5/tests/issue2212-add-changes-pending-for-other-files.sh0000755000000000000000000000325707346545000023020 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2212 - darcs updates pending when add is called for a distinct ## file. ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R cd R touch a b darcs add a darcs rec -am 'Add a' rm a darcs add b # Darcs shouldn't have updated anything to do with (despite the fact that it # has indeed been deleted.) cat _darcs/patches/pending | not grep 'rmfile \./a' # The same should be true for other commands that have to recompute pending # from the working directory darcs revert -a touch b darcs add b rm a darcs revert b -a cat _darcs/patches/pending | not grep 'rmfile \./a' darcs-2.14.5/tests/issue2225-obliterate-not-in.sh0000755000000000000000000000342107346545000017566 0ustar0000000000000000#!/usr/bin/env bash ## ## Obliterate patches not in other repo(s) ## ## Copyright (C) 2014 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib for i in {1..4} do rm -rf R$i darcs init --repo R$i done recFile() { touch $1 darcs rec -lam "add $1" } cd R1 recFile file1 recFile file2 recFile file3 recFile file4 recFile file5 # Should fail, we haven't specified a repo, and we don't have a default repo not darcs ob -a --not-in-remote darcs push -a -p file2 --set-default ../R2 darcs push -a -p file3 ../R3 darcs push -a -p file4 ../R4 darcs ob -a --not-in-remote=../R3 --not-in-remote=../R4 --not-in-remote # Confirm that the only patches that were deleted were file1 and file5 [[ -f file2 && -f file3 && -f file4 && ! -f file1 && ! -f file5 ]] darcs-2.14.5/tests/issue2227-rebase-amend-record.sh0000755000000000000000000000273607346545000020043 0ustar0000000000000000#!/bin/sh -e ## ## amend-record needs to pull the rebase patch to the head ## of the repo so that 'withManualRebaseUpdate' can work ## ## Copyright (C) 2013 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init touch file1 darcs rec -lam "add file1" touch file2 darcs rec -lam "add file2" echo ydy | darcs rebase suspend touch file3 darcs rec -lam "add file3" echo 'contents' > file1 echo nyyy | darcs amend darcs-2.14.5/tests/issue2243-unknown-patch-annotating-empty-first-line.sh0000755000000000000000000000251607346545000024400 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2243 - annotating a file with a blank first gives an "unknown" ## patch. ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib darcs init --repo R cd R echo -e "\nline2" > file darcs rec -alm 'Add file' darcs annotate file | not grep unknown darcs-2.14.5/tests/issue2248-rebase-zero-suspended.sh0000755000000000000000000000304107346545000020443 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2248 - can get into state of "0 suspended patches" ## ## Copyright (C) 2012 Owen Stephens, Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R cd R touch foo darcs rec -lam "add foo" echo foo > foo darcs rec -am "change foo" echo bar > foo echo yd | not darcs rebase suspend darcs whatsnew | not grep suspended echo d | darcs rebase suspend darcs whatsnew | not grep suspended echo q | darcs rebase suspend darcs whatsnew | not grep suspended darcs-2.14.5/tests/issue2262-display_of_meta_data.sh0000755000000000000000000000021207346545000020356 0ustar0000000000000000#!/usr/bin/env bash . lib abort_windows # issue2590 darcs init R cd R touch äöüßÄÖÜ darcs whatsnew -l | grep './äöüßÄÖÜ' darcs-2.14.5/tests/issue2270-log-interactive-only-to-files.sh0000755000000000000000000001025707346545000022032 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2270 - ## darcs log should only show changes to relevant files ## ## Copyright (C) 2013 Sebastian Fischer ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R mkdir R cd R darcs init echo irrelevant > irrelevant darcs add irrelevant darcs record -am "recorded irrelevant file" echo relevant-initial > relevant echo other > other darcs add relevant other darcs record -am "recorded relevant and other file" # --interactive --only-to-files should only show relevant (echo y | darcs log -i --only-to-files relevant > out) || true cat out not grep "addfile ./irrelevant" out grep "addfile ./relevant" out not grep "addfile ./other" out # --verbose --only-to-files should only show relevant (darcs log -v --only-to-files relevant > out) || true cat out not grep "addfile ./irrelevant" out grep "addfile ./relevant" out not grep "addfile ./other" out # --interactive should only show relevant and other (echo yy | darcs log -i relevant > out) || true cat out not grep "addfile ./irrelevant" out grep "addfile ./relevant" out grep "addfile ./other" out # --verbose should only show relevant and other (darcs log -v relevant > out) || true cat out not grep "addfile ./irrelevant" out grep "addfile ./relevant" out grep "addfile ./other" out # --interactive --only-to-files should show old name of moved darcs move relevant renamed-relevant darcs record -am "renamed relevant file" (echo yy | darcs log -i --only-to-files renamed-relevant > out) || true cat out grep "addfile ./relevant" out not grep "addfile ./irrelevant" out not grep "addfile ./other" out # --verbose --only-to-files should show old name of moved (darcs log -v --only-to-files renamed-relevant > out) || true cat out grep "addfile ./relevant" out not grep "addfile ./irrelevant" out not grep "addfile ./other" out # --interactive should show old name of moved (echo yy | darcs log -i renamed-relevant > out) || true cat out grep "addfile ./relevant" out not grep "addfile ./irrelevant" out grep "addfile ./other" out # --verbose should show old name of moved (darcs log -v renamed-relevant > out) || true cat out grep "addfile ./relevant" out not grep "addfile ./irrelevant" out grep "addfile ./other" out # adding a new file called 'relevant' : # changes should now relate to that file and not to the original one echo relevant-new > relevant darcs add relevant echo other-new > other darcs record -am "recorded new add of relevant" (echo yy | darcs log -i --only-to-files relevant > out) || true cat out grep "addfile ./relevant" out grep 'relevant-new' out not grep 'other-new' out not grep 'relevant-initial' out (echo yy | darcs log -v --only-to-files relevant > out) || true cat out grep "addfile ./relevant" out grep 'relevant-new' out not grep 'other-new' out not grep 'relevant-initial' out (echo yy | darcs log -i relevant > out) || true cat out grep "addfile ./relevant" out grep 'relevant-new' out grep 'other-new' out not grep 'relevant-initial' out (echo yy | darcs log -v relevant > out) || true cat out grep "addfile ./relevant" out grep 'relevant-new' out grep 'other-new' out not grep 'relevant-initial' out cd .. rm -rf R darcs-2.14.5/tests/issue2271-disable-patch-index.sh0000755000000000000000000000302407346545000020037 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2271 - --disable-patch-index should really work ## ## Copyright (C) 2013 Mark Stosberg ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R touch t.txt darcs add t.txt darcs record -am 'initial record' t.txt darcs optimize enable-patch-index chmod -w _darcs/patch_index not darcs optimize disable-patch-index 2>&1 | grep 'Could not delete patch index' cd ../ darcs-2.14.5/tests/issue2286-metadata-encoding.sh0000755000000000000000000000311707346545000017607 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2286 - darcs changes fails when reading non-UTF8 encoded ## metadata ## ## Copyright (C) 2012 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib gunzip -c $TESTDATA/metadata-encoding.tgz | tar xf - cd metadata-encoding darcs log -v switch_to_utf8_locale darcs log -v darcs clone . ../utf8-clone darcs log -v --repodir ../utf8-clone switch_to_latin9_locale darcs log -v darcs clone . ../latin-clone darcs log -v --repodir ../latin-clone LC_ALL=C darcs log -v darcs clone . ../c-clone darcs log -v --repodir ../c-clone darcs-2.14.5/tests/issue2287_obliterate_overwrite.sh0000755000000000000000000000374407346545000020574 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2287 - Obliterate overwrites the existing file ## when the parameter -O is used. ## ## Copyright (C) YEAR AUTHOR ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R echo 'Example content 1.' > f darcs record -lam 'Add f.' echo 'Example content for obliterate.' >> f darcs record -am 'content obliterate' # Create 'existing useful dpatch' p='content-obliterate.dpatch' p1='content-obliterate_0.dpatch' touch $p # This command should finish with error, since file already exists. not darcs obliterate -a -p 'content obliterate' -o $p if [ ! -z "$(cat $p)" ]; then exit 2 fi # This command create autogenerate non-conflict file darcs obliterate -a -p 'content obliterate' -O # Assert file was not overwritten if [ ! -z "$(cat $p)" ]; then exit 2 fi # Assert new file was created if [ ! -f $p1 ]; then exit 2 fi darcs-2.14.5/tests/issue2311_posthook_for_get_should_run_in_created_repo.sh0000755000000000000000000000330407346545000025327 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2311 - ## posthook for 'get' should run in created repo ## ## Copyright (C) 2013 Sebastian Fischer ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf repos mkdir repos cd repos mkdir origin cd origin darcs init cd .. # The output of the posthook `pwd` should include "branch" # if "branch" is passed as repo name darcs get origin branch --posthook=pwd > out head -n 1 out | grep branch # The output of the posthook `pwd` should include "origin_0" # if no name for the created repo is passed darcs get origin --posthook=pwd > out head -n 1 out | grep origin_0 cd .. rm -rf repos darcs-2.14.5/tests/issue2312_posthooks_for_record_and_amend-record_should_receive_DARCS_PATCHES.sh0000755000000000000000000000602307346545000031154 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2312 - ## posthooks for 'record' and 'amend-record' should receive DARCS_PATCHES ## ## Copyright (C) 2013 Sebastian Fischer ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. # passing environment variables to posthooks isn't supported at # all in Windows abort_windows # even though the test doesn't work on Windows at the moment, # might as well future proof it by using a Haskell program instead # of a script for the post hook. cat < echo_darcs_patches.hs # create a posthoook that echos $DARCS_PATCHES import System.Environment main = do [outFile] <- getArgs darcsPatches <- getEnv "DARCS_PATCHES" writeFile outFile (darcsPatches ++ "\n") FAKE ghc --make -o echo_darcs_patches echo_darcs_patches.hs ECHO_DARCS_PATCHES=`pwd`/echo_darcs_patches rm -rf R mkdir R cd R darcs init touch some.file darcs add some.file # posthook for darcs record should receive DARCS_PATCHES with correct change darcs record -am msg1 --posthook="$ECHO_DARCS_PATCHES out" cat out grep msg1 out grep "A ./some.file" out # posthook for amend-record should receive DARCS_PATCHES with correct change echo contents > some.file echo y | darcs amend-record -a --posthook="$ECHO_DARCS_PATCHES out" cat out grep msg1 out grep "A ./some.file" out # newly added file should appear after amend echo more contents >> some.file touch new.file darcs record -am msg2 --posthook="$ECHO_DARCS_PATCHES out" cat out grep msg2 out grep "M ./some.file" out not grep "A ./new.file" out darcs add new.file echo y | darcs amend-record -a --posthook="$ECHO_DARCS_PATCHES out" cat out not grep msg1 out grep msg2 out grep "M ./some.file" out grep "A ./new.file" out # no change should appear if it is not recorded echo > out # clear out file, in case posthook is not called echo contents >> new.file echo ny | darcs record -m msg3 --posthook="$ECHO_DARCS_PATCHES out" not grep msg1 out not grep msg2 out not grep msg3 out not grep "M ./new.file" out cd .. rm -rf R darcs-2.14.5/tests/issue2313-trailing-newlines-stack-overflow.sh0000755000000000000000000000054407346545000022632 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp && mkdir temp cd temp darcs init echo "one line" > test_file.txt for i in {1..18} do cat test_file.txt test_file.txt > test_file2.txt && mv -f test_file2.txt test_file.txt done echo -n "last line without newline" >> test_file.txt darcs add test_file.txt darcs wh -l | grep "A ./test_file.txt" cd .. && rm -rf tempdarcs-2.14.5/tests/issue2333.sh0000755000000000000000000000067107346545000014240 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2333 - . lib # Load some portability helpers. require_ghc 706 darcs init --repo R # Create our test repos. darcs init --repo S cd R echo 'Example content.' > f darcs record -lam 'Add f.' thedarcs=$(type -P darcs) PATH='' $thedarcs push ../S -a # Try to push patches between repos. cd .. darcs-2.14.5/tests/issue2343.sh0000755000000000000000000000423607346545000014242 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2343 - 'darcs amend-record does not record my change' ## ## Copyright (C) 2013 José Neder ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib rm -rf temp1 mkdir temp1 cd temp1 darcs init cat > file << FOO { foo(foovar); } FOO # The issue happens when the last line not common was a "boring" line. The diff # algorithm was wrongly checking one line above and therefore it wasn't working # right. darcs record -m 'add' --all --look-for-adds cat > file << FOO { foo(foovar2); } FOO # Here the last line in common is "}". The empty line between "foo(foovar;)"" # and "}" is checked and since it is a "boring" line the last line number is # incremented, but the line "foo(foovar2);" isn't so the last line number in # the "newfile" is not incremented and so it makes a bad diff later. # is important to make a different line from the top # "foo(foobar);" -> "foo(foovar2);" because if not it will only be an deleted # line and the algorithm will skip the check of boring lines. darcs wh >log 2>&1 cat > log.expected < d/f darcs add d/f darcs record -am'added d/f' --skip-long-comment darcs move d/f . darcs record -am'moved d/f to .' --skip-long-comment rmdir d darcs record -am'removed d' --skip-long-comment darcs move f d darcs record -am'moved f to d' --skip-long-comment darcs obliterate --last=3 --all darcs whatsnew -l darcs-2.14.5/tests/issue2380-rename-to-deleted-file.sh0000755000000000000000000000327007346545000020446 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2380 - darcs won't rename a file to a file that has been ## deleted in the working dir. ## ## Copyright (C) 2014 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE rm -rf R && darcs init --repo R . lib cd R echo foostuff > foo echo otherstuff > other darcs rec -alm 'Add foo and other' rm foo darcs mv other foo # foo should exist, with the correct contents, and other should not [[ -e foo && ! -e other && $( expected darcs wh > actual diff expected actual darcs rev -a [[ -e foo && -e other && $( $1 darcs unrecord --last 1 -a } function rmOutputFiles () { rm recoutput* expected* whoutput* } . lib darcs init --repo R cd R # foo is recorded as a file echo foo > foo darcs rec -alm 'Add foo' rm foo darcs wh # foo is now a dir in working, with a file within mkdir foo touch foo/bar darcs wh > whoutput1 cat << EOF > expected1 hunk ./foo 1 -foo rmfile ./foo EOF diff whoutput1 expected1 # Ensure recording everything isn't any different to asking whatsnew getRecordedChanges recoutput1 diff recoutput1 expected1 rmOutputFiles # To avoid the output file appearing in the output of wh -l whl=$(darcs wh -l) echo "$whl" > whoutput2 cat << EOF > expected2 R ./foo a ./foo/ a ./foo/bar EOF diff whoutput2 expected2 darcs add foo darcs wh > whoutput3 cat << EOF > expected3 hunk ./foo 1 -foo rmfile ./foo adddir ./foo EOF diff whoutput3 expected3 getRecordedChanges recoutput3 diff recoutput3 expected3 rmOutputFiles darcs add foo/bar darcs wh > whoutput4 cat << EOF > expected4 hunk ./foo 1 -foo rmfile ./foo adddir ./foo addfile ./foo/bar EOF diff whoutput4 expected4 getRecordedChanges recoutput4 diff recoutput4 expected4 # Make sure we can remove the directory, without modifying working darcs remove foo/bar darcs remove foo darcs add -r foo darcs wh > whoutput4a getRecordedChanges recoutput4a diff whoutput4a expected4 diff recoutput4a expected4 rmOutputFiles # Make sure foo is now recorded as a directory darcs rec -alm 'Make foo a dir' # Evil. Poor darcs, having to work all this out. We've made foo back into a # file in working rm -r foo touch foo darcs wh > whoutput5 cat << EOF > expected5 rmfile ./foo/bar rmdir ./foo EOF diff whoutput5 expected5 getRecordedChanges recoutput5 diff recoutput5 expected5 rmOutputFiles darcs rev -a mkdir bar darcs rec -alm 'Add bar dir' rmdir bar touch bar darcs wh > whoutput6 cat << EOF > expected6 rmdir ./bar EOF diff whoutput6 expected6 getRecordedChanges recoutput6 diff recoutput6 expected6 rmOutputFiles whl=$(darcs wh -l) echo "$whl" > whoutput7 cat << EOF > expected7 R ./bar/ a ./bar EOF diff whoutput7 expected7 darcs add bar darcs wh > whoutput8 cat << EOF > expected8 rmdir ./bar addfile ./bar EOF diff whoutput8 expected8 getRecordedChanges recoutput8 diff recoutput8 expected8 rmOutputFiles darcs-2.14.5/tests/issue2432-pull-reorder-commute.sh0000755000000000000000000000322307346545000020315 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2432 - pull --reorder fails to commute patches ## ## Copyright (C) 2015 G. Hoffmann ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R echo X > x darcs record -lam 'Add x with one line' darcs clone . ../S sed -i "1iNEW FIRST LINE" x darcs record -am 'insert line at beginning' cd ../S echo "NEW LAST LINE" >> x darcs record -am 'insert line at the end' darcs log -p "insert line at the end" --last 1 -v |grep "hunk ./x 2" # darcs pull --all darcs pull --all --reorder darcs check darcs-2.14.5/tests/issue2479-mv-list-files.sh0000755000000000000000000000057107346545000016743 0ustar0000000000000000#!/usr/bin/env bash ## Test for issueNNNN - Bad error message in 'darcs move' if the repo root dir (".") ## is given among multiple sources for the move. . lib # Load some portability helpers. mkdir R cd R darcs init echo "test" > b darcs add b darcs record -a -m 'added b' mkdir a not darcs move . ./b a 2>&1 | not grep -i bug darcs-2.14.5/tests/issue2480-display-unicode-in-patch-content.sh0000755000000000000000000000030607346545000022476 0ustar0000000000000000#!/usr/bin/env bash . lib darcs init R cd R echo 'äöüßÄÖÜ' > file darcs whatsnew -l --no-summary | grep '+äöüßÄÖÜ' darcs record -lam'added file' darcs log -v | grep '+äöüßÄÖÜ' darcs-2.14.5/tests/issue2494-output-of-record-with-file-arguments.sh0000755000000000000000000000502707346545000023355 0ustar0000000000000000#!/usr/bin/env bash # Load some portability helpers . lib echo added >> ../all_paths echo not-added >> ../all_paths echo recorded >> ../all_paths echo removed >> ../all_paths echo not-existing >> ../all_paths echo /not-repo-path >> ../all_paths check_report() { yes="$1" log="$2" pre="$3" shift shift shift paths="$@" for arg in "$@"; do grep $yes "$pre.\+$arg" "$log" done } check_report_yes() { check_report '' "$@" } check_report_no() { check_report '-v' "$@" } # Create and populate test repo darcs init --repo R cd R touch recorded removed darcs add recorded removed darcs record -am'two files' touch added not-added rm removed darcs add added # Now do the tests echo q | darcs record added not-added recorded removed not-existing /not-repo-path > ../record.out 2>&1 check_report_yes ../record.out 'non-repository' /not-repo-path check_report_no ../record.out 'non-repository' added not-added recorded removed not-existing check_report_yes ../record.out 'non-existing' not-added not-existing check_report_no ../record.out 'non-existing' added recorded removed /not-repo-path check_report_yes ../record.out 'not.\+in.\+repository' added check_report_no ../record.out 'not.\+in.\+repository' not-added recorded removed not-existing /not-repo-path check_report_yes ../record.out 'Recording' added recorded removed check_report_no ../record.out 'Recording' not-added not-existing /not-repo-path echo q | darcs record -l added not-added recorded removed not-existing /not-repo-path > ../record-l.out 2>&1 check_report_yes ../record-l.out 'non-repository' /not-repo-path check_report_no ../record-l.out 'non-repository' added not-added recorded removed not-existing check_report_yes ../record-l.out 'non-existing' not-existing check_report_no ../record-l.out 'non-existing' added not-added recorded removed /not-repo-path check_report_no ../record-l.out 'not.\+in.\+repository' added not-added recorded removed not-existing /not-repo-path check_report_yes ../record-l.out 'Recording' added not-added recorded removed check_report_no ../record-l.out 'Recording' not-existing /not-repo-path echo q | darcs record -l -q added not-added recorded removed not-existing /not-repo-path > ../record-l-q.stdout not grep 'paths' ../record-l-q.stdout check_report_no ../record-l-q.stdout 'Recording' added not-added recorded removed not-existing /not-repo-path echo q | darcs record -q -a -m'patchname' added not-added recorded removed not-existing /not-repo-path > ../record-q-a.stdout not grep '.' ../record-q-a.stdout darcs-2.14.5/tests/issue2496-output-of-whatsnew-with-file-arguments.sh0000755000000000000000000000433607346545000023743 0ustar0000000000000000#!/usr/bin/env bash # Load some portability helpers . lib echo added >> ../all_paths echo not-added >> ../all_paths echo recorded >> ../all_paths echo removed >> ../all_paths echo not-existing >> ../all_paths echo /not-repo-path >> ../all_paths check_report() { yes="$1" log="$2" pre="$3" shift shift shift paths="$@" for arg in "$@"; do grep $yes "$pre.\+$arg" "$log" done } check_report_yes() { check_report '' "$@" } check_report_no() { check_report '-v' "$@" } # Create and populate test repo darcs init --repo R cd R touch recorded removed darcs add recorded removed darcs record -am'two files' touch added not-added rm removed darcs add added # Now do the tests darcs whatsnew added not-added recorded removed not-existing /not-repo-path > ../whatsnew.out 2>&1 check_report_yes ../whatsnew.out 'non-repository' /not-repo-path check_report_no ../whatsnew.out 'non-repository' added not-added recorded removed not-existing check_report_yes ../whatsnew.out 'non-existing' not-added not-existing check_report_no ../whatsnew.out 'non-existing' added recorded removed /not-repo-path check_report_yes ../whatsnew.out "What's new" added recorded removed check_report_no ../whatsnew.out "What's new" not-added not-existing /not-repo-path darcs whatsnew -l added not-added recorded removed not-existing /not-repo-path > ../whatsnew-l.out 2>&1 check_report_yes ../whatsnew-l.out 'non-repository' /not-repo-path check_report_no ../whatsnew-l.out 'non-repository' added not-added recorded removed not-existing check_report_yes ../whatsnew-l.out 'non-existing' not-existing check_report_no ../whatsnew-l.out 'non-existing' added not-added recorded removed /not-repo-path check_report_no ../whatsnew-l.out 'not.\+in.\+repository' added not-added recorded removed not-existing /not-repo-path check_report_yes ../whatsnew-l.out "What's new" added not-added recorded removed check_report_no ../whatsnew-l.out "What's new" not-existing /not-repo-path darcs whatsnew -l -q added not-added recorded removed not-existing /not-repo-path > ../whatsnew-l-q.stdout not grep 'paths' ../whatsnew-l-q.stdout check_report_no ../whatsnew-l-q.stdout "What's new" added not-added recorded removed not-existing /not-repo-path darcs-2.14.5/tests/issue2512-multiple-authors-clobbered-in-global-conf.sh0000755000000000000000000000233307346545000024254 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2512 - Multiple authors in global config get overwritten . lib abort_windows # different directory names on Windows # helper function fail { echo "ERROR: $1" exit 1 } # add multiple author IDs to global preferences cat >"$HOME/.darcs/author" <<-EOF AUTHOR_1, this one will be chosen when prompted for an author AUTHOR_2, this one should still be there in the end EOF # create a repo rm -rf repo mkdir repo cd repo darcs init # make a change so that we have something to commit touch changed darcs add changed # darcs will find multiple authors in global preferences, # so darcs will ask for the author and we pick the first one darcs record -am 'testing' <<-EOF 1 EOF echo # check the configuration after the commit (primary test for this issue) if ! grep -q 'AUTHOR_2' "$HOME/.darcs/author"; then fail "'\$HOME/.darcs/author' with multiple authors was clobbered." fi # in addition, confirm that the author was properly added to the repository if ! [[ -f _darcs/prefs/author ]]; then fail "The author was not recorded in the repository." fi if ! grep -q 'AUTHOR_1' _darcs/prefs/author; then fail "An 'author' file was created in the repository, but does not contain the chosen author." fi darcs-2.14.5/tests/issue2526-whatsnew-boring.sh0000755000000000000000000000052107346545000017352 0ustar0000000000000000#!/usr/bin/env bash . lib # test that 'whatsnew -l --boring' actually lists boring files rm -rf R darcs init R cd R echo xxx > boring darcs setpref boringfile boring darcs record -lam'added boring and set as boringile' touch xxx darcs whatsnew -l --boring | grep xxx darcs whatsnew -l --boring | grep -v 'No changes' cd .. rm -rf R darcs-2.14.5/tests/issue2545_command-execution-via-ssh-uri.sh0000755000000000000000000000371607346545000022114 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2545 - Argument smuggling in SSH repository URLs ## Darcs allows (almost) arbitrary command execution via a crafted ssh URI. ## ## Copyright (C) 2017 Gian Piero Carrubba ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R DARCS_SCP=sftp darcs pull -a ssh://-oProxyCommand='touch FAIL' \ 2>/dev/null || true not ls FAIL >/dev/null DARCS_SCP=sftp darcs pull -a -- -oProxyCommand='touch FAIL':dir \ 2>/dev/null || true not ls FAIL >/dev/null # Executing the same tests with `clone' instead of `pull'. The results shoud # be the same, but better safe than sorry. DARCS_SCP=sftp darcs clone ssh://-oProxyCommand='touch FAIL' S \ 2>/dev/null || true not ls FAIL >/dev/null DARCS_SCP=sftp darcs clone -- -oProxyCommand='touch FAIL':dir T \ 2>/dev/null || true not ls FAIL >/dev/null cd .. darcs-2.14.5/tests/issue2567-darcs-whatsnew-unified.sh0000755000000000000000000000057007346545000020620 0ustar0000000000000000#!/usr/bin/env bash # check that darcs whatsnew --unified outputs correct context lines . lib cat > before << EOF 1 2 3 4 5 EOF cat > after << EOF 1 3 4a 4b 5 EOF cat > exp << EOF hunk ./file 2 1 -2 3 hunk ./file 3 -4 +4a +4b 5 EOF darcs init R cd R cp ../before file darcs record -lam 'add file' cp ../after file darcs whatsnew --unified > ../got diff ../exp ../got darcs-2.14.5/tests/issue257.sh0000755000000000000000000000052707346545000014163 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf tempc mkdir tempc cd tempc darcs init echo foo > foo.c darcs rec -Ax -alm init cd .. rm -rf temps darcs get tempc temps cd temps echo server >> foo.c darcs rec -Ax -alm server cd ../tempc echo client >> foo.c darcs rec -Ax -alm client if darcs push -a ../temps; then false fi cd .. rm -rf tempc temps darcs-2.14.5/tests/issue2575-revert_during_rebase.sh0000755000000000000000000000027007346545000020441 0ustar0000000000000000. lib darcs init R cd R touch f darcs record -l f -am'add f' darcs rebase suspend -a --last 1 echo bla > g darcs add g darcs revert -a not grep 'DO NOT TOUCH' _darcs/patches/unrevert darcs-2.14.5/tests/issue2581-rebase_pull_reorder_updates_format.sh0000755000000000000000000000040007346545000023345 0ustar0000000000000000. lib darcs init R cd R touch f darcs record -l f -am "add f in R" cd .. darcs init S cd S touch f darcs record -l f -am "add f in S" # first y is for the "repos are unrelated" prompt echo yaa | darcs rebase pull ../R --reorder-patches darcs rebase log darcs-2.14.5/tests/issue27.sh0000755000000000000000000000130107346545000014065 0ustar0000000000000000#!/bin/sh . ./lib rm -rf temp1 temp2 mkdir temp1 temp2 cd temp1 darcs init echo first > a darcs add a darcs record --pipe --all --name=first < b darcs add b darcs record --pipe --all --name=first <> a darcs record --pipe --all --name=second <> b darcs record --pipe --all --name=second < f darcs add f darcs record -am 00 cd .. for r in a b c d; do darcs get temp1 temp_$r cd temp_$r; echo $r > f darcs record -am "patch:$r"; cd .. done cd temp_d darcs pull -a ../temp_a darcs pull -a ../temp_b darcs pull -a ../temp_c cd .. cd temp_c darcs pull -a ../temp_a darcs pull -a ../temp_b echo rc > f darcs record -a -m rc cd .. cd temp_d darcs pull -a ../temp_c > log not grep -i "no remote" log not grep -i get_extra log cd .. darcs-2.14.5/tests/issue381.sh0000755000000000000000000000202707346545000014156 0ustar0000000000000000#!/usr/bin/env bash . ./lib # for issue381: "darcs send -o message --edit-description doesn't work" DARCS_EDITOR=echo export DARCS_EDITOR rm -rf temp1 temp2 mkdir temp1 temp2 cd temp2 darcs init cd .. cd temp1 darcs init echo Hello world > foobar darcs add foobar darcs record -a -A me -m add_foobar # Test that editor is called when --output is used with --edit-description echo This is a note > note cat > editor <> \$1 cat \$1-temp >> \$1 echo >> \$1 echo finished editing >> \$1 echo I am done running the editor EOF chmod +x editor DARCS_EDITOR='bash editor' darcs send --author=me -a --output=bundle --edit-description ../temp2 echo === beginning of bundle > === cat bundle echo === end of bundle > === grep ' add_foobar' bundle grep 'finished editing' bundle IFS=' ' darcs send --author=me -a --subject="it works" --to user@place.org --sendmail-command='grep "^Subject: it works$" %<' ../temp2 cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/issue436.sh0000755000000000000000000000072007346545000014155 0ustar0000000000000000#!/usr/bin/env bash . ./lib # this test fails in the darcs 1 format skip-formats darcs-1 mkdir temp1 cd temp1 darcs init echo A > f darcs add f darcs record --ignore-times -a -m A cd .. darcs get temp1 temp2 cd temp1 echo C > f darcs record --ignore-times -a -m A-C cd .. cd temp2 echo B > f darcs record --ignore-times -a -m A-B echo A > f darcs record --ignore-times -a -m B-A (darcs push -a || :) 2> push-result grep "Refusing to apply" push-result cd .. darcs-2.14.5/tests/issue458.sh0000755000000000000000000000132007346545000014156 0ustar0000000000000000#!/usr/bin/env bash ### http://bugs.darcs.net/issue458 ### darcs get --set-scripts-executable ignores umask . ./lib ## Windows doesn't support proper permissions. if echo $OS | grep -i windows; then echo Windows does not support posix permissions exit 0 fi rm -rf temp mkdir temp cd temp mkdir repo1 darcs initialize --repodir repo1 printf >repo1/x '#!/bin/sh\ntrue' # make a shebang'd script darcs record --repodir repo1 -lam x x umask 077 # DENY ALL access to group, all darcs get --set-scripts-executable repo1 repo2 # remove trailing-dot for xattr ls -l repo2/x | cut -f 1 -d\ | sed -e "s/\.$//" > mode echo -rwx------ > desired-mode diff -u desired-mode mode cd .. rm -rf temp darcs-2.14.5/tests/issue494-pending-sort.sh0000755000000000000000000000262607346545000016577 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue494: pending patch when files are renamed ## ## Copyright (C) 2007 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. mkdir R cd R darcs init echo abc > b darcs add b darcs record --all -m patch1 -A moi darcs mv b a echo def > a darcs record --all -m patch2 -A moi cd .. mkdir S cd S darcs init darcs pull --all ../R darcs whatsnew | grep 'No changes' darcs-2.14.5/tests/issue525_amend_duplicates.sh0000755000000000000000000000067607346545000017547 0ustar0000000000000000#!/bin/sh . ./lib ## I would use the builtin !, but that has the wrong semantics. not () { "$@" && exit 1 || :; } rm -rf temp1 mkdir temp1 cd temp1 darcs init echo first > a darcs add a darcs record -am 'first' echo replace first with something else > a darcs record -am 'mistake' echo first > a echo on second thought >> a echo ya | darcs amend-record -a darcs changes --last=1 -v > output cat output not grep first output cd .. rm -rf temp1 darcs-2.14.5/tests/issue53.sh0000755000000000000000000000063407346545000014074 0ustar0000000000000000#!/usr/bin/env bash . lib if echo $OS | grep -i windows; then echo This test does not work under Windows exit 0 fi # pull from not empty repo to empty repo rm -rf temp1 mkdir temp1 cd temp1 darcs init echo a > Aux.hs not darcs add Aux.hs darcs add --reserved-ok Aux.hs echo b > foo darcs add foo darcs record -am 'two files' not darcs mv foo com1 darcs mv --reserved-ok foo com1 cd .. rm -rf temp1 darcs-2.14.5/tests/issue538.sh0000755000000000000000000000607507346545000014171 0ustar0000000000000000#!/bin/env bash # A test for issue 538 - that an executable test script will run successfully if # it is recorded with --set-scripts-executable. . ./lib if echo $OS | grep -i windows; then echo I do not know how to run a test program under windows exit 0 fi function make_repo_with_test { mkdir temp1 ; cd temp1 ; darcs init echo "#!/bin/sh" > test.sh echo "echo 'hello world'" >> test.sh darcs add test.sh darcs record --author=test@test -am test darcs setpref test './test.sh' } # test record with --set-scripts-executable rm -rf temp1 make_repo_with_test touch blaat darcs add blaat if darcs record --set-scripts-executable -A test@test -am blaat --test; then echo "ok 1" else echo "not ok 1 recording second patch failed (because test failed?)" exit 1 fi cd .. # test record without --set-scripts-executable rm -rf temp1 make_repo_with_test touch blaat darcs add blaat if darcs record --dont-set-scripts-executable -A test@test -am blaat --test; then echo "not ok 2 recording second patch succeeded though test script should not be executable" exit 1 else echo "ok 2" fi cd .. # test amend-record with --set-scripts-executable rm -rf temp1 make_repo_with_test touch blaat darcs add blaat if echo y | darcs amend-record --set-scripts-executable -A test@test -a --test; then echo "ok 3" else echo "not ok 3 amending patch failed (because test failed?)" exit 1 fi cd .. # test amend-record without --set-scripts-executable rm -rf temp1 make_repo_with_test touch blaat darcs add blaat if echo y | darcs amend-record --dont-set-scripts-executable -A test@test -a /dev/null --test; then echo "not ok 4 amending patch succeeded even though --dont-set-scripts-executable specified" exit 1 else echo "ok 4" fi cd .. # test --linear with --set-scripts-executable rm -rf temp1 make_repo_with_test if darcs test --linear --set-scripts-executable | grep 'Success!' ; then echo "ok 5" else echo "not ok 5 tracking down with --set-scripts-executable failed (because test failed?)" exit 1 fi cd .. # test --linear without --set-scripts-executable rm -rf temp1 make_repo_with_test if darcs test --linear --dont-set-scripts-executable | grep 'Noone passed the test!' ; then echo "ok 6" else echo "not ok 6 tracking down did not find failure even though --dont-set-scripts-executable was given" exit 1 fi cd .. # check test --linear with files that become scripts during trackdown rm -rf temp1 mkdir temp1 ; cd temp1 ; darcs init echo "#!/bin/sh" > test.sh echo "./helper.sh" >> test.sh echo "#!/bin/sh" > helper.sh echo "echo 'helper speaking'" >> helper.sh darcs add test.sh darcs add helper.sh darcs record -am 'valid helper' -A test echo 'this is definitely not a valid script' > helper.sh darcs record -am 'invalid helper' -A test darcs setpref test './test.sh' darcs test --linear --set-scripts-executable > trackdown-out if grep 'Test failed!' trackdown-out && grep 'Success!' trackdown-out ; then echo "ok 7" else echo "not ok 7 either no failure or no success (both should occur)" exit 1 fi cd .. rm -rf temp1 darcs-2.14.5/tests/issue588.sh0000755000000000000000000000130007346545000014160 0ustar0000000000000000#!/usr/bin/env bash # For issue588, "amend-record --look-for-adds end up with two "addfile" entries" . ./lib rm -rf temp1 darcs init --repodir temp1 # Setup f with contents foo. echo foo > temp1/f darcs add --repodir temp1 f darcs rec --repodir temp1 -am p1 # Remove f, and amend p1, but only the hunk not the rmfile. # Here we use look-for-adds to trigger the bug rm temp1/f echo yyd | darcs amend-record --repodir temp1 --look-for-adds darcs changes --repodir temp1 --last 1 -v echo show the buggy pending cat temp1/_darcs/patches/pending echo bar > temp1/f echo y | darcs amend-record --repodir temp1 --all darcs changes --repodir temp1 --last 1 -v darcs check --repodir temp1 rm -rf temp1 darcs-2.14.5/tests/issue595_get_permissions.sh0000755000000000000000000000253407346545000017462 0ustar0000000000000000#!/usr/bin/env bash # Issue595 # # A test for running "darcs get" when the parent directory has restrictive # permissions. The bug is that darcs trys to "chdir" to the current directory # using the full path. The permissions on the parent directory prevent this # from working, even though the current repo and the remote have sufficient # permissions. # # The real-world case where this would happen would be a web-server with # restrictive permissions on "/home", with a user running darcs within that. . lib abort_windows rm -rf temp1 temp2 # Set up a "remote" repo mkdir tmp_remote cd tmp_remote darcs 'init' cd .. DIR=`pwd` # Set up a directory with restrictive permissions mkdir -p tmp_restrictive/liberal cd tmp_restrictive/liberal chmod 0111 ../../tmp_restrictive # sanity check that we can cd out and back cd ../..; cd tmp_restrictive/liberal # TODO: we avoid this test on Solaris because it seems we can't create # anything in tmp_restrictive/liberal touch can_touch if [ -e can_touch ]; then if hwpwd; then darcs get "$DIR/tmp_remote" 2> log not grep -i 'permission denied' log else echo "Apparently I can't do `basename $0` on this platform" fi else echo "Can't do `basename $0` on this platform" fi cd "$DIR" # We have to fix the permissions, just so we can delete it. chmod 0755 tmp_restrictive rm -rf tmp_remote tmp_restrictive darcs-2.14.5/tests/issue612_repo_not_writable.sh0000755000000000000000000000134407346545000017752 0ustar0000000000000000#!/usr/bin/env bash # Test that darcs fails appropriately when the target repo inventory file is not writable. # See issue612 . lib abort_windows rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init touch t.t darcs add t.t darcs record -am "initial add" if [ -e _darcs/inventories ]; then chmod 0555 _darcs/inventories/* chmod 0555 _darcs/inventories fi if [ -e _darcs/inventory ]; then chmod 0555 _darcs/inventory fi cd .. darcs get temp1 temp2 cd temp2 # this block may fail so we'd better make sure we clean up after # ourselves to avoid a permissions mess for other tests trap "cd ..; chmod -R 0755 temp1; rm -rf temp1 temp2" EXIT echo new >> t.t darcs record -am "new patch" not darcs push -a ../temp1 2> log grep failed log darcs-2.14.5/tests/issue68_broken_pipe.sh0000755000000000000000000000070007346545000016451 0ustar0000000000000000#!/usr/bin/env bash # For issue68, 'don't report "resource vanished" when stdout pipe is broken.' . ./lib rm -rf temp1 # Another script may have left a mess. darcs init --repodir temp1 cd temp1 for i in {1..500} do echo $i >> f done darcs changes 2> err | head darcs rec -alm 'Add big f' # We recorded a big file add, so asking for the first n lines of the patch # would trigger this bug. darcs changes -v 2> err | head [[ ! -s err ]] darcs-2.14.5/tests/issue691.sh0000755000000000000000000000042607346545000014163 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp mkdir temp cd temp darcs init echo 'record name' > _darcs/prefs/defaults # name requires an argument echo 'ALL unified foobar' >> _darcs/prefs/defaults # unified takes no argument darcs record && exit 1 darcs whats && exit 1 rm -rf temp darcs-2.14.5/tests/issue706.sh0000755000000000000000000000037107346545000014157 0ustar0000000000000000#!/usr/bin/env bash . ./lib # for issue706: "Filenames with spaces issue" DARCS_EDITOR=echo export DARCS_EDITOR rm -rf temp mkdir temp cd temp darcs init touch 'A B' darcs add 'A B' darcs rec -a -m 'a b' -A me ls darcs check cd .. rm -rf temp darcs-2.14.5/tests/issue709_pending_look-for-adds.sh0000755000000000000000000000153107346545000020406 0ustar0000000000000000#!/bin/sh . ./lib rm -rf temp1 mkdir temp1 cd temp1 darcs init # Here we check whether recording just one of two --look-for-add # addfiles causes any trouble (which it doesn't) date > f1 date > f2 echo yyd | darcs record -l -m ff cat _darcs/patches/pending not darcs wh rm f2 # Try recording a file add without --look-for-adds, with a setpref # patch present that we don't record. darcs setpref boringfile .boring echo bar > bar darcs add bar echo yyd | darcs record -mbar cat _darcs/patches/pending darcs whatsnew -s test -z "`darcs whatsnew -s`" # Now try the same thing using --look-for-adds echo foo > foo darcs wh -l # remove any files added by profiling or hpc... rm -f darcs.tix darcs.prof echo yyd | darcs record --look-for-adds -mfoo cat _darcs/patches/pending darcs whatsnew -s test -z "`darcs whatsnew -s`" cd .. rm -rf temp1 darcs-2.14.5/tests/issue70_setpref.sh0000755000000000000000000000405307346545000015622 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue70 - unrecorded (pending) changes to preferences ## should coalesce; if you set the same preference more than once in ## the same patch, only the last change should actually be recorded. ## ## Copyright (C) 2005 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf temp1 mkdir temp1 cd temp1 darcs init darcs setpref predist apple darcs setpref predist banana darcs setpref predist clementine darcs record -a -m manamana darcs changes --verbose > log not grep apple log not grep banana log grep clementine log cd .. rm -rf temp1 # not sure what i'm going for here - if coalescing happens strictly # before commuting, no problem, but what if patches are commuted # before coalescing? mkdir temp1 cd temp1 darcs init darcs setpref predist apple darcs setpref predist banana darcs setpref predist apple darcs setpref predist clementine darcs setpref predist banana darcs record -a -m manamana darcs changes --verbose > log not grep apple log not grep clementine log grep banana log cd .. rm -rf temp1 darcs-2.14.5/tests/issue761-fail-early-bad-pull-match.sh0000755000000000000000000000145307346545000020775 0ustar0000000000000000#!/usr/bin/env bash # This is a test for issue761, which pointed out that we didn't check the # syntax of --match patterns until after having spent considerable time # doing considerable work. So here we construct a very invalid repository, # and check that darcs fails *before* it notices that it's pulling from a # bad repository. Thus we verify that we aren't doing any work prior to # checking the flags. . ./lib rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init touch foo bar darcs add foo bar darcs record -a -m 'add two files' darcs tag -m tag rm foo bar darcs record -a -m 'rm two files' darcs tag -m tag2 rm -rf _darcs/inventories/* rm -rf _darcs/patches/* cd .. mkdir temp2 cd temp2 darcs init ! darcs pull --match 'foobar' ../temp1 2> error cat error grep foobar error rm -rf temp1 temp2 darcs-2.14.5/tests/issue803.sh0000755000000000000000000000067307346545000014162 0ustar0000000000000000#!/usr/bin/env bash # http://bugs.darcs.net/issue803: Darcs 2.0 regression on manual renames . lib rm -rf temp mkdir temp cd temp darcs init touch a.txt darcs add a.txt darcs record -a -m "First" -A me mkdir subdir darcs add subdir darcs record -a -m "Second" -A me mv a.txt subdir/ darcs mv a.txt subdir/a.txt darcs record -a -m "Third" -A me darcs changes --last 1 -v > stdout cat stdout not grep 'rmfile' stdout cd .. rm -rf temp darcs-2.14.5/tests/issue844_gzip_crc.sh0000755000000000000000000000043607346545000016044 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init echo > a darcs add a darcs record a -a -m "init" cd .. mkdir temp2 cd temp2 darcs init darcs pull ../temp1 -a darcs optimize compress for f in _darcs/patches/*-*; do gzip -t < "$f" done rm -rf temp1 temp2 darcs-2.14.5/tests/issue942_push_apply_prehook.sh0000755000000000000000000000332607346545000020157 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue942 - remote apply prehook not invoked on darcs push ## We also test for posthooks along the way even though that's not part ## of the issue. ## ## Copyright (C) 2009 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. echo 'apply prehook touch g' >R/_darcs/prefs/defaults echo 'apply posthook touch h' >>R/_darcs/prefs/defaults darcs get R S cd S touch f darcs add f darcs record -lam 'Add f' test ! -e ../R/g test ! -e ../R/h darcs push -a test -e ../R/g test -e ../R/h darcs-2.14.5/tests/latin9-input.sh0000755000000000000000000001630307346545000015131 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue64 - Should store patch metadata in UTF-8 ## ## Copyright (C) 2009 Reinier Lamers ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Helper function: do a darcs changes --xml and grep the result for the first # argument. If it is not found, exit with status 1. Otherwise, continue. The # second argument is a text that describes what we're grepping for. # If a third argument is given, it is used as the value for a --last option for # darcs changes. grep_changes () { switch_to_utf8_locale if [ -z "$3" ]; then last="" else last="--last $3" fi darcs changes $last --xml > changes.xml if grep "$1" changes.xml ; then echo "$2 OK" else cat changes.xml echo "$2 not UTF-8-encoded!" exit 1 fi switch_to_latin9_locale } # This file is encoded in ISO-8859-15 aka latin9. It was crafted with a hex editor. # Please leave it this way :-) switch_to_latin9_locale # This test clobbers the global darcs author -f $HOME/.darcs/author && exit 200 rm -rf temp1 mkdir temp1 cd temp1 darcs init # Test recording non-UTF-8-encoded non-latin1 ("funny") metadata from # interactive input echo 'Selbstverstndlich berraschend' > something.txt darcs add something.txt echo 'l33tking0r@example.org' > interaction_script.txt echo y >> interaction_script.txt echo y >> interaction_script.txt echo y >> interaction_script.txt echo 'uroh4xx0rz' >> interaction_script.txt echo n >> interaction_script.txt unset DARCSEMAIL unset EMAIL set darcs record -i --skip-long-comment < interaction_script.txt grep_changes 'l33tkingž0r@example.org' 'patch author from interactive prompt' grep_changes '€uroh4xx0rz' 'patch name from interactive prompt' # Test recording funny metadata from command line echo 'Sogar berraschender' >> something.txt darcs record -a -A 'Jrme Lebuf' -m 'that will be 15, sir' if echo $OS | not grep -i windows; then # issue2591 grep_changes 'that will be € 15, sir' 'patch name from command line' grep_changes 'Jérôme Lebœuf' 'patch author from command line' fi # Test recording funny metadata from a log file echo 'Am allerberraschendsten' >> something.txt echo 'darcs is soms wat naef aangaande tekstcodering' > log.txt echo 'en zulke naviteit is tegenwoordig pass, aldus iek' >> log.txt darcs record -a -A 'Jrme Lebuf' --logfile=log.txt grep_changes 'darcs is soms wat naïef aangaande tekstcodering' 'patch name from log file' grep_changes 'en zulke naïviteit is tegenwoordig passé, aldus Žižek' 'patch log from log file' # Test recording funny metadata from environment, export EMAIL='Slavoj iek ' rm $HOME/.darcs/author echo 'La la la, the more lines the better!' >> something.txt darcs record -a -m 'Patch names are overrated' if echo $OS | not grep -i windows; then # issue2591 grep_changes 'Slavoj Žižek' 'author name from environment' fi # Test recording funny metadata from prefs files echo 'ed is dead' > _darcs/prefs/author echo '483 bottles of beer on the wall' >> something.txt darcs record -a -m 'Patch by ed' grep_changes 'Žed is dead' 'author name from prefs file' # Test amend-recording funny metadata echo 'No, it is really 484' >> something.txt echo y | darcs amend-record -p 'Patch by ' -A 'ed is even deader' -a if echo $OS | not grep -i windows; then # issue2591 grep_changes 'Žed is even deader' 'author name from amend-record command line flag' fi cat < editor.hs # create an 'editor' that writes latin9 import System.Environment import qualified Data.ByteString as B str = B.pack [65,108,108,32,109,121,32,164,115,32,97,114,101,32,103,111,110,101] main = getArgs >>= \[x] -> B.writeFile x str FAKE ghc --make -o editor editor.hs export DARCS_EDITOR="`pwd`/editor" if echo $OS | not grep -i windows; then # issue2591 printf "y\ny\n" | darcs amend --edit -p 'Patch by ' grep_changes 'All my €s are gone' 'description edited from amend-record' grep_changes 'Žed is even deader' 'author name taken from draft in amend' fi # Test tag recording funny metadata rm _darcs/prefs/author # Make tag be taken from EMAIL env variable if echo $OS | not grep -i windows; then # issue2591 darcs tag -m ' is my favorite letter' grep_changes 'Slavoj Žižek' 'author name from environment with tag command' 1 grep_changes 'Ž is my favorite letter' 'Tag name from command line' fi unset EMAIL printf "ors\ninitialcomment\n" | darcs tag --edit-long-comment grep_changes Žors 'Author name from interactive prompt from tag command' grep_changes 'All my €s are gone' 'Tag name from editor from tag command' 1 if grep ors $HOME/.darcs/author ; then echo 'Author name stored locale-encoded in prefs file after tag command, OK' else echo 'No locale-encoded author in prefs file after tag command!' exit 1 fi rm $HOME/.darcs/author if echo $OS | not grep -i windows; then # issue2591 darcs tag -A Ade -m 'Lat call' grep_changes Adže 'Author name from tag command line' 1 grep_changes 'Lažt call' 'Tag name from tag command line (take 2)' 1 fi cd .. # test that UTF-8 metadata doesn't get mangled on get rm -rf temp2 darcs get temp1 temp2 darcs changes --repodir temp1 --xml > temp1/changes.xml darcs changes --repodir temp2 --xml > temp2/changes.xml diff temp1/changes.xml temp2/changes.xml # and that it doesn't get mangled on push rm -rf temp2 mkdir temp2; darcs init --repodir temp2 darcs push --repodir temp1 -a temp2 --set-default darcs changes --repodir temp1 --xml > temp1/changes.xml darcs changes --repodir temp2 --xml > temp2/changes.xml diff temp1/changes.xml temp2/changes.xml # and that it doesn't get mangled on pull rm -rf temp2 mkdir temp2; darcs init --repodir temp2 darcs pull --repodir temp2 -a temp1 darcs changes --repodir temp1 --xml > temp1/changes.xml darcs changes --repodir temp2 --xml > temp2/changes.xml diff temp1/changes.xml temp2/changes.xml # and that it doesn't get mangled on send rm -rf temp2 mkdir temp2; darcs init --repodir temp2 darcs send --repodir temp1 -a -o temp2/patch.dpatch darcs apply --repodir temp2 -a temp2/patch.dpatch darcs changes --repodir temp1 --xml > temp1/changes.xml darcs changes --repodir temp2 --xml > temp2/changes.xml diff temp1/changes.xml temp2/changes.xml darcs-2.14.5/tests/lazy-optimize-reorder.sh0000755000000000000000000000213307346545000017045 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 temp2 temp3 mkdir temp1 cd temp1 darcs init --no-patch-index # this test only applies to hashed formats if cat _darcs/inventory; then exit 200; fi date > f1 darcs add f1 darcs record -am 'add f1' darcs tag -m 'tag f1' date > f2 darcs add f2 darcs record -am 'add f2' cd .. darcs get --lazy temp1 temp2 darcs get --lazy temp2 temp3 cd temp2 # Run darcs changes so we pull in the inventories (but no the patches) darcs changes # Remove original repository, so we have no references to changes f1 and f2. rm -rf ../temp1 # Now we should be unable to read some of the history darcs changes -s > out cat out grep unavailable out date > f3 darcs add f3 darcs record -am 'add f3' darcs tag -m 'tag 123' cd .. cd temp3 date > f4 darcs add f4 darcs record -am 'add f4' darcs pull -av # Here's the point of this test: we should be able to optimize # --reorder without being able to read all the patches in the # repository. darcs optimize reorder # Just a double-check: we shouldn't be able to check in this case. not darcs check cd .. rm -rf temp1 temp2 temp3 temp4 darcs-2.14.5/tests/lib0000755000000000000000000000550607346545000012734 0ustar0000000000000000# This is a -*- sh -*- library. ## I would use the builtin !, but that has the wrong semantics. not () { "$@" && exit 1 || :; } # trick: OS-detection (if needed) abort_windows () { if echo $OS | grep -i windows; then echo This test does not work on Windows exit 200 fi } pwd() { ghc --make -o hspwd "$TESTBIN/hspwd.hs" > /dev/null "./hspwd" } which() { type -P "$@" | cut -d' ' -f 3- } # switch locale to one supporting the latin-9 (ISO 8859-15) character set if possible, otherwise skip test no_latin9_locale_warning () { echo "no ISO 8859-15 locale found, skipping test" echo "try (eg): sudo locale-gen en_US.ISO-8859-15" } switch_to_latin9_locale () { if echo $OS | grep -i windows; then chcp.com 28605 else if ! which locale ; then echo "no locale command, skipping test" exit 200 fi # look for a ISO 8859-15 locale. locale -a shows iso885915, on ubuntu at least latin9_locale=`locale -a | egrep --text -i iso8859-?15 | head -n 1` || (no_latin9_locale_warning; exit 200) test -n "$latin9_locale" || (no_latin9_locale_warning; exit 200) echo "Using locale $latin9_locale" export LC_ALL=$latin9_locale echo "character encoding is now `locale charmap`" fi } # switch locale to utf8 if supported if there's a locale command, skip test # otherwise switch_to_utf8_locale () { if echo $OS | grep -i windows; then chcp.com 65001 else if ! which locale ; then echo "no locale command" exit 200 # skip test fi utf8_locale=`locale -a | grep --text .utf8 | head -n 1` || exit 200 test -n "$utf8_locale" || exit 200 echo "Using locale $utf8_locale" export LC_ALL=$utf8_locale echo "character encoding is now `locale charmap`" fi } serve_http() { cat > light.conf < /dev/null 2>&1 || exit 200 baseurl="http://localhost:23032" } finish_http() { test -e "$1/light.pid" && kill `cat "$1/light.pid"` || true } check_remote_http() { if ! curl -fI "$1"; then echo Cannot reach "$1" exit 200 fi } skip-formats() { for f in "$@"; do grep $f $HOME/.darcs/defaults && exit 200 || true; done } # check that the specified string appears precisely once in the output grep-once() { grep -c "$@" | grep -w 1 } require_ghc() { test $GHC_VERSION -ge $1 || exit 200 } grep -q darcs-2 .darcs/defaults && format=darcs-2 grep -q darcs-1 .darcs/defaults && format=darcs-1 set -vex -o pipefail darcs-2.14.5/tests/log-duplicate.sh0000755000000000000000000000273307346545000015327 0ustar0000000000000000#!/usr/bin/env bash ## Copyright (C) 2012 BSRK Aditya ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # this test fails for darcs-1 repos skip-formats darcs-1 darcs init --repo R darcs init --repo S cd R touch f darcs record -lam 'p1' cd ../S touch f darcs record -lam 'p2' darcs send -ao p2.dpatch ../R cd ../R darcs apply -a ../S/p2.dpatch darcs log --verbose darcs log --verbose | grep -q 'duplicate' darcs log f --verbose | not grep -q 'duplicate' darcs-2.14.5/tests/log.sh0000755000000000000000000000641107346545000013354 0ustar0000000000000000#!/usr/bin/env bash . ./lib # Some tests for 'darcs log -a' rm -rf temp1 darcs init temp1 cd temp1 date >> date.t darcs record -A 'Mark Stosberg ' -lam foo #### darcs log date.t > out # trivial case first cat out grep foo out darcs log --last=1 date.t > out cat out grep foo out darcs log --last 1 --summary date.t > out cat out grep foo out darcs log --last=1 --xml > out cat out grep '<a@b.com>' out # check that --xml encodes < and > ### # Add 6 records and try again for i in 0 1 2 3 4 5; do date >> date.t darcs record -a -m "foo record num $i" date.t done darcs log date.t > out cat out grep foo out darcs log --last=1 date.t > out cat out grep foo out darcs log --last 1 --summary date.t > out cat out grep foo out ### darcs log --context --from-patch='num 1' --to-patch 'num 4' > out cat out grep 'num 4' out grep 'num 3' out grep 'num 2' out grep 'num 1' out cd .. # Some tests for the output of log when combined with move. rm -rf temp2 darcs init temp2 cd temp2 date > foo darcs record -lam 'add foo' mkdir d darcs record -lam 'add d' darcs mv foo d darcs record -m 'mv foo to d' -a darcs mv d directory darcs record -m 'mv d to directory' -a echo 'How beauteous mankind is' > directory/foo darcs record -m 'modify directory/foo' -a darcs log directory/foo > log grep 'add foo' log grep 'mv foo to d' log echo 'O brave new world' > directory/foo # darcs should also take unrecorded moves into account darcs mv directory/foo directory/bar darcs log directory/foo > log grep 'mv foo to d' log echo 'That has such people in it' > directory/foo darcs add directory/foo darcs record -m 'mv foo then add new foo' -a darcs annotate directory/bar | tee log grep 'O brave new world' log grep "mv foo then add new foo" log not grep "unknown" log cd .. # Issue244 # darcs changes should be able to pull up the history for a file # using its moved and not-yet recorded new name rm -rf temp3 darcs init temp3 cd temp3 touch b darcs record -lam 11 darcs mv b c darcs log c | grep 11 cd .. ## issue1337 - darcs log shows unrelated patches ## Asking "darcs log" about an unrecorded file d/f will list the ## patch that creates the parent directory d/ (instead of no patches). rm -rf temp4 darcs init temp4 cd temp4 mkdir d darcs record -lam d d # We use --match 'touch d/f' instead of simply d/f because the latter # prints "Changes to d/f:\n" before the count. test 0 -eq "$(darcs log --count --match 'touch d/f')" cd .. ## issue1632 - 'darcs changes d/f' should not list any changes, ## where d is part of the repo and f is a non-existent file. rm -rf temp5 darcs init temp5 cd temp5 mkdir d darcs record -lam 'added directory d' # darcs should not list any changes here: darcs changes non-existent-file > log not grep 'added directory d' log # ...and neither here: darcs changes d/non-existent-file > log not grep 'added directory d' log cd .. ## issue1888 - changes --context is broken when topmost patch ## is a clean tag. rm -rf temp6 darcs init temp6 cd temp6 echo a > a ; darcs rec -lam "patch_a" darcs log --context | grep patch_a darcs tag -m "tag_a" darcs log --context | not grep patch_a darcs log --context | grep tag_a echo b > a; darcs rec -lam "patch_b" darcs log --context | not grep patch_a darcs log --context | grep tag_a darcs log --context | grep patch_b cd .. darcs-2.14.5/tests/log_send_context.sh0000755000000000000000000000056707346545000016137 0ustar0000000000000000#!/usr/bin/env bash . ./lib # RT#544 using context created with 8-bit chars; rm -rf temp1 mkdir temp1 cd temp1 darcs init touch foo darcs record -la -m 'add\212 foo' | grep 'Finished record' darcs log --context >context date > foo darcs record -a -m 'date foo' | grep 'Finished record' darcs send -a -o patch --context context . | grep 'Wrote patch to' cd .. rm -rf temp1 darcs-2.14.5/tests/look_for_add.sh0000755000000000000000000000133507346545000015215 0ustar0000000000000000#!/usr/bin/env bash cat > empty_pending < dir/foo echo zag > foo mkdir dir2 echo hi > dir2/foo2 darcs record -a -m add_foo -A x --look-for-adds check_empty_pending cd ../temp2 darcs init darcs pull -a ../temp1 cd .. cmp temp1/dir2/foo2 temp2/dir2/foo2 cmp temp1/dir/foo temp2/dir/foo cmp temp1/foo temp2/foo rm -rf temp1 temp2 darcs-2.14.5/tests/look_for_moves.sh0000755000000000000000000000750107346545000015617 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 mkdir temp1 temp2 cd temp1 # simple add and move darcs init touch foo darcs record -lam add_file mv foo foo2 darcs wh --summary --look-for-moves >log 2>&1 cat > log.expected < ./foo2 EOF diff -u log log.expected rm log log.expected darcs record -am move_file --look-for-moves darcs wh --look-for-moves --look-for-adds >log 2>&1 grep -vE "(^ *$|^\+|No changes!)" log rm -rf * # simple add and move dir darcs init mkdir foo darcs record -lam add_dir mv foo foo2 darcs wh --summary --look-for-moves >log 2>&1 cat > log.expected < ./foo2 EOF diff -u log log.expected rm log log.expected darcs record -am move_dir --look-for-moves darcs wh --look-for-adds >log 2>&1 grep -vE "(^ *$|^\+|No changes!)" log rm -rf * # add, move and add same name darcs init touch foo darcs record -lam add_file mv foo foo2 touch foo darcs wh --summary --look-for-moves >log 2>&1 cat > log.expected < ./foo2 EOF diff -u log log.expected rm log log.expected darcs wh --summary --look-for-moves --look-for-adds >log 2>&1 cat > log.expected < ./foo2 a ./foo EOF darcs record -am move_file_add_file --look-for-moves --look-for-adds grep -vE "(^ *$|^\+|No changes!)" log rm -rf * # amend-record darcs init touch foo darcs record -lam add_file mv foo foo2 echo 'yyy' | darcs amend-record -p add_file --look-for-moves darcs wh --look-for-moves --look-for-adds >log 2>&1 grep -vE "(^ *$|^\+|No changes!)" log darcs log -v --machine -p add_file | grep "] addfile ./foo2" rm -rf * # add, move, add same name and amend-record darcs init touch foo darcs record -lam add_file mv foo foo2 touch foo echo 'yyyy' | darcs amend-record -p add_file --look-for-moves --look-for-adds darcs wh --look-for-moves --look-for-adds >log 2>&1 grep -vE "(^ *$|^\+|No changes!)" log darcs log -v --patch add_file >log 2>&1 grep "addfile ./foo" log grep "addfile ./foo2" log rm -rf * # add, move, amend-record, move, amend-record darcs init touch foo darcs record -lam add_file mv foo foo2 echo 'yyy' | darcs amend-record -p add_file --look-for-moves mv foo2 foo echo 'yyy' | darcs amend-record -p add_file --look-for-moves darcs wh --look-for-moves --look-for-adds >log 2>&1 grep -vE "(^ *$|^\+|No changes!)" log rm -rf * # move dir with content darcs init touch foo # created before dir to get a lower inode mkdir dir mv foo dir darcs record -lam add_files mv dir dir2 darcs wh --summary --look-for-moves > log 2>&1 cat > log.expected < ./dir2 EOF diff -u log log.expected rm log log.expected darcs record -am move_dir --look-for-moves darcs wh --look-for-moves --look-for-adds >log 2>&1 grep -vE "(^ *$|^\+|No changes!)" log rm -rf * # name swapping -- unsupported thus ignored darcs init touch foo foo2 darcs record -lam add_file mv foo foo.tmp mv foo2 foo mv foo.tmp foo2 not darcs wh --look-for-moves rm -rf * # dir swapping -- dir moves are ignored but inner files moves are considered darcs init mkdir dir dir2 touch dir/foo dir2/foo2 darcs record -lam add_files_and_dirs mv dir dir.tmp mv dir2 dir mv dir.tmp dir2 darcs wh --summary --look-for-moves > log 2>&1 cat > log.expected < ./dir2/foo ./dir2/foo2 -> ./dir/foo2 EOF diff -u log log.expected rm -rf * # darcs mv before a plain mv darcs init touch foo darcs record -lam add_files_and_dirs darcs mv foo foo2 mv foo2 foo3 darcs wh --summary --look-for-moves > log 2>&1 cat > log.expected < ./foo3 EOF diff -u log log.expected rm log log.expected darcs record -a -m move_dirs --look-for-moves darcs wh --look-for-moves --look-for-adds >log 2>&1 grep -vE "(^ *$|^\+|No changes!)" log rm -rf * # mv to a boring filename darcs init touch foo darcs record -lam add_files_and_dirs mv foo foo~ darcs wh --summary --look-for-moves > log 2>&1 cat > log.expected < old echo foo >> old echo bar >> old darcs record -lam 'added old' mv old new echo bar > new echo bar >> new echo bar >> new darcs whatsnew --look-for-moves --look-for-replaces $paths > ../out.actual cd .. } cat < out.expected move ./old ./new hunk ./new 3 -bar +foo replace ./new [A-Za-z_0-9] foo bar EOF test_setup 1 "" diff out.actual out.expected # same but only for old test_setup 2 old # remove the line about What's new in: old sed -i '1d' out.actual diff out.actual out.expected # same but only for new test_setup 3 new # remove the line about What's new in: new sed -i '1d' out.actual # NOTE: the move is NOT detected in this case # We might want to change that... sed '1d' out.expected | sed 's/new/old/' > out.expected3 diff out.actual out.expected3 # same but only for old and new test_setup 4 old new # remove the line about What's new in: old new sed -i '1d' out.actual diff out.actual out.expected # same but only for old and new and non-existing test_setup 5 old new non-existing # remove the line about What's new in: old new, and the one that reports non-existing sed -i '1,2d' out.actual diff out.actual out.expected darcs-2.14.5/tests/look_for_moves_with_args.sh0000755000000000000000000000140407346545000017662 0ustar0000000000000000#!/usr/bin/env bash # test that --look-for-moves properly handles file arguments . ./lib darcs init R cd R touch old1 touch old2 touch old3 darcs record -lam 'added files' mv old1 new1 mv old2 new2 cd .. runtest () { darcs whatsnew --repodir R --look-for-moves $* | grep move > out } num_lines () { test "$(cat $2 | wc -l)" = "$1" } move1='move \./old1 \./new1' move2='move \./old2 \./new2' runtest "" grep "$move1" out grep "$move2" out num_lines 2 out runtest old1 # we expect to see only move1 grep "$move1" out not grep "$move2" out num_lines 1 out runtest old1 old2 # we expect to see both moves grep "$move1" out grep "$move2" out num_lines 2 out runtest old2 old3 # we expect to see only move2 grep "$move2" out not grep "$move1" out num_lines 1 out darcs-2.14.5/tests/mark-conflicts.sh0000755000000000000000000000144207346545000015506 0ustar0000000000000000#!/usr/bin/env bash # Automated tests for "darcs mark-conflicts". # The builtin ! has the wrong semantics for not. not () { "$@" && exit 1 || :; } mkdir temp1 cd temp1 darcs init echo "Conflict, Base ." > child_of_conflict darcs add child_of_conflict darcs record -am 'Conflict Base' cd .. darcs get temp1 temp2 # Add and record differing lines to both repos cd temp1 echo "Conflict, Part 1." > child_of_conflict darcs record -A author -am 'Conflict Part 1' cd .. cd temp2 echo "Conflict, Part 2." > child_of_conflict darcs record -A author -am 'Conflict Part 2' cd .. cd temp1 darcs pull -a ../temp2 > log grep conflict log grep finished log grep 'v v' child_of_conflict darcs revert -a not grep 'v v' child_of_conflict darcs mark-conflicts grep 'v v' child_of_conflict cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/match-date.sh0000755000000000000000000001405407346545000014604 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 # Some tests for the '--match' flag, specifically the date-matching fmt_offset() { if date -d "now${1}days" >& /dev/null; then date -d "now${1}days" +"%Y%m%d" elif date -v ${1}d >& /dev/null; then date -v ${1}d +"%Y%m%d" else echo "Can't do date arithmetic on this system :(" >&2 return 1 fi } reset_repo () { cd .. rm -rf temp1 mkdir temp1 cd temp1 darcs init touch bar darcs add bar } create_entry () { echo $1 >> bar echo "$1/tester/a///" | tr / \\012 | darcs record -m "does not matter" --pipe bar } create_entry_now () { echo today >> bar darcs record -m "does not matter" bar -a -A tester } # parse_date just checks for parsing, while match_date checks for an actual match. # It's better if we can use "match_date", but we have to be able to construct such a date # based on a date dynamically generated by this test script. # alternately, it might be more useful to build a random date string generator # using QuickCheck... for any n random CalendarTimes, have it generate some # possible variants and roundtrip them to see if they match parse_date () { darcs changes --match "date \"$1\"" > log not grep fancy log } match_date () { darcs changes --match "date \"$1\"" > log grep tester log not grep fancy log } nomatch_date () { darcs changes --match "date \"$1\"" > log not grep tester log not grep fancy log } mkdir temp1 cd temp1 reset_repo # this block of dates should all refer to the same thing year=1973 mm=02 dd=04 hhmmss="15:08" create_entry "$year-$mm-$dd $hhmmss" match_date "$year-$mm-$dd" match_date "$year$mm$dd" match_date "$year-$mm" match_date "$year$mm" match_date "$year" # week dates. note that 2007 was selected as it starts on Monday reset_repo create_entry "2007-01-04 15:00" match_date '2007-W01-4' nomatch_date '2007-W01-1' match_date '2007W014' match_date '2007-W01' nomatch_date '2007-W02-1' create_entry "2007-01-08 15:00" match_date '2007-W02' match_date '2007-W02-1' create_entry "2007-05-20 15:00" match_date '2007-W20' nomatch_date '2007-W21' nomatch_date '2007-W19' # ordinal dates. eh... why not? match_date '2007-004'; # fourth day of 2007 match_date '2007004' nomatch_date '2007-005' # midnight and zero reset_repo create_entry "1992-10-15 00:00" match_date '1992-10-14 24:00' match_date '1992-10-15 00:00' # all the same date/time reset_repo create_entry "1992-02-12T22:32:11" match_date '1992-02-12T22:32:11' match_date '1992-02-12 22:32:11' match_date '1992-02-12T223211.0000' # english dates - the old hard coded from < darcs 1.0.6 reset_repo year=`date +%Y` mm=`date +%m` dd=`date +%d` hhmmss=`date +%k:%M:%S` tz=`date +%z` create_entry "$(($year-1))-$mm-$dd" nomatch_date 'today' nomatch_date 'yesterday' nomatch_date 'day before yesterday' nomatch_date 'last week' nomatch_date 'last month' # note: this test might fail if you run it just before midnight reset_repo create_entry_now match_date 'today' nomatch_date 'yesterday' nomatch_date 'day before yesterday' match_date 'last week' match_date 'last month' fmt_offset -1 || exit 200 reset_repo create_entry "$(fmt_offset -350)" # english dates - new possibilities nomatch_date 'yesterday at 14:00:00' match_date 'last 3 years' match_date 'last year' nomatch_date '2 days ago' nomatch_date 'last month 13:00' nomatch_date '3 days before last week' reset_repo create_entry_now match_date 'day after yesterday' match_date 'day since yesterday' match_date 'week after last week' match_date 'week since last week' create_entry "1992-10-02 00:15" match_date '15 minutes after 1992-10-02' match_date '15 minutes since 1992-10-02' reset_repo create_entry "1992-10-02 00:15+05" # note that earlier dates will always match match_date '15 minutes after 1992-10-02 00:00+05'; # same time match_date '15 minutes after 1992-10-01 23:00+04'; # same time match_date '15 minutes since 1992-10-02 00:00+05'; # same time match_date '15 minutes since 1992-10-01 23:00+04'; # same time nomatch_date '15 minutes after 1992-10-02 01:00+05'; # 1 hour later nomatch_date '15 minutes after 1992-10-02 00:00+04'; # 1 hour later nomatch_date '1 hour, 15 minutes after 1992-10-02 00:00+05'; # 1 hour later nomatch_date '15 minutes since 1992-10-02 01:00+05'; # 1 hour later nomatch_date '15 minutes since 1992-10-02 00:00+04'; # 1 hour later nomatch_date '1 hour, 15 minutes since 1992-10-02 00:00+05'; # 1 hour later match_date '1 hour, 15 minutes after 1992-10-02 00:00+06'; # same time match_date '1 hour, 15 minutes after 1992-10-01 23:00+05'; # same time match_date '1 hour, 15 minutes since 1992-10-02 00:00+06'; # same time match_date '1 hour, 15 minutes since 1992-10-01 23:00+05'; # same time reset_repo create_entry_now create_entry 1992-10-02 00:15 # english intervals nomatch_date 'between last fortnight and day before yesterday' match_date 'between last fortnight and today' match_date 'in the last 45 seconds' match_date 'after 1992' match_date 'since 1992' # iso 8601 intervals parse_date '1992-10-02 00:00Z/1992-10-02 00:16Z' match_date '1992-10-02 00:00/1992-10-02 00:16' match_date 'between 1992-10-02 00:00 and 1992-10-12 00:16' parse_date 'P3YT3M/1992' parse_date '1992/P3Y3M4DT5H3M2S' parse_date '1992/P3Y3M' # stuff from the manual reset_repo create_entry_now nomatch_date 'between 2004-03-12 and last week' match_date 'last week' parse_date 'yesterday' parse_date 'today 14:00' nomatch_date '3 days before last year at 17:00' # We can't in general parse the raw date output by darcs. If we change the # format to not include timezone information, this would be possible. But # maybe that's not desireable. For now, we just won't test the raw date. #match_date "$raw_date" parse_date 'after 2005' parse_date 'since 2005' parse_date 'in the last 3 weeks' parse_date 'P3M/2006-03-17' parse_date '2004-01-02/2006-03-17' parse_date 'P2M6D' # cvs dates parse_date '2006/01/19 21:14:20 UTC' # We can't handle all timezones in the old style dates # so this test will not work everywhere # match_date "$year/$mm/$dd $hhmmss $tz" reset_repo create_entry '2038-01-01' match_date 'after 2037' match_date 'since 2037' rm -rf temp1 temp2 darcs-2.14.5/tests/match.sh0000755000000000000000000000521507346545000013670 0ustar0000000000000000#!/usr/bin/env bash # Some tests for the '--match' flag . lib # set up the repository rm -rf temp1 # another script may have left a mess. mkdir temp1 cd temp1 darcs init cd .. # create three patches - the property we exploit to determine # if a matcher does the right thing is that each patch has a # different author cd temp1 touch bar darcs add bar darcs record -a -m "first patch" bar -A author1 echo foo > bar darcs record -a -m "\"second\" \\ patch" bar -A author2 echo blop > bar darcs record -a -m "second" bar -A author3 cd .. # ------------------------------------------------------------------- # single matchers # ------------------------------------------------------------------- cd temp1 # matching on author really matches on that, and not something else darcs changes --match='author "first patch"' > log not grep '.' log # normal changes shows both authors and patch names darcs changes > log grep author1 log grep author2 log grep author3 log grep 'first patch' log grep '"second" \\ patch' log grep -v patch log | grep second # exact darcs changes --match='exact second' > log not grep author1 log not grep author2 log grep author3 log # name darcs changes --match='name second' > log not grep author1 log grep author2 log grep author2 log # author darcs changes --match='author author1' > log grep author1 log not grep author2 log not grep author3 log #hash darcs changes --xml-output --match='exact "\"second\" \ patch"' > log hash=`grep hash log | sed -e "s/.*hash='//" -e "s/'.*//"` echo $hash darcs changes --match="hash $hash" not grep author1 log grep author2 log not grep author3 log cd .. # ------------------------------------------------------------------- # matching on combinations # # uses the setup from the atomic patches # ------------------------------------------------------------------- cd temp1 # or darcs changes --match='author author1 || author author2' > log grep author1 log grep author2 log not grep author3 log # and darcs changes --match='name second && author author2' > log not grep author1 log grep author2 log not grep author3 log # not darcs changes --match='not name second' > log grep author1 log not grep author2 log not grep author3 log # grouping darcs changes --match='(not name second) || (author author3)' > log grep author1 log not grep author2 log grep author3 log # an empty pattern should just match all patches [[ $(darcs changes --match '' --count) -eq 3 ]] # check the error message for an invalid matcher not darcs changes --match invalid_matcher > log 2>&1 grep "unexpected 'i'" log grep 'expecting valid expressions over' log grep 'for more help, see `darcs help patterns`' log cd .. rm -rf temp1 darcs-2.14.5/tests/merge_three_patches.sh0000755000000000000000000000176507346545000016577 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf tempOld tempA tempB mkdir tempOld tempA cd tempOld darcs initialize echo record author me > _darcs/prefs/defaults echo ALL all >> _darcs/prefs/defaults #echo ALL verbose >> _darcs/prefs/defaults echo ALL ignore-times >> _darcs/prefs/defaults echo A > foo echo B >> foo echo C >> foo echo D >> foo echo E >> foo echo F >> foo echo G >> foo echo H >> foo darcs add foo darcs record -m Old cd .. cd tempA darcs initialize cp ../tempOld/_darcs/prefs/defaults _darcs/prefs darcs pull ../tempOld cp foo temp cat temp | grep -v A | grep -v B | grep -v D | sed s/E/e/ \ | grep -v G | sed s/H/h/ > foo darcs record -m AA cd .. darcs get tempOld tempB cd tempB cp ../tempOld/_darcs/prefs/defaults _darcs/prefs echo 7 > foo darcs record -m BB darcs pull ../tempA darcs record -m "conflict resolution" cd .. cd tempA darcs pull ../tempB darcs log -v --max-count 1 -p B | cat darcs log -v --max-count 1 -p resolution | cat cd .. cmp tempA/foo tempB/foo rm -rf tempOld tempA tempB darcs-2.14.5/tests/mergeresolved.sh0000755000000000000000000000177607346545000015447 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf fooOld tempA tempB mkdir fooOld tempA tempB cd fooOld darcs init echo record author me > _darcs/prefs/defaults echo ALL all >> _darcs/prefs/defaults #echo ALL verbose >> _darcs/prefs/defaults echo ALL ignore-times >> _darcs/prefs/defaults echo Old > foo darcs add foo darcs record -m Old cd .. cd tempA darcs init cp ../fooOld/_darcs/prefs/defaults _darcs/prefs darcs pull ../fooOld echo A > foo darcs record -m AA cd .. cd tempB darcs init cp ../fooOld/_darcs/prefs/defaults _darcs/prefs darcs pull ../fooOld echo B > foo darcs record -m BB darcs pull ../tempA echo A > foo darcs record -m "ok A's fine." cd .. # At this point, tempB and tempA should agree--since the conflict was # resolved in favor of tempA. cmp tempB/foo tempA/foo cd tempA echo AA > foo darcs record -m "AA -- upping the ante." cd .. cd tempB darcs pull ../tempA cd .. cd tempA darcs pull ../tempB cd .. # At this point, tempB and tempA should agree since we have pulled both ways. cmp tempB/foo tempA/foo darcs-2.14.5/tests/merging_newlines.sh0000755000000000000000000000101707346545000016124 0ustar0000000000000000#!/usr/bin/env bash # trick: requiring something to fail . lib # A test for darcs detecting a conflict, inspired by bug #152 in RT # set up the repository darcs init temp1 cd temp1 echo "apply allow-conflicts" > _darcs/prefs/defaults echo "from temp1" > one.txt darcs add one.txt darcs record -am "add one.txt" echo >> one.txt darcs wh -u cd .. darcs get temp1 temp2 cd temp2 echo "from temp2" >> one.txt darcs whatsnew -s | grep M darcs record -am "append non-empty line" darcs push -av > log grep -i conflicts log cd .. darcs-2.14.5/tests/mutex-option-precedence.sh0000755000000000000000000000335307346545000017340 0ustar0000000000000000#!/usr/bin/env bash ## Test for issueNNNN - with mutually exclusive options "ALL foo" and ## "bar no-foo", "darcs bar" should mean "darcs bar --no-foo". ## ## Copyright (C) 2009 Trent W. Buck ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ../tests/lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repo. darcs init --repo S # Create our test repos. cd R echo 'Example content.' >f # Change the working tree. darcs record -lam 'Add f.' darcs send -aof.dpatch ../S darcs obl -a cat >>_darcs/prefs/defaults < temp.c darcs add temp.c darcs record --all -A test --name=hi echo goodbye >> temp.c darcs whatsnew darcs record -a -A au -m bye echo bar > bar.c darcs add bar.c darcs record -a -m one -A ex darcs mv bar.c zig.c darcs whatsnew darcs record -a -m two -A ex mkdir baz darcs add baz darcs whatsnew darcs record -a -m three -A ex darcs mv zig.c baz/bar.c darcs whatsnew darcs record -a -m four -A ex darcs mv baz temp darcs whatsnew darcs record -a -m five -A ex darcs mv temp temp 1> stdout 2> stderr || true grep 'Cannot rename a file or directory onto itself' stderr cd .. rm -rf temp1 darcs init temp1 cd temp1 echo hi world > a darcs record -lam lower cd .. darcs clone temp1 temp2 cd temp1 darcs mv a A echo goodbye > A darcs record --all -m 'to upper' cd ../temp2 darcs pull -a cd .. rm -rf temp1 temp2 # Part 2 darcs init temp1 cd temp1 echo adding a directory with more than one .. in it should work. mkdir foo.d mkdir foo.d/second mkdir foo.d/second/third mkdir foo.d/other touch ./foo.d/other/date.t darcs add -r foo.d cd foo.d/second/third darcs mv ../../other/date.t ../../other/date_moved.t cd ../../.. echo darcs refuses to move to an existing file touch ping pong darcs add ping pong not darcs mv ping pong 2>&1 | grep "already exists" # case sensitivity series # ----------------------- # these are tests designed to check out darcs behave wrt to renames # where the case of the file becomes important # are we on a case sensitive file system? touch is_it_cs rm -f IS_IT_CS if test -e is_it_cs; then echo This is a case-sensitive file system. else echo This is NOT a case-sensitive file system. fi # if the new file already exists - we don't allow it # basically the same test as mv ping pong, except we do mv ping PING # and both ping and PING exist on the filesystem echo "case sensitivity - simply don't allow mv if new file exists" touch 'cs-n-1'; touch 'CS-N-1'; touch 'cs-y-1'; touch 'CS-Y-1'; darcs add cs-n-1 cs-y-1 if test -e is_it_cs; then # regardless of case-ok, we do NOT want this mv at all not darcs mv cs-n-1 CS-Y-1 2>&1 | grep "already exists" not darcs mv --case-ok cs-n-1 CS-Y-1 2>&1 | grep "already exists" fi # if the new file does not already exist - we allow it echo "case sensitivity - the new file does *not* exist" touch 'cs-n-2'; touch 'cs-y-2'; darcs add cs-n-2 cs-y-2 # these mv's should be allowed regardless of flag or filesystem darcs mv cs-n-2 CS-N-2 darcs mv --case-ok cs-y-2 CS-Y-2 # parasites - do not accidentally overwrite a file just because it has a # similar name and points to the same inode. We want to check if a file if the # same NAME already exists - we shouldn't care about what the actual file is! echo "case sensitivity - inode check"; touch 'cs-n-3'; touch 'cs-y-3'; darcs add cs-n-3 cs-y-3 if ln cs-n-3 CS-N-3; then # checking if we support hard links ln cs-y-3 CS-Y-3 # regardless of case-ok, we do NOT want this mv at all not darcs mv cs-n-3 CS-N-3 2>&1 | grep "already exists" not darcs mv --case-ok cs-y-3 CS-Y-3 2>&1 | grep "already exists" fi # parasites - we don't allow weird stuff like mv foo bar/foo just because # we opened up some crazy exception based on foo's name echo 'refuses to move to an existing file with same name, different path' touch 'cs-n-4'; touch 'foo.d/cs-n-4'; touch 'cs-y-4'; touch 'foo.d/cs-y-4'; darcs add cs-n-4 # regardless of case-ok, we do NOT want this mv at all not darcs mv cs-n-4 foo.d/cs-n-4 2>&1 | grep "already exists" not darcs mv --case-ok cs-y-4 foo.d/cs-y-4 2>&1 | grep "unadded" # --------------------------- # end case sensitivity series touch abs_path.t darcs add abs_path.t REPO_ABS=`pwd` darcs mv "$REPO_ABS/abs_path.t" abs_path_new.t darcs mv abs_path_new.t "$REPO_ABS/abs_path.t" # issue608 touch 'gonna_be_deleted'; darcs add gonna_be_deleted darcs record -am 'added doomed file' rm gonna_be_deleted darcs record -am 'deleted file' touch 'new_file'; darcs add new_file darcs mv new_file gonna_be_deleted cd .. rm -rf temp1 # mv and test suite darcs init temp1 cd temp1 date > foo darcs record -lam add_foo echo 'test ! -e foo' > test.sh # "foo should not exist" darcs record -lam add_test darcs setpref test 'ls && bash test.sh' darcs record -a -m settest --no-test darcs mv foo bar darcs record --debug -a -m mvfoo cd .. rm -rf temp1 # mv then ad darcs init temp1 cd temp1 touch fee fi fo fum darcs record -lam add darcs mv fee foo touch fee darcs add fee darcs record -a -m newfee darcs mv fi fib darcs record -a -m mvfi date > fi darcs add fi darcs record -a -m newfi cd .. rm -rf temp1 # illegal mv darcs init temp1 cd temp1 echo text > afile.txt darcs record -lam init mkdir d not darcs mv afile.txt d/afile.txt # should fail, since d not in repo cd .. rm -rf temp1 # swapping files darcs init temp1 cd temp1 touch foo bar darcs record -lam add_foo_bar darcs mv foo zig darcs mv bar foo darcs mv zig bar darcs record -a -m swap_foo_bar cd .. rm -rf temp1 ## issue2139 - darcs should accept to mv to the current working directory ## Copyright (C) 2012 Eric Kow darcs init temp1 cd temp1 # move dir to root mkdir a a/a2 a/a3 darcs record -lam 'Some directories (a)' darcs mv a/a2 . test -d a2 cd a darcs mv a3 .. not test -d a3 cd .. test -d a3 # move dir to non-root dir mkdir b b2 b3 darcs record -lam 'Some directories (b)' darcs mv b2 b test -d b/b2 cd b darcs mv ../b3 . test -d b3 cd .. cd .. rm -rf temp1 # issue1740 - darcs mv on directories should work after the fact darcs init temp1 cd temp1 mkdir d echo 'Example content.' > d/f darcs record -lam 'Add d/f' mv d d2 darcs mv d d2 # oops, I meant to darcs mv that darcs what | grep "move ./d ./d2" cd .. rm -rf temp1 darcs-2.14.5/tests/mv_and_remove_tests.sh0000755000000000000000000000206007346545000016632 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp mkdir temp cd temp darcs init touch fee fi fo fum darcs add f* darcs record --author me --all --no-test --name add mkdir d darcs add d darcs mv f* d darcs remove d/fi cd d darcs remove fo echo let us have fun > fun darcs add fun darcs mv fun fum .. darcs record --author me --all --no-test --name mv cd .. if darcs show files | egrep '^./fee$'; then false; else true; fi test ! -f fee darcs show contents d/fee | cmp d/fee - test ! -f fi test -f d/fi if darcs show files | egrep '^./fi$'; then false; else true; fi if darcs show files | egrep '^./d/fi$'; then false; else true; fi test ! -f fo test -f d/fo if darcs show files | egrep '^./fo$'; then false; else true; fi if darcs show files | egrep '^./d/fo$'; then false; else true; fi darcs show contents fun | cmp fun - darcs show contents fum | cmp fum - darcs mv fun d darcs record -A me -a --no-test -m "fun again" darcs show content d/fun | cmp d/fun - test ! -f fun if darcs show files | egrep '^./fun$'; then false; else true; fi # Now clean up. cd .. rm -rf temp darcs-2.14.5/tests/network/0000755000000000000000000000000007346545000013723 5ustar0000000000000000darcs-2.14.5/tests/network/clone-http-packed-detect.sh0000755000000000000000000000175307346545000021040 0ustar0000000000000000#!/usr/bin/env bash # 2011, by Petr Rockai, Guillaume Hoffmann, public domain # Tests that darcs clone --verbose reports getting a pack when there is one, # and does not report when there is none or when --no-packs is passed. . lib skip-formats darcs-1 # compressed repo is darcs-2 gunzip -c $TESTDATA/laziness-complete.tgz | tar xf - cd repo darcs optimize http test -e _darcs/packs/basic.tar.gz test -e _darcs/packs/patches.tar.gz cd .. serve_http # sets baseurl # check that default behaviour is to get packs darcs clone $baseurl/laziness-complete S --verbose |grep "Cloning packed basic repository" # check that it does really not get packs when --no-packs is passed rm -rf S darcs clone $baseurl/laziness-complete S --no-packs --verbose |not grep "Cloning packed basic repository" # check that it does not clam getting packs when there are not rm -rf S rm -rf laziness-complete/_darcs/packs/ darcs clone $baseurl/laziness-complete S --verbose |not grep "Cloning packed basic repository" darcs-2.14.5/tests/network/clone-http-packed.sh0000755000000000000000000000072607346545000017571 0ustar0000000000000000#!/usr/bin/env bash # Written in 2010 by Petr Rockai, placed in public domain . lib skip-formats darcs-1 # compressed repo is darcs-2 gunzip -c $TESTDATA/laziness-complete.tgz | tar xf - cd repo darcs optimize http test -e _darcs/packs/basic.tar.gz test -e _darcs/packs/patches.tar.gz cd .. serve_http # sets baseurl darcs clone --packs $baseurl/laziness-complete S cd S rm _darcs/prefs/sources # avoid any further contact with the original repository darcs check darcs-2.14.5/tests/network/clone-http.sh0000755000000000000000000000270207346545000016340 0ustar0000000000000000#!/usr/bin/env bash # Written in 2010 by Petr Rockai, placed in public domain # This file is included as part of the Darcs test distribution, # which is licensed to you under the following terms: ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R S && mkdir R cd R darcs init echo a > a darcs rec -lam a cd .. serve_http # sets baseurl darcs clone $baseurl/R S cd S darcs pull ../R | tee log grep "No remote" log darcs check darcs-2.14.5/tests/network/clone.sh0000755000000000000000000000066107346545000015365 0ustar0000000000000000#!/usr/bin/env bash . lib check_remote_http http://hub.darcs.net/kowey/tabular rm -rf temp temp2 temp3 #"$DARCS" clone http://hub.darcs.net/kowey/tabular temp darcs clone --lazy http://hub.darcs.net/kowey/tabular temp2 darcs clone --lazy --tag . http://hub.darcs.net/kowey/tabular temp3 cd temp2 darcs obliterate --from-tag . -a darcs pull --tag . -a cd .. diff -u temp2/_darcs/hashed_inventory temp3/_darcs/hashed_inventory darcs-2.14.5/tests/network/external.sh0000755000000000000000000000140707346545000016106 0ustar0000000000000000#!/usr/bin/env bash # Some tests for launching external commands . lib rm -rf temp1 touch_fakessh='./touch-fakessh' if echo $OS | grep -i windows; then touch_fakessh="touch_fakessh.bat" fi export DARCS_SSH=$touch_fakessh export DARCS_SCP=$touch_fakessh export DARCS_SFTP=$touch_fakessh rm -rf 'fakessh' rm -rf 'touch-fakessh' # make our ssh command one word only echo 'echo hello > fakessh' > $touch_fakessh chmod u+x $touch_fakessh # first test the DARCS_SSH environment variable not darcs clone example.com:foo grep hello fakessh rm -f fakessh # now make sure that we don't launch ssh for nothing mkdir temp1 cd temp1 darcs init cd .. darcs clone temp1 > log not grep fakessh log not darcs clone http://darcs.net/nonexistent not grep fakessh log cd .. rm -rf temp1 darcs-2.14.5/tests/network/failing-issue1599-automatically-expire-unused-caches.sh0000755000000000000000000000367707346545000026253 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1599 - 'Automatically expire unused caches' ## ## Copyright (C) 2010 Adolfo Builes ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R S log && mkdir R cd R darcs init echo a > a darcs rec -lam a echo b > b darcs rec -lam b echo c > c darcs rec -lam c cd .. serve_http # sets baseurl darcs clone --lazy $baseurl/R S rm S/_darcs/prefs/sources if [ -z "$http_proxy" ]; then echo "repo:http://10.1.2.3/S" >> S/_darcs/prefs/sources fi echo "repo:$baseurl/dummyRepo" >> S/_darcs/prefs/sources echo "repo:~/test1599/S" >> S/_darcs/prefs/sources echo "repo:$baseurl/R" >> S/_darcs/prefs/sources export DARCS_CONNECTION_TIMEOUT=1 && darcs log --repo S --debug --verbose --no-cache 2>&1 | tee log if [ -z "$http_proxy" ]; then c=`grep -c "URL.waitUrl http://10.1.2.3/S" log` [ $c -eq 1 ] fi c1=`grep -c "URL.waitUrl $baseurl/dummyRepo" log` [ $c1 -eq 2 ] c2=`grep -c "~/test1599/S" log` [ $c2 -eq 1 ] darcs-2.14.5/tests/network/issue1503_prefer_local_caches_to_remote_one.sh0000755000000000000000000000270407346545000024667 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1503 - 'Prefer local caches to remote ones' ## ## Copyright (C) 2010 Adolfo Builes ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib check_remote_http http://darcs.net/testing/repo1 rm -rf S T darcs clone --lazy http://darcs.net/testing/repo1 S darcs tag --repo S -m 2 darcs clone --lazy http://darcs.net/testing/repo1 T darcs pull --repo T S -a --debug --verbose 2>&1 | tee log not grep repo1 log darcs-2.14.5/tests/network/issue1923-cache-warning.sh0000755000000000000000000000373307346545000020443 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1599 - 'Automatically expire unused caches' ## ## Copyright (C) 2010 Adolfo Builes ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib darcs init --repo R cd R echo a > a darcs rec -lam a cd .. serve_http cat < fake-sources repo:$baseurl/dummyRepo repo:/some/bogus/local/path repo:$baseurl/R SOURCES darcs clone --lazy R S1 && cp fake-sources S1/_darcs/prefs/sources darcs clone --lazy R S2 && cp fake-sources S2/_darcs/prefs/sources # make sure we do warn about things that are under your control darcs log --verbose --repo S1 --no-cache 2>&1 | tee log-local c1=`grep -c "$baseurl/dummyRepo" log-local` [ $c1 -eq 1 ] c2=`grep -c "/some/bogus/local/path" log-local` [ $c2 -eq 1 ] # now what about things that aren't? darcs log --verbose --repo $baseurl/S2 --no-cache 2>&1 | tee log-remote c1=`grep -c "$baseurl/dummyRepo" log-remote` [ $c1 -eq 1 ] # always under your control not grep -c "/some/bogus/local/path" log-remote darcs-2.14.5/tests/network/issue1932-remote.sh0000755000000000000000000000364607346545000017233 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue1932 - "darcs add -qr ." should not break on files with colons ## ## Copyright(C) 2010 Dmitry Astapov ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. . sshlib # Colons could be in repo names and in file name. # Colon in repo name is an indication of special case - remote repo. # Colon in the file could be there under unix and requires no special treatment. # Repo name with ':' is either scp repo or http repo. # Let's check scp repo first. ( darcs clone user@invalid:path || true ) > log 2>&1 [ -n "$(fgrep 'ssh: Could not resolve hostname invalid: Name or service not known' log)" ] # HTTP repo ( http_proxy= darcs clone http://www.bogus.domain.so.it.will.surely.fail.com || true ) 2>&1 | tee log egrep 'CouldNotResolveHost|host lookup failure' log # local repos are tested by tests/issue1932-colon-breaks-add.sh darcs-2.14.5/tests/network/issue2090-transfer-mode.sh0000755000000000000000000000332007346545000020467 0ustar0000000000000000#!/usr/bin/env bash ## Test for darcs transfer-mode ## ## Copyright (C) 2012 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. # echo 'Comment this line out and run the script by hand'; exit 200 # . $(dirname $0)/../lib # . $(dirname $0)/sshlib . lib . sshlib # Clean up after previous remote runs ${SSH} ${REMOTE} "\ rm -rf ${REMOTE_DIR}; \ mkdir ${REMOTE_DIR}; \ " # Set up a repo to test darcs init --repo R cd R touch f g darcs add f g darcs record f g -a --ignore-times -m 'add some files' -A moi darcs clone . $REMOTE:$REMOTE_DIR/R cd .. darcs clone $REMOTE:$REMOTE_DIR/R S --debug > log 2>&1 COUNT=$(grep -c '^Exec.*darcs.*transfer-mode' log) # with issue2090, this was 6! test $COUNT -eq 1 darcs-2.14.5/tests/network/issue2545_command-execution-via-ssh-uri.sh0000755000000000000000000000406107346545000023577 0ustar0000000000000000#!/usr/bin/env bash ## Test for issue2545 - Argument smuggling in SSH repository URLs ## ## Darcs allows (almost) arbitrary command execution via a crafted ssh ## URI. ## When pushing to a remote repo, darcs is invoked on the remote server ## via ssh. This use of ssh is different from the ones tested by the ## not-networked test. Also, I'm not sure how (if) it can be exploited, ## so I'm just checking for the debug message. Pretty lame test, I know. ## ## Copyright (C) 2017 Gian Piero Carrubba ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. . sshlib # Load ssh helpers. init_remote_repo R # Create our test repos. darcs init --repo R # cd R echo "text" > file # Modify the working dir darcs record -lam "First Patch" # Record the changes check="\"${SSH}\" \"--\" \"${REMOTE}\" \"darcs apply --all --debug --repodir '${REMOTE_DIR}/R'\"" darcs push -a --debug "${REMOTE}":"${REMOTE_DIR}"/R 2>&1 >/dev/null | \ fgrep "$check" darcs-2.14.5/tests/network/lazy-clone.sh0000755000000000000000000000075707346545000016350 0ustar0000000000000000#!/usr/bin/env bash . lib check_remote_http http://hub.darcs.net/kowey/tabular rm -rf temp temp2 temp3 darcs clone --lazy http://hub.darcs.net/kowey/tabular temp darcs clone --lazy temp temp2 rm -rf temp cd temp2 test ! -f _darcs/patches/0000005705-178beaf653578703e32346b4d68c8ee2f84aeef548633b2dafe3a5974d763bf2 darcs log -p 'Initial version' -v | cat test -f _darcs/patches/0000005705-178beaf653578703e32346b4d68c8ee2f84aeef548633b2dafe3a5974d763bf2 cd .. rm -rf temp temp2 temp3 darcs-2.14.5/tests/network/log.sh0000755000000000000000000000121307346545000015040 0ustar0000000000000000#!/usr/bin/env bash . lib check_remote_http http://darcs.net # Demonstrates issue385 and others darcs log --repo=http://darcs.net GNUmakefile --last 300 # Test things mentioned in issue2461: # no _darcs should remain test ! -d _darcs # go to a directory where we have no write access # (I dearly hope nobody tries to run the tests as root!) cd / # and try again (with less patches to fetch) darcs log --repo=http://darcs.net GNUmakefile --last 3 # an absolute path should give an error not darcs log --repo=http://darcs.net /GNUmakefile --last 3 # also test that it works without any filename arguments darcs log --repo=http://darcs.net --last 1 darcs-2.14.5/tests/network/show_tags-remote.sh0000755000000000000000000000317007346545000017552 0ustar0000000000000000#!/usr/bin/env bash ## Test for show tags --repo ## ## Copyright (C) 2010 Eric Kow ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. darcs init --repo S cd R echo 'Example content.' > f darcs record -lam 'Add f' darcs tag 't0' darcs tag 't1' darcs show tags | grep t0 cd .. serve_http # sets baseurl cd S darcs log --repo ../R darcs show tags --repo ../R | grep t0 darcs show tags --repo $baseurl/R | grep t0 cd .. darcs show tags --repo R | grep t0 darcs show tags --repo $baseurl/R | grep t0 darcs-2.14.5/tests/network/ssh.sh0000755000000000000000000000634507346545000015067 0ustar0000000000000000#!/bin/bash # echo 'Comment this line out and run the script by hand'; exit 200 # . $(dirname $0)/../lib # . $(dirname $0)/sshlib . lib . sshlib # ================ Setting up remote repositories =============== ${SSH} ${REMOTE} " rm -rf ${REMOTE_DIR} mkdir ${REMOTE_DIR} cd ${REMOTE_DIR} mkdir testrepo; cd testrepo darcs init echo moi > _darcs/prefs/author touch a; darcs add a darcs record --skip-long-comment a --ignore-times -am 'add file a' echo 'first line' > a darcs record --skip-long-comment a --ignore-times -am 'add first line to a' cd .. darcs clone testrepo testrepo-pull cd testrepo-pull echo moi > _darcs/prefs/author touch b; darcs add b; darcs record --skip-long-comment b --ignore-times -am 'add file b' echo 'other line' > b; darcs record --skip-long-comment b --ignore-times -am 'add other line to b' cd .. darcs clone testrepo testrepo-push darcs clone testrepo testrepo-send " # ================ Settings =============== echo ${DARCS_SSH_FLAGS} echo ${DARCS_SSH} echo ${DARCS_SCP} echo ${DARCS_SFTP} # ================ Checking darcs clone ================== darcs clone ${DARCS_SSH_FLAGS} ${REMOTE}:${REMOTE_DIR}/testrepo ${DARCS_SSH_FLAGS} # check that the test repo made it over [ -d testrepo ] [ -d testrepo/_darcs ] [ -f testrepo/a ] # if the above test is disabled we just init a blank repo # so that the other tests can continue if [ ! -d testrepo ]; then mkdir testrepo cd testrepo darcs init cd .. fi # ================ Checking darcs pull ================= darcs clone ${DARCS_SSH_FLAGS} testrepo testrepo-pull cd testrepo-pull echo yyy | darcs pull ${DARCS_SSH_FLAGS} ${REMOTE}:${REMOTE_DIR}/testrepo-pull # see if the changes got pulled over grep "other line" b cd .. # ================ Checking darcs push and send =================" darcs clone ${DARCS_SSH_FLAGS} testrepo testrepo-push cd testrepo-push echo moi > _darcs/prefs/author echo "second line" >> a darcs record --skip-long-comment a --ignore-times -am "add second line to a" touch c; darcs add c darcs record --skip-long-comment --ignore-times -am "add file c" c echo yyy | darcs push ${DARCS_SSH_FLAGS} ${REMOTE}:${REMOTE_DIR}/testrepo-push # check that the file c got pushed over ${SSH} ${REMOTE} "[ -f ${REMOTE_DIR}/testrepo-push/c ]" echo yyy | darcs send --no-edit-description ${DARCS_SSH_FLAGS} ${REMOTE}:${REMOTE_DIR}/testrepo-send -o mybundle.dpatch # check that the bundle was created grep "add file c" mybundle.dpatch cd .. # ================ Checking darcs clone to ssh destination ==================" cd testrepo darcs clone . ${DARCS_SSH_FLAGS} ${REMOTE}:${REMOTE_DIR}/testrepo-clone # check that the clone was successful ${SSH} ${REMOTE} "[ -d ${REMOTE_DIR}/testrepo-clone/_darcs ]" ${SSH} ${REMOTE} "[ -f ${REMOTE_DIR}/testrepo-clone/a ]" cd .. # ======== Checking push over ssh with a conflict =========" ${SSH} ${REMOTE} "echo apply no-allow-conflicts >> ${REMOTE_DIR}/testrepo-clone/_darcs/prefs/defaults" cd testrepo echo moi > _darcs/prefs/author echo 'change for remote' > a darcs record --skip-long-comment --ignore-times -am 'change for remote' darcs push -a darcs ob --last 1 -a echo 'change for local' > a darcs record --skip-long-comment --ignore-times -am 'change for local' darcs push -a > log 2>&1 || : grep -q 'conflicts options to apply' log cd .. darcs-2.14.5/tests/network/sshlib0000755000000000000000000000143707346545000015142 0ustar0000000000000000if [ x${REMOTE_DIR} = x ]; then REMOTE_DIR=/tmp/darcs-ssh-test$$ fi if [ x"${USE_PUTTY}" != x ]; then DARCS_SSH=plink export DARCS_SSH DARCS_SCP=pscp export DARCS_SCP DARCS_SFTP=psftp export DARCS_SFTP fi if [ x"${USE_CONTROL_MASTER}" != x ]; then DARCS_SSH_FLAGS="--ssh-cm" export DARCS_SSH_FLAGS fi if [ x"${DARCS_SSH}" = x ]; then SSH=ssh else SSH=${DARCS_SSH} fi if [ x${REMOTE} = x ]; then REMOTE=$(whoami)@localhost fi init_remote_repo() { repodir="${1:-R}" ${SSH} ${REMOTE} \ "rm -rf '${REMOTE_DIR}' && mkdir '${REMOTE_DIR}' && \ cd '${REMOTE_DIR}' && darcs init --repo '$repodir' --$format" } # test if we can connect via ssh, otherwise skip test ${SSH} -x -o=NumberofPasswordPrompts=0 ${REMOTE} true || exit 200 # vim: syntax=sh: darcs-2.14.5/tests/nodeps.sh0000755000000000000000000000357007346545000014066 0ustar0000000000000000#!/usr/bin/env bash . ./lib # Test the --no-deps option with Send, Push, Pull, Obliterate and Unrecord. # # Create four patches with dependencies. # file 'f': patch 'fa' and 'fb' # file 'g': patch 'ga' and 'gb' # The 'b' patches depend on the 'a' patches. rm -rf tmp1 mkdir tmp1 cd tmp1 darcs init echo 'record no-ask-deps' >> _darcs/prefs/defaults echo 'record ignore-times' >> _darcs/prefs/defaults echo 'a' > f darcs add f darcs rec -am 'fa' f echo 'a' > g darcs add g darcs rec -am 'ga' g echo 'b' > f darcs rec -am 'fb' f echo 'b' > g darcs rec -am 'gb' g mkdir d darcs init --repodir d # Try to Send all 'b' and 'g' patches. The two 'g' patches should succeed, # but the 'fb' patch depends on the unselected 'fa' patch, an should be # skipped. darcs send -o bundle -a -p '[bg]' --no-deps d grep '^\[ga$' bundle grep '^\[fb$' bundle && exit 1 # Try to Push all 'b' and 'g' patches. Expect same result as for Send. darcs push -a -p '[bg]' --no-deps d cd d darcs changes | grep '^ \* ga$' darcs changes | grep '^ \* fb$' && exit 1 # stay in d !! # Try to Pull all 'b' and 'g' patches. Expect same result as for Send. # already in d rm -rf *; darcs init darcs pull -a -p '[bg]' --no-deps .. darcs changes | grep '^ \* ga$' darcs changes | grep '^ \* fb$' && exit 1 cd .. # Try to Obliterate all 'a' and 'g' patches. The two 'g' patches should # succeed, but the 'fa' patch depends on the unselected 'fb' patch, an # should be skipped. darcs get . tmp; cd tmp echo y/y/y/q | tr / \\012 | darcs obliterate -p '[ag]' --no-deps darcs changes | grep '^ \* gb$' && exit 1 darcs changes | grep '^ \* fa$' cd .. # Try to Unrecord all 'a' and 'g' patches. Expect same result as for # Obliterate. # in "top" tmp repo -- destroys it! echo y/y/y/q | tr / \\012 | darcs unrecord -p '[ag]' --no-deps darcs changes | grep '^ \* gb$' && exit 1 darcs changes | grep '^ \* fa$' cd .. rm -rf tmp1 darcs-2.14.5/tests/nonewline.sh0000755000000000000000000000051007346545000014563 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 mkdir temp1 temp2 cd temp1 darcs init echo -n zig > foo darcs add foo sleep 1 darcs record -a -m add_foo -A x #sleep 1 echo -n zag >> foo darcs record --ignore-time -a -m mod_foo -A x cd ../temp2 darcs init darcs pull -a ../temp1 cd .. cmp temp1/foo temp2/foo rm -rf temp1 temp2 darcs-2.14.5/tests/obliterate.sh0000755000000000000000000000323207346545000014723 0ustar0000000000000000#!/usr/bin/env bash . ./lib # Part 1 rm -rf temp1 darcs initialize temp1 cd temp1 echo hello world > foo darcs record -l -a -m hellofoo echo goodbye world >> foo darcs record -a -m goodbyefoo darcs replace world bar foo echo Hi there foo > bar darcs record -l -a -m addbar darcs mv bar baz darcs replace bar baz foo darcs record -a -m bar2baz echo Do not love the baz, or anything in the baz. >> foo darcs record -a -m nolove darcs mv baz world darcs replace baz world foo darcs record -a -m baz2world not darcs whatsnew grep 'love the world' foo echo yy | darcs obliterate -p baz2world not darcs whatsnew grep 'love the baz' foo echo yy | darcs obliterate -p bar2baz grep 'love the bar' foo echo yy | darcs obliterate -p nolove grep 'love' foo && exit 1 || true cd .. rm -rf temp1 # Part 2 darcs init temp1 cd temp1 touch a.txt darcs add a.txt darcs record -a -m 'adding a' a.txt touch b.txt darcs add b.txt darcs record -a -m 'adding b' b.txt # extra confirmation for --all echo an | darcs obliterate -p add | grep -i "really obliterate" # --last=1 echo nyy | darcs obliterate --last 1 | grep -i adding # automatically getting dependencies date >> a.txt darcs record -a -m 'modifying a' a.txt echo ny | darcs obliterate -p 'adding a' > log grep -i "modifying a" log grep -i "No patches selected" log cd .. rm -rf temp1 # Part 3 darcs init temp1 cd temp1 echo foo > foo darcs record -l -a -m 'addfoo' darcs obliterate -a not darcs whatsnew cd .. rm -rf temp1 # Part 4 darcs init temp1 cd temp1 cat > f < f < foo # Unrecorded change darcs optimize upgrade darcs check grep hashed _darcs/format not grep darcs-2 _darcs/format darcs whatsnew | grep 'hunk ./foo 1' cd .. rm -rf old hashed ## issue1248 - darcs doesn't handle darcs 1 repos with compressed ## inventories gunzip -c $TESTDATA/oldfashioned-compressed.tgz | tar xf - cd oldfashioned-compressed darcs optimize upgrade darcs check cd .. rm -rf oldfashioned-compressed darcs-2.14.5/tests/optimize.sh0000755000000000000000000000053107346545000014430 0ustar0000000000000000#!/usr/bin/env bash . ./lib # tests for "darcs optimize" rm -rf temp1 mkdir temp1 cd temp1 darcs init touch foo darcs add foo darcs record -a -m add_foo darcs optimize reorder| grep -i "done" cd .. rm -rf temp1 ## issue2388 - optimize fails if no patches have been recorded darcs init temp1 cd temp1 darcs optimize clean cd .. rm -rf temp1 darcs-2.14.5/tests/optimize_relink.sh0000755000000000000000000000253507346545000016002 0ustar0000000000000000 #!/usr/bin/env bash # For issue600, testing optimize --relink . ./lib ## We don't support hard links on Windows. if echo $OS | grep -i windows; then echo darcs does not support hard links on Windows exit 0 fi ## compare succeeds if there are hard links compare () { echo 'use File::Basename; $res=0; while ($fn=<'$1'/*>) { $fn2="'$2'/" . basename($fn); @fd1=lstat($fn); @fd2=lstat($fn2); $res += ($fd1[1] != $fd2[1]);}; exit($res);' | perl } rm -rf temp mkdir temp cd temp mkdir x darcs init --repodir x cd x date > foo darcs add foo darcs record -a -A me -m 'addfoo' cd .. ## Does the filesystem support hard linking at all? mkdir z1 echo "hi" > z1/foo mkdir z2 if ! ln z1/foo z2/foo ; then echo No ln command for `pwd` - assuming no hard links. exit 0 fi if ! compare z1 z2 ; then echo Filesystem for `pwd` does not support hard links. exit 0 fi # workaround for SunOS cp which does not support `-a' option but also # doesn't fail when it is encountered. cp -r x y ## Now try relinking using darcs. rm -rf z darcs optimize relink --verbose --repodir x --sibling y rm -rf x/_darcs/patches/pend* y/_darcs/patches/pend* if compare x/_darcs/patches y/_darcs/patches then echo darcs optimize relink is working, hard links were done. else echo darcs optimize relink is not working, it did not make any hard links. exit 2 fi cd .. rm -rf temp darcs-2.14.5/tests/output.sh0000755000000000000000000000244007346545000014131 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 temp3 mkdir temp2 cd temp2 darcs init cd .. mkdir temp1 cd temp1 darcs init touch foo bar darcs add foo bar darcs record -a -m foobar -A author darcs send --no-minimize -a --dont-edit-description -o ../temp3 ../temp2 test -f ../temp3 darcs send --no-minimize -a --dont-edit-description -o ../temp2/patchfile ../temp2 test -f ../temp2/patchfile mkdir subdir darcs send --no-minimize -a --dont-edit-description -o subdir/../../temp2/patchfile1 ../temp2 test -f ../temp2/patchfile1 cp ../temp3 correct cd subdir darcs send --no-minimize -a --dont-edit-description -o ../patchfile ../../temp2 diff -u ../patchfile ../correct rm ../patchfile darcs send --no-minimize -a --set-default --dont-edit-description -o - ../../temp2 > ../patchfile grep -v Creating ../patchfile | diff -u ../correct - darcs apply --repodir=../../temp2 --dry-run ../patchfile > out cat out grep foobar out cd ../.. cd temp2 darcs apply --dry-run ../temp3 > out cat out grep foobar out darcs apply --dry-run ../temp1/correct > out cat out grep foobar out darcs apply --dry-run ../temp1/patchfile > out cat out grep foobar out darcs apply --dry-run ../temp3 > out cat out grep foobar out darcs apply --dry-run ../temp3 > out cat out grep foobar out cd .. rm -rf temp1 temp2 temp3 darcs-2.14.5/tests/overriding-defaults.sh0000755000000000000000000000271407346545000016552 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp mkdir temp cd temp darcs init darcs setpref test false darcs record --no-test -a -m 'add failing test' # should fail when test is run not darcs test # should pass with --no-test in defaults echo record --no-test > _darcs/prefs/defaults touch a darcs record -alm a touch b not darcs record --test -alm b # should fail with --test in defaults echo record --test > _darcs/prefs/defaults touch c not darcs record -alm c touch d darcs record --no-test -alm d # check global defaults cp ~/.darcs/defaults defaults.backup trap "cp defaults.backup ~/.darcs/defaults" EXIT rm _darcs/prefs/defaults # --no-test works in global defaults echo record --no-test > ~/.darcs/defaults touch e darcs record -alm e touch f not darcs record --test -alm f # --test works in global defaults echo record --test > ~/.darcs/defaults touch g not darcs record -alm g touch h darcs record --no-test -alm h # Verify that per-repository defaults override global defaults # --no-test in repository defaults overrides global --test echo record --test > ~/.darcs/defaults echo record --no-test > _darcs/prefs/defaults touch i darcs record -alm i touch j not darcs record --test -alm j # --test in repository defaults overrides global --no-test echo record --no-test > ~/.darcs/defaults echo record --test > _darcs/prefs/defaults touch k not darcs record -alm k touch l darcs record --no-test -alm l trap - EXIT cp defaults.backup ~/.darcs/defaults cd .. rm -rf temp darcs-2.14.5/tests/patch-index-annotate.sh0000755000000000000000000000130507346545000016603 0ustar0000000000000000. lib rm -rf R darcs init --repo R cd R echo 'revision 1' > f darcs record -lam 'p1' echo 'revision 2' > f darcs record -am 'p2' echo 'revision 3' > f darcs record -am 'p3' darcs annotate f > out # creates patch index on annotate grep p3 out not grep p2 out not grep p1 out darcs annotate f --patch 'p2' > out grep p2 out not grep p3 out not grep p1 out darcs annotate f --patch 'p1' > out grep p1 out not grep p2 out not grep p3 out darcs optimize disable-patch-index darcs annotate f > out grep p3 out not grep p2 out not grep p1 out darcs annotate f --patch 'p2' > out grep p2 out not grep p3 out not grep p1 out darcs annotate f --patch 'p1' > out grep p1 out not grep p2 out not grep p3 out darcs-2.14.5/tests/patch-index-creation.sh0000755000000000000000000000614007346545000016600 0ustar0000000000000000#!/usr/bin/env bash ## Test for patch index automation - Patch index should ## be recreated when running: ## * annotate on a file or directory ## * non-interative log on a file ## * init, clone and convert with flag --with-patch-index ## ## It should NOT be created when running: ## * annotate or log with --no-patch-index ## * init, clone and convert, without flags ## ## Copyright (C) 2012 BSRK Aditya, Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R cd R darcs show patch-index | grep 'Patch Index is not yet created.' # init cd .. rm -rf R darcs init --repo R --with-patch-index cd R darcs show patch-index | grep 'Patch Index is in sync with repo.' # init --patch-index cd .. rm -rf S darcs clone R S cd S darcs show patch-index | grep 'Patch Index is not yet created.' # clone cd .. rm -rf S darcs clone R S --with-patch-index cd S darcs show patch-index | grep 'Patch Index is in sync with repo.' # clone --patch-index cd .. rm -rf repo repo2 gunzip -c $TESTDATA/simple-v1.tgz | tar xf - echo 'I understand the consequences of my action' | darcs convert darcs-2 repo repo2 cd repo2 darcs show patch-index | grep 'Patch Index is not yet created.' # convert cd .. rm -rf repo repo2 gunzip -c $TESTDATA/simple-v1.tgz | tar xf - echo 'I understand the consequences of my action' | darcs convert darcs-2 repo repo2 --with-patch-index cd repo2 darcs show patch-index | grep 'Patch Index is in sync with repo.' # convert --patch-index cd ../R mkdir d echo 'New line.' >> d/f darcs record -lam "Change d/f" rm -rf _darcs/patch_index darcs annotate d/f darcs show patch-index | grep 'Patch Index is in sync with repo.' # annotate rm -rf _darcs/patch_index darcs annotate d/f --no-patch-index darcs show patch-index | grep 'Patch Index is not yet created.' # annotate --no-patch-index rm -rf _darcs/patch_index darcs log -a d/f darcs show patch-index | grep 'Patch Index is in sync with repo.' # log -a file rm -rf _darcs/patch_index darcs log -a d/f --no-patch-index darcs show patch-index | grep 'Patch Index is not yet created.' # log -a file --no-patch-index cd .. darcs-2.14.5/tests/patch-index-enabled-and-disabled.sh0000755000000000000000000000443007346545000020673 0ustar0000000000000000#!/usr/bin/env bash ## Test for patch index self-healing after used non-patch-index-enabled darcs ## Copyright (C) 2012 Mark Stosberg ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R --with-patch-index cd R #Record some example content echo 'Example content.' > f darcs record -lam 'create file.' # Simulate use by an older darcs binary, by backup in the index and disabling patch index. mv _darcs/patch_index _darcs/patch_index.bak touch _darcs/no_patch_index # Now record Some new changes. echo 'Example content updated.' > f echo 'Example content updated.' > f2 darcs record -lam 'Update by older darcs.' # Now return the repo to the state that the patch-index-enabled darcs would see it. rm _darcs/no_patch_index mv _darcs/patch_index.bak _darcs/patch_index # Now, perform an action with the this darcs. ( and make sure we see the changes from the older darcs. ) darcs changes f | grep 'older darcs' # Now, check: Did the patch-index self heal? darcs show patch-index | grep 'Patch Index is in sync with repo.' # Another check, just to be sure. echo 'Example content updated again.' > f darcs record -lam 'Another update by newer darcs' # Still good? darcs show patch-index | grep 'Patch Index is in sync with repo.' # Clean up. cd .. rm -rf R darcs-2.14.5/tests/patch-index-log.sh0000755000000000000000000000245507346545000015562 0ustar0000000000000000. lib rm -rf R darcs init --repo R cd R [[ $(darcs log FOO --count | tail -n 1) -eq 0 ]] touch f0 darcs record -lam 'p0' mkdir d1 darcs record -lam 'p1' touch d1/f1 darcs record -lam 'p2' darcs move f0 d1/f0 darcs record -am 'p3' touch d1/f2 darcs record -lam 'p4' rm d1/f1 darcs record -am 'p5' darcs move d1/f0 f0 darcs record -am 'p6' darcs move d1 d2 darcs record -am 'p7' mkdir d1 darcs record -lam 'p8' touch d1/f3 darcs record -lam 'p9' echo "f0" > f0 darcs record -am 'p10' # log on directories gives all patches # that touched any sub path (including itself) # Note that the path of the directory varies # as you move backward in history. # The sub path comparision is with the path # the directory had when the patch which is is being # tested has been just applied. # d1 <-> p8-p9 [[ $(darcs log d1 --count | tail -n 1) -eq 2 ]] for i in 8 9 do darcs log d1 | grep p$i done # d2 <-> p1-p7 [[ $(darcs log d2 --count | tail -n 1) -eq 7 ]] for i in {1..7} do darcs log d2 | grep p$i done darcs optimize disable-patch-index [[ $(darcs log FOO --count | tail -n 1) -eq 0 ]] [[ $(darcs log d1 --count | tail -n 1) -eq 2 ]] for i in 8 9 do darcs log d1 | grep p$i done [[ $(darcs log d2 --count | tail -n 1) -eq 7 ]] for i in {1..7} do darcs log d2 | grep p$i done darcs-2.14.5/tests/patch-index-released.sh0000755000000000000000000000267507346545000016571 0ustar0000000000000000#!/usr/bin/env bash # Check that the latest darcs can still use the patch index # produced by released versions. . lib # A tarball of a repo with a v2 patch index, which at the # time of writing was the version in use in the last released # version of darcs. tar -xz < $TESTDATA/patch-index-v2.tgz cd pi # If darcs can't read the index but thinks it can, this will crash. # If there's a new patch index format and the format version has # been properly bumped, then darcs will simply delete and replace it # and this command will work. darcs annotate file1.txt # It would be nice to check that the released version of darcs also # correctly handles any changes we make, but it's much harder to write # a test that relies on the released version. # When a change is made to the patch index format, the # format version should be bumped and a new sample repo should be # added to this test, to ensure that the new format is properly # covered by the tests as soon as it is released. # The "released" version above should be kept to maintain the # guard against regressions. # If further changes to the format are made before the next release, # it should be ok to keep the same (new) version, though it might # mean developers/people using the bleeding edge see some breakage. # Once the release happens, it should be ok to delete the test for # the old format, on the assumption we are unlikely to make a gross # mistake like decrementing the format version. darcs-2.14.5/tests/patch-index-rename.sh0000755000000000000000000000260407346545000016244 0ustar0000000000000000#!/usr/bin/env bash ## Test that the patch index passes its self-test on a repository ## with a rename. ## ## Copyright (C) 2014 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib mkdir R cd R darcs init --with-patch-index echo initial contents > file1 darcs rec -lam "initial" darcs mv file1 file2 darcs rec -am "move" darcs show patch-index --verbose darcs-2.14.5/tests/patch-index-spans.sh0000755000000000000000000000451507346545000016124 0ustar0000000000000000#!/usr/bin/env bash ## Test for patch index integrity of spans - ## ## Copyright (C) YEAR AUTHOR ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R --with-patch-index # Create our test repos. cd R mkdir d e # Change the working tree. echo 'Example content.' > d/f darcs record -lam 'Add d/f and e.' darcs show patch-index --verbose > pi grep -F "./d -> 1#./d" pi grep -F "./d/f -> 1#./d/f" pi grep -F "./e -> 1#./e" pi grep -F "1#./d -> ./d" pi grep -F "1#./d/f -> ./d/f" pi grep -F "1#./e -> ./e" pi darcs mv d/f e/ darcs record -am 'Move d/f to e/f.' darcs show patch-index --verbose > pi grep -F "./d -> 1#./d" pi grep -F "./d/f -> 1#./d/f" pi grep -F "./e -> 1#./e" pi grep -F "./e/f -> 1#./d/f" pi grep -F "1#./d -> ./d" pi grep -F "1#./d/f -> ./e/f" pi grep -F "1#./d/f -> ./d/f" pi grep -F "1#./e -> ./e" pi echo 'File 2' > d/f darcs record -lam 'Add d/f' darcs show patch-index --verbose > pi grep -F "./d -> 1#./d" pi grep -F "./d/f -> 2#./d/f" pi grep -F "./d/f -> 1#./d/f" pi grep -F "./e -> 1#./e" pi grep -F "./e/f -> 1#./d/f" pi grep -F "1#./d -> ./d" pi grep -F "1#./d/f -> ./e/f" pi grep -F "1#./d/f -> ./d/f" pi grep -F "2#./d/f -> ./d/f" pi grep -F "1#./e -> ./e" pi darcs-2.14.5/tests/patch-index-sync.sh0000755000000000000000000000527707346545000015762 0ustar0000000000000000#!/usr/bin/env bash ## Test for patch index automation - ## ## Copyright (C) 2012 BSRK Aditya ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R S darcs init --repo R --with-patch-index darcs init --repo S --with-patch-index cd R darcs show patch-index | grep 'Patch Index is in sync with repo.' # test init mkdir d e echo 'Example content.' > d/f darcs record -lam 'Add d/f and e.' darcs show patch-index | grep 'Patch Index is in sync with repo.' # test record echo 'New line.' >> d/f echo "y" | darcs amend-record -p 'Add d/f and e.' -a darcs show patch-index | grep 'Patch Index is in sync with repo.' # test amend-record darcs push -a ../S cd ../S darcs show patch-index | grep 'Patch Index is in sync with repo.' # test push echo 'Changed Content' > d/f darcs record -am 'Change d/f' darcs show patch-index | grep 'Patch Index is in sync with repo.' # test record 2 darcs send -ao test.dpatch ../R cd .. darcs clone R T --with-patch-index cd T darcs show patch-index | grep 'Patch Index is in sync with repo.' # test clone darcs pull -a ../S darcs show patch-index | grep 'Patch Index is in sync with repo.' # test pull darcs obliterate -p 'Add d/f and e.' -a darcs show patch-index | grep 'Patch Index is in sync with repo.' # test obliterate cd ../R darcs apply -a ../S/test.dpatch darcs show patch-index | grep 'Patch Index is in sync with repo.' # test apply darcs unrecord -a -p 'Change d/f' darcs show patch-index | grep 'Patch Index is in sync with repo.' # test unrecord darcs tag -m 'tag R' darcs show patch-index | grep 'Patch Index is in sync with repo.' # test tag cd .. rm -rf R S T darcs-2.14.5/tests/pending.sh0000755000000000000000000000106207346545000014214 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp temp_0 mkdir temp cd temp darcs init date > bla darcs add bla darcs record -a --name=11 echo hello > world darcs add world darcs whatsnew --dont-look-for-adds > wn1 cd .. darcs get temp cd temp_0 date > bla2 date >> bla darcs add bla2 darcs record -a --name=22 darcs push -a ../temp cd .. cd temp darcs whatsnew --dont-look-for-adds > wn2 diff wn1 wn2 darcs record -a -m 'cleaning up for new test.' date > foo.jpg darcs add foo.jpg darcs whatsnew darcs remove foo.jpg darcs whatsnew && exit 1 cd .. rm -rf temp temp0 darcs-2.14.5/tests/pending_has_conflicts.sh0000755000000000000000000000162707346545000017122 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 mkdir temp1 cd temp1 darcs init date > date.t date > date_moved.t write_buggy_pending () { cat > _darcs/patches/pending <&1 | tee out grep 'pending has conflicts' out echo pending should now be fixed but there are no changes not darcs whatsnew write_buggy_pending darcs revert -a 2>&1 | tee out grep 'pending has conflicts' out echo pending should now be emptied darcs revert -a write_buggy_pending not darcs record -a -m foo 2>&1 | tee out grep 'pending has conflicts' out darcs changes -v darcs repair 2>&1 | tee out grep 'The repository is already consistent' out write_buggy_pending darcs repair 2>&1 | tee out grep 'The repository is already consistent' out cd .. rm -rf temp1 darcs-2.14.5/tests/perms.sh0000755000000000000000000000120307346545000013713 0ustar0000000000000000#!/usr/bin/env bash . ./lib uname | grep "MINGW" > /dev/null && exit 0 rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init echo record author me > _darcs/prefs/defaults echo ALL all >> _darcs/prefs/defaults echo ALL verbose >> _darcs/prefs/defaults echo ALL ignore-times >> _darcs/prefs/defaults touch foo darcs add foo darcs record -m add_foo echo hello >> foo darcs record -m mod_foo cd .. darcs get --repo-name temp2 temp1 cd temp2 cp ../temp1/_darcs/prefs/defaults _darcs/prefs echo y/d/y | tr / \\012 | darcs unpull --interactive test -f foo -a ! -s foo chmod +x foo test -x foo darcs pull ../temp1 test -x foo cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/posthook.sh0000755000000000000000000000222607346545000014441 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 mkdir temp1 cd temp1 darcs init touch foo darcs add foo # Check that posthook works... darcs whatsnew -s --posthook 'touch posthook-ran' test -f posthook-ran rm posthook-ran # Check that posthook works with defaults... echo ALL --posthook touch posthook-ran > _darcs/prefs/defaults darcs whatsnew -s test -f posthook-ran rm posthook-ran cd .. rm -rf temp1 # POSIX-only section # ---------------------------------------------------------------------- # Things below this section do not appear to work on Windows. # Pending further investigation at http://bugs.darcs.net/issue1813 if echo $OS | grep -i windows; then exit 0 fi # Check that DARCS_PATCHES_XML works rm -rf R S # another script may have left a mess darcs init --repo R # Create our test repos. darcs init --repo S # Create our test repos. cd R echo 'echo $DARCS_PATCHES_XML' > hook darcs record -lam 'hook' chmod u+x hook cat > _darcs/prefs/defaults << END apply run-posthook apply posthook ./hook END cd .. cd S echo 'Example content.' > f darcs record -lam 'Add f' darcs push -a ../R | grep 'patch author' cd .. darcs-2.14.5/tests/prefs.sh0000755000000000000000000000053007346545000013706 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs initialize echo ALL ignore-times >> _darcs/prefs/defaults cp _darcs/prefs/boring .boring darcs add .boring darcs setpref boringfile .boring darcs record -a -m p1 -A me cd .. darcs get temp1 temp2 cmp temp1/_darcs/prefs/prefs temp2/_darcs/prefs/prefs rm -rf temp1 temp2 darcs-2.14.5/tests/prefs_binary.sh0000755000000000000000000000065407346545000015261 0ustar0000000000000000#!/usr/bin/env bash # Test that _darcs/prefs/binaries . lib rm -rf temp1 mkdir temp1 cd temp1 darcs init mkdir d touch d/t.t darcs add d/t.t darcs record -am "initial record" echo 'some change' >> d/t.t echo ny | darcs record --interactive > log # pre-test: plain text files are not binary not grep binary log echo 'd/t' >> _darcs/prefs/binaries echo ny | darcs record --interactive > log grep binary log cd .. rm -rf temp1 darcs-2.14.5/tests/prehook.sh0000755000000000000000000000063107346545000014240 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 mkdir temp1 cd temp1 darcs init touch foo darcs add foo # Check that prehook runs darcs whatsnew -s --prehook 'touch prehook-ran' test -f prehook-ran rm prehook-ran # Check that --prehook works with defaults... echo ALL --prehook touch prehook-ran > _darcs/prefs/defaults darcs whatsnew -s test -f prehook-ran rm prehook-ran echo Successful. cd .. rm -rf temp1 darcs-2.14.5/tests/printer.sh0000755000000000000000000001050407346545000014254 0ustar0000000000000000#!/usr/bin/env bash # Some tests for 'darcs printer (the output formating)' . lib mkdir temp1 cd temp1 darcs init touch a darcs add a darcs rec -a -m add env # clear all output formating environment variables for e in DARCS_DONT_ESCAPE_ISPRINT DARCS_USE_ISPRINT\ DARCS_ESCAPE_8BIT\ DARCS_DONT_ESCAPE_EXTRA DARCS_ESCAPE_EXTRA\ DARCS_DONT_ESCAPE_TRAILING_SPACES\ DARCS_DONT_COLOR DARCS_ALWAYS_COLOR DARCS_ALTERNATIVE_COLOR\ DARCS_DONT_ESCAPE_ANYTHING; do unset $e done env # make sure the locale is c export LC_ALL=C test_line () { rm -f a echo $1 > a darcs whatsnew | grep -F $2 } # First check escaping and coloring. Use whatsnew, since that is the # most common use of escapes. # test the defaults # - no color to pipe # - don't escape 7-bit ASCII printables, \n,\t and space (we can't test \n) # - escape control chars with ^ # - escape other chars with \xXX test_line " !#%&',-0123456789:;<=>"\ " !#%&',-0123456789:;<=>" test_line "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"\ "ABCDEFGHIJKLMNOPQRSTUVWXYZ_" test_line "\`abcdefghijklmnopqrstuvwxyz"\ "\`abcdefghijklmnopqrstuvwxyz" test_line "\t\"\$()*+./?\@[\\]^{|}"\ "\t\"\$()*+./?\@[\\]^{|}" # skip ^@ and ^Z since they make darcs treat the file as binary # don't put any space control chars at end of line # ascii control chars are escaped with ^ test_line $(printf '\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0D\x0E')\ '[_^A_][_^B_][_^C_][_^D_][_^E_][_^F_][_^G_][_^H_][_^K_][_^L_][_^M_][_^N_]' test_line $(printf '\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19')\ '[_^O_][_^P_][_^Q_][_^R_][_^S_][_^T_][_^U_][_^V_][_^W_][_^X_][_^Y_]' test_line $(printf '\x1B') '[_^[_]' test_line $(printf '\x1C') '[_^\_]' test_line $(printf '\x1D') '[_^]_]' test_line $(printf '\x1E') '[_^^_]' test_line $(printf '\x1F') '[_^__]' # everything up to here is escaped by default; # for the rest we must explicitly set it: export DARCS_ESCAPE_8BIT=1 test_line $(printf '\x7F') '[_^?_]' # other chars are escaped with test_line $(printf '\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F')\ '[__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__]' test_line $(printf '\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F')\ '[__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__]' test_line $(printf '\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF')\ '[__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__]' test_line $(printf '\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF')\ '[__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__]' test_line $(printf '\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF')\ '[__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__]' test_line $(printf '\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF')\ '[__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__]' test_line $(printf '\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF')\ '[__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__]' test_line $(printf '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF')\ '[__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__]' darcs-2.14.5/tests/pull-dont-prompt-deps.sh0000755000000000000000000000131607346545000016760 0ustar0000000000000000#!/usr/bin/env bash . ./lib # Check that the right patches get pulled using --dont-prompt-for-dependencies rm -rf temp1 rm -rf temp2 mkdir temp2 mkdir temp1 cd temp2 darcs init cd .. cd temp1 darcs init echo foo > f darcs record -Ax -alm foo1 echo bar > b darcs rec -Ax -alm bar1 echo foo2 > f darcs record -Ax -alm foo2 echo bar2 > b darcs record -Ax -alm bar2 cd ../temp2 echo yy | darcs pull ../temp1 -i --dont-prompt-for-dependencies -p foo2 --dry-run > toto #on the previous line, we get asked about foo2, and we take it grep foo2 toto | wc -l | grep 2 #we don't get asked about foo1, but we take it anyway, so grep foo1 toto | wc -l | grep 1 #and we don't send bar not grep bar toto cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/pull-reorder.sh0000755000000000000000000000226707346545000015214 0ustar0000000000000000#!/usr/bin/env bash ## Test that pull --reorder moves to the top the uncommon set of patches between ## the current repository and remote repository which we are pulling. . lib # Load some portability helpers. check_patches_order () { darcs changes | tr -d "\n" | grep $1.*$2.*$3 } test_init () { rm -rf R1 R2 darcs init "R1" cd R1 touch "r1_0" darcs add "r1_0" darcs record -a --author=me -m "Adding r1_0" "r1_0" cd .. darcs clone "R1" "R2" cd R2 touch "r2_0" darcs add "r2_0" darcs record -a --author=me -m "Adding r2_0" "r2_0" cd .. cd R1 touch "r1_1" darcs add "r1_1" darcs record -a --author=me -m "Adding r1_1" "r1_1" cd .. } test_init cd R1 darcs pull -a -p "r2_0" "../R2" # Without reorder the expected order is r2_0, r1_1, r1_0 . check_patches_order r2_0 r1_1 r1_0 # Test that pull --reorder reorders even if there is nothing to pull. darcs pull -a --reorder -p "r2_0" "../R2" check_patches_order r1_1 r2_0 r1_0 cd .. test_init cd R1 darcs pull -a --reorder -p "r2_0" "../R2" # With reorder the expected order is r1_1, r2_0, r1_0 . check_patches_order r1_1 r2_0 r1_0 cd .. darcs-2.14.5/tests/pull.sh0000755000000000000000000001426507346545000013555 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 temp2 darcs init temp1 cd temp1 cd .. darcs init temp2 cd temp2 mkdir one cd one mkdir two cd two # darcs pull should work relative to the current directory darcs pull -a ../../../temp1 | grep -i 'No remote patches to pull in' # darcs pull should pull into repo specified with --repo cd ../.. # now in temp2 darcs add one; darcs record --name uno --all cd .. # now outside of any repo darcs pull --set-default --repodir temp1 --all temp2 | grep -i 'Finished pulling.' # temp2 is not relative to temp1 # set up server repo date > temp2/one/date.t darcs add --repodir ./temp2 one/date.t darcs record --repodir ./temp2 -a -m foo # set up client repo for failure if echo $OS | grep -i windows; then echo this test does not work on windows because it echo is not possible to chmod -r elif whoami | grep root; then echo root never gets permission denied else chmod a-rwx ./temp1/one # remove all permissions not darcs pull --repodir ./temp1 -a 2> err chmod u+rwx temp1/one # restore permission grep 'permission denied' err rm -rf temp1/one fi cd temp1 echo Before trying to pull from self, defaultrepo is something else not grep temp1 _darcs/prefs/defaultrepo #return special message when you try to pull from yourself DIR="`pwd`" not darcs pull --debug -a "$DIR" 2> out grep 'Can.t pull from current repository' out not darcs pull --debug -a . 2> out grep 'Can.t pull from current repository' out # and do not update the default repo to be the current di not grep temp1 _darcs/prefs/defaultrepo rm -f _darcs/prefs/defaultrepo not darcs pull 2> err grep 'please specify one' err echo . > _darcs/prefs/defaultrepo not darcs pull --debug 2> err grep 'Can.t pull from current repository' err not darcs pull --debug ../* 2> out not grep 'Can.t pull from current repository' out cd .. # now outside of any repo cd temp1 echo a > foo darcs record -lam AA echo b > foo darcs record -lam BB echo c > foo darcs record -lam CC darcs rollback -p CC -a darcs record -am unC cd .. rm -rf temp2 darcs get --to-patch B temp1 temp2 cd temp2 sleep 1 # So that rollback won't have same timestamp as get. darcs rollback -p BB -a darcs record -am unB darcs pull -a ../temp1 2> err2 not grep 'Error applying patch' err2 cd .. cd temp1 echo -n foo > baz darcs add baz darcs record -am newbaz cd ../temp2 darcs pull -a | grep Finished echo -n bar > baz darcs record -am bazbar cd ../temp1 darcs pull ../temp2 -a echo -n bar > correct_baz diff baz correct_baz cd .. # my $test_name = "when a patch creating a directory is attempted to be applied # while a directory with that name already exists, a warning is raised, but # the pull succeeds."; mkdir temp1/newdir cd temp1 darcs add newdir darcs record -am newdir cd ../temp2 mkdir newdir darcs pull -a --set-default ../temp1 &> out2 grep Backing out2 grep 'Finished pulling' out2 grep newdir out2 cd .. rm -rf temp1 temp2 # issue662, which triggered: # darcs failed: Error applying hunk to file ./t.t # Error applying patch to the working directory. darcs init temp1 cd temp1 touch t.t echo 'content'> t.t darcs record -lam 'initial add' echo 'content: remote change'> t.t darcs record -am 'remote change' --ignore cd .. darcs clone temp1 temp2 cd temp2 darcs obliterate --last 1 --all echo 'content: local change'> t.t darcs pull -a ../temp1 darcs w -s darcs revert -a cd .. rm -rf temp1 temp2 # pull with conflicts darcs initialize temp1 cd temp1 echo foo > bar darcs record -lam addbar cd .. darcs clone temp1 temp2 cd temp1 date > bar darcs record -a -m datebar cd ../temp2 echo aack >> bar darcs record -a -m aackbar darcs pull -a darcs check cd .. rm -rf temp1 temp2 # pull --union rm -rf temp1 temp2 temp3 darcs init temp1 cd temp1 echo A > A darcs record -lam A echo B > B darcs record -lam B cd .. darcs clone temp1 temp2 cd temp2 darcs obliterate --last 1 -a echo C > C darcs record -lam C cd .. darcs init temp3 cd temp3 darcs pull -a ../temp1 ../temp2 darcs log > out grep A out grep B out grep C out cd .. rm -rf temp1 temp2 temp3 # pull --intersection darcs init temp1 cd temp1 echo A > A darcs record -lam Aismyname echo B > B darcs record -lam Bismyname cd .. darcs clone temp1 temp2 cd temp2 darcs obliterate --last 1 -a echo C > C darcs record -lam Cismyname cd .. darcs init temp3 cd temp3 darcs pull -a --intersection ../temp1 ../temp2 darcs log > out grep Aismyname out not grep Bismyname out not grep Cismyname out cd .. rm -rf temp1 temp2 temp3 # pull --skip-conflicts rm -rf R S darcs init R cd R echo 'foo' > foo echo 'bar' > bar darcs rec -lam 'Add foo and bar' cd .. darcs clone R S cd R echo 'foo2' > foo darcs rec -lam 'Change foo (2)' echo 'bar2' > bar darcs rec -lam 'Change bar (2)' cd .. cd S echo 'foo3' > foo darcs rec -lam 'Change foo (3)' darcs pull --skip-conflicts -a ../R test `darcs log --count` -eq 3 cd .. cd S darcs pull -a ../R test `darcs log --count` -eq 4 cd .. rm -rf R S # bad pending after pull rm -fr temp1 temp2 darcs init temp1 cd temp1 echo abc > A echo def > B1 darcs record -lam patch1 darcs mv B1 B2 darcs record -am patch2 cd .. darcs init temp2 cd temp2 darcs pull -a ../temp1 not darcs whatsnew cd .. rm -fr temp1 temp2 # issue494: note that in this test, we deliberately select filenames # with a backwards sorting order darcs init temp1 cd temp1 echo abc > b darcs record -lam patch1 darcs mv b a echo def > a darcs record -am patch2 cd .. darcs init temp2 cd temp2 darcs pull --all ../temp1 not darcs whatsnew cd .. rm -fr temp1 temp2 # pull binary rm -rf temp1 temp2 darcs init temp1 cd temp1 printf "%01048576d" 0 > foo darcs record -l -a -m xx rm foo darcs record -a -m yy cd .. darcs init temp2 cd temp2 echo yny | darcs pull --set-default ../temp1 rm foo darcs pull -a cd .. rm -rf temp1 temp2 # pull --matches darcs init temp1 cd temp1 echo first > a darcs record -lam 'first' firsthash=`darcs log --xml | grep 'hash=' | sed -e "s/.*hash='//" -e "s/'>//"` echo second > b darcs record -lam 'second' cd .. darcs init temp2 darcs pull --repodir temp2 -a --match "hash $firsthash" temp1 test $(darcs log --count --repodir temp2) -eq 1 darcs init temp3 darcs pull --repodir temp3 -a --hash $firsthash temp1 test $(darcs log --count --repodir temp3) -eq 1 rm -rf temp1 temp2 temp3 darcs-2.14.5/tests/pull_complement.sh0000755000000000000000000000724707346545000016002 0ustar0000000000000000#!/usr/bin/env bash ## Public domain 2007 Kevin Quick ## ## This file is included as part of the Darcs test distribution, ## which is licensed to you under the following terms: ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib rm -rf temp1 temp2 temp3 temp4 temp5 mkdir temp1 cd temp1 cat > foo < foo.tmp mv foo.tmp foo darcs record -a --ignore-times -m "$2" } cd temp1 chgrec 's/line2/line2\nline2.1\nline2.2/' inssub2 chgrec 's/line4/Line 4/' Line4 darcs changes | grep ' \*' echo done with changes on temp1 > /dev/null cd .. darcs get temp1 temp2 darcs get temp1 temp3 cd temp1 chgrec 's/line1/line0\nline1/' line0 chgrec 's/Line 4/LINE FOUR/' LINE4 chgrec 's/line7/line7\nLastLine/' LastLine chgrec 's/LINE FOUR/LINE FOUR\nline4.1/' line4.1 darcs changes | grep ' \*' echo done with changes on temp1 > /dev/null cd ../temp3 darcs pull -p LastLine -av chgrec 's/line1$/FirstLine/' FirstLine cd ../temp4 darcs changes | grep ' \*' echo done with changes on temp4 > /dev/null darcs pull ../temp1 --dry-run | grep ' \*' darcs pull ../temp1 --dry-run | grep ' \*' > p1.out cat > p1.req < p2.out diff p1.out p2.out darcs pull --dry-run --complement ../temp1 ../temp2 | grep ' \*' > p3.out cat > p3.req < p4.out cat > p4.req < p5.out diff p4.out p5.out darcs pull --dry-run --complement ../temp1 ../temp2 ../temp3 ../temp2 ../temp2 ../temp3 ../temp3 ../temp2 | grep ' \*' > p6.out diff p4.out p6.out darcs pull --dry-run --complement ../temp3 ../temp2 | grep ' \*' > p7.out cat > p7.req < p8.out grep "No remote patches to pull in!" p8.out # because duplicates are stripped before performing action, # this is the same as: darcs pull ../temp1 darcs pull --dry-run --complement ../temp1 ../temp1 > fooout cat fooout grep ' \*' fooout > p9.out diff p1.req p9.out # so the "null" pull must be tested this way: darcs get ../temp1 ../temp5 darcs pull --dry-run --complement ../temp1 ../temp5 > p9.out grep "No remote patches to pull in!" p9.out darcs pull -av --complement ../temp1 ../temp3 darcs check cd .. rm -rf temp1 temp2 temp3 temp4 temp5 darcs-2.14.5/tests/push-dry-run.sh0000755000000000000000000000077207346545000015154 0ustar0000000000000000#!/usr/bin/env bash . ./lib # For issue855: wish: avoid taking lock if using --dry-run chmod -R u+w temp2 || : rm -rf temp1 temp2 darcs init temp1 darcs init temp2 cd temp2 touch x darcs record -lam test cd .. chmod -R u-w temp2 cd temp2 # need to capture this failure so that we can still # chmod -R u+w the directory even if we fail darcsexit=0 darcs push --dry-run ../temp1 || darcsexit=$? cd .. chmod -R u+w temp2 # so that other scripts can cleanup if [ $darcsexit -ne 0 ]; then exit $darcsexit fi darcs-2.14.5/tests/push.sh0000755000000000000000000000407307346545000013554 0ustar0000000000000000#!/usr/bin/env bash # Some tests for 'darcs push' . lib slash() { if echo $OS | grep -q -i windows; then echo -n \\ else echo -n / fi } DIR="`pwd`" rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init cd .. mkdir temp2 cd temp2 darcs init cd .. # push without a repo gives an error cd temp1 not darcs push -p 123 2> log grep -i 'No default repository to push to' log cd .. mkdir -p temp2/one/two cd temp2/one/two # darcs push should work relative to the current directory darcs push -a ../../../temp1 | grep -i 'No recorded local patches to push' cd ../../../ # darcs push should push into repo specified with --repo cd temp2 darcs add one darcs record --name uno --all cd .. darcs push --repodir temp2 --all temp1 | grep -i 'Finished apply' cd temp1 # Before trying to pull from self, defaultrepo does not exist test ! -e _darcs/prefs/defaultrepo # return special message when you try to push to yourself not darcs push -a "$DIR`slash`temp1" 2> log grep -i "cannot push from repository to itself" log # and don't update the default repo to be the current dir test ! -e _darcs/prefs/defaultrepo cd .. rm -rf temp1 temp2 # Check that the right patches get pushed using --dont-prompt-for-dependencies rm -rf temp1 temp2 darcs init temp2 darcs init temp1 cd temp1 echo foo > f darcs record -alm foo1 echo bar > b darcs rec -alm bar1 echo foo2 > f darcs record -alm foo2 echo bar2 > b darcs record -alm bar2 echo yy | darcs push ../temp2 --dont-prompt-for-dependencies -p foo2 --dry-run -i > toto #on the previous line, we get asked about foo2, and we take it grep foo2 toto | wc -l | grep 2 #we don't get asked about foo1, but we take it anyway, so grep foo1 toto | wc -l | grep 1 #and we don't send bar not grep bar toto cd .. rm -rf temp1 temp2 # For issue257: push => incorrect return code when couldn't get lock rm -rf temp1 temp2 darcs init temp1 cd temp1 echo foo > foo.c darcs rec -alm init cd .. darcs clone temp1 temp2 cd temp2 echo server >> foo.c darcs rec -alm server cd ../temp1 echo client >> foo.c darcs rec -alm client not darcs push -a ../temp2 cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/rebase-amend.sh0000755000000000000000000000263507346545000015122 0ustar0000000000000000#!/bin/sh -e ## ## Test that amend doesn't leave the rebase in a bad state ## ## Copyright (C) 2012 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init echo 'wibble' > wibble darcs rec -lam 'wibble' echo 'wobble' > wibble darcs rec -am 'wobble' echo 'yd' | darcs rebase suspend echo 'wubble' > wibble echo 'ya' | darcs amend-record darcs checkdarcs-2.14.5/tests/rebase-apply.sh0000755000000000000000000000413207346545000015155 0ustar0000000000000000#!/bin/sh -e ## ## Basic test of rebase apply ## ## Copyright (C) 2011-2014 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R1 R2 R3 mkdir R1 cd R1 darcs init echo '1' > foo darcs rec -lam "add foo" cd .. darcs get R1 R2 cd R2 echo '2' > foo darcs rec -am "2" darcs send -a -o 2.dpatch ../R1 cd .. darcs get R1 R3 cd R3 echo '3' > foo darcs rec -am "3" echo '4' > foo darcs rec -am "4" # TODO: figure out behaviour of --all and test it # (should it answer 'yes' to both pulling and suspending? echo yyy | darcs rebase apply -a ../R2/2.dpatch darcs changes --count 2>&1 | grep "Rebase in progress: 2 suspended patches" echo yny | darcs rebase unsuspend | grep "We have conflicts" cat > expected < foo echo yyy | darcs amend --patch '3' echo yy | darcs rebase unsuspend | grep "We have conflicts" cat > expected < foo echo yyy | darcs amend --patch '4' cd .. darcs-2.14.5/tests/rebase-basic.sh0000755000000000000000000000264707346545000015122 0ustar0000000000000000#!/bin/sh -e ## ## Basic test of rebase ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init echo 'wibble' > wibble darcs rec -lam "add wibble" echo 'yy' | darcs rebase suspend 2>&1 | grep-once "Rebase in progress: 1 suspended patch" not test -f wibble echo 'yy' | darcs rebase unsuspend | grep-once "Rebase finished" test -f wibble darcs-2.14.5/tests/rebase-count.sh0000755000000000000000000000261107346545000015160 0ustar0000000000000000#!/bin/sh -e ## ## Test that patches are counted properly when a rebase is in progress ## ## Copyright (C) 2015 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init echo 'wibble' > wibble darcs rec -lam 'wibble' echo 'wobble' > wibble darcs rec -am 'wobble' echo 'yd' | darcs rebase suspend darcs log --last 1 | grep wibble darcs-2.14.5/tests/rebase-keeps-deps-on-amend.sh0000755000000000000000000000435007346545000017566 0ustar0000000000000000#!/usr/bin/env bash ## ## Check that explicit dependencies are preserved during rebase ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf t1 mkdir t1 cd t1 darcs init echo 'A' > A darcs add A darcs rec -am"A" --ignore-times echo 'B' > B darcs add B darcs rec -am"B" --ignore-times echo 'C' > C darcs add C echo 'yyy' | darcs rec -am"C" --ignore-times --ask-deps echo 'yyd' | darcs rebase suspend echo 'A2' > A echo 'y' | darcs amend -a echo 'yyy' | darcs rebase unsuspend darcs unpull --patch 'A' --no-deps | grep "No patches selected" darcs unpull --patch 'B' --no-deps | grep "No patches selected" # repeat the test with a tag darcs unpull --patch 'C' -a darcs tag T # two stages because suspend stops at clean tags # might need to change back to one stage if this changes echo 'yy' | darcs rebase suspend echo 'yd' | darcs rebase suspend echo 'yyy' | darcs rebase unsuspend # this offers 'T', seems to be a bug in darcs unpull --no-deps # darcs unpull --patch 'A' --no-deps | grep "No patches selected" darcs unpull --match 'not name T' | grep "No patches selected" darcs unpull --patch 'B' --no-deps | grep "No patches selected"darcs-2.14.5/tests/rebase-keeps-deps.sh0000755000000000000000000000430007346545000016065 0ustar0000000000000000#!/usr/bin/env bash ## ## Check that explicit dependencies are preserved during rebase ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf t1 mkdir t1 cd t1 darcs init echo 'A' > A darcs add A darcs rec -am"A" --ignore-times echo 'B' > B darcs add B darcs rec -am"B" --ignore-times echo 'C' > C darcs add C echo 'yyy' | darcs rec -am"C" --ignore-times --ask-deps echo 'yydy' | darcs rebase suspend echo 'yyy' | darcs rebase unsuspend darcs unpull --patch 'A' --no-deps | grep "No patches selected" darcs unpull --patch 'B' --no-deps | grep "No patches selected" # repeat the test with a tag darcs unpull --patch 'C' -a darcs tag T # two stages because suspend stops at clean tags # might need to change back to one stage if this changes echo 'yy' | darcs rebase suspend echo 'yd' | darcs rebase suspend echo 'yyy' | darcs rebase unsuspend # this offers 'T', seems to be a bug in darcs unpull --no-deps # darcs unpull --patch 'A' --no-deps | grep "No patches selected" darcs unpull --match 'not name T' | grep "No patches selected" darcs unpull --patch 'B' --no-deps | grep "No patches selected"darcs-2.14.5/tests/rebase-move-2.sh0000755000000000000000000000307407346545000015141 0ustar0000000000000000#!/usr/bin/env bash ## ## Check that rebase handles amended-in moves ## ## Copyright (C) 2012 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R darcs init --repo R cd R echo 'wibble' > wibble darcs rec -lam "add" darcs mv wibble wobble darcs rec -am "rename" echo 'wobble' > wobble darcs rec -am "edit" echo 'yyd' | darcs rebase suspend darcs mv wibble wobble echo 'yyy' | darcs amend echo 'yd' | darcs rebase obliterate echo 'yy' | darcs rebase unsuspend not darcs wh darcs-2.14.5/tests/rebase-move.sh0000755000000000000000000000316207346545000015000 0ustar0000000000000000#!/usr/bin/env bash ## ## Check that rebase merges moves without conflicts ## ## Copyright (C) 2010 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf t1 mkdir t1 cd t1 darcs init echo 'wibble' > wibble darcs add wibble darcs rec -am"wibble" --ignore-times echo 'wobble' > wibble darcs rec -am"wobble" --ignore-times echo 'yd' | darcs rebase suspend darcs mv wibble wobble echo 'y' | darcs amend -a --patch 'wibble' # there shouldn't be any conflicts echo 'yy' | darcs rebase unsuspend # | not grep "We have conflicts" not darcs wh darcs-2.14.5/tests/rebase-nochanges.sh0000755000000000000000000000404707346545000016002 0ustar0000000000000000#!/bin/sh -e ## ## Test that having a rebase in progress doesn't impact ## the UI of other darcs commands. ## ## At the time of writing, rebase was represented by ## a special internal patch and so this test is specifically ## aimed at checked that this patch is not presented in the UI ## Even if this changes, it is still worth having tests of ## the general principle that normal commands should still ## work as usual. ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init echo 'wibble' > wibble darcs rec -lam "add wibble" echo 'yy' | darcs rebase suspend darcs changes --count | grep 0 darcs unpull --dry-run | grep "No patches selected!" echo 'wobble' > wobble darcs rec -lam "add wobble" -A tester darcs changes --count | grep 1 cat > expected <&1 | grep "Rebase finished" test -f wibble darcs-2.14.5/tests/rebase-obliterate.sh0000755000000000000000000000270707346545000016170 0ustar0000000000000000#!/bin/sh -e ## ## Test of rebase obliterate ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init echo 'wibble' > wibble darcs rec -lam "add wibble" echo 'wobble' > wobble darcs rec -lam "add wobble" echo 'yyy' | darcs rebase suspend echo 'yd' | darcs rebase obliterate echo 'yy' | darcs rebase unsuspend | grep 'Rebase finished' test -f wobble not test -f wibble darcs-2.14.5/tests/rebase-pull-reorder.sh0000755000000000000000000000136507346545000016451 0ustar0000000000000000#!/usr/bin/env bash . lib # Load some portability helpers. check_patches_order () { darcs changes | tr -d "\n" | grep $1.*$2.*$3 } test_init () { rm -rf R1 R2 darcs init "R1" cd R1 touch "r1_0" darcs add "r1_0" darcs record -a --author=me -m "Adding r1_0" "r1_0" cd .. darcs clone "R1" "R2" cd R2 touch "r2_0" darcs add "r2_0" darcs record -a --author=me -m "Adding r2_0" "r2_0" darcs send --author=me -a --no-edit-description -o ../R1/P cd .. cd R1 touch "r1_1" darcs add "r1_1" darcs record -a --author=me -m "Adding r1_1" "r1_1" cd .. } test_init cd R1 darcs rebase pull -a --reorder ../R2 check_patches_order r1_1 r2_0 r1_0 cd .. darcs-2.14.5/tests/rebase-pull-tag.sh0000755000000000000000000000306707346545000015563 0ustar0000000000000000#!/usr/bin/env bash ## ## Check that you can pull tags into a repo with rebase in progress ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf t1 mkdir t1 cd t1 darcs init touch a darcs add a darcs rec -am"a" darcs tag a cd .. rm -rf t2 mkdir t2 cd t2 darcs init touch b darcs add b darcs rec -am"b" echo 'yy' | darcs rebase suspend darcs pull -a ../t1 darcs check darcs changes # because darcs check doesn't complain about a corrupt rebase state :-( darcs-2.14.5/tests/rebase-pull.sh0000755000000000000000000000405207346545000015005 0ustar0000000000000000#!/bin/sh -e ## ## Basic test of rebase pull ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R1 R2 R3 mkdir R1 cd R1 darcs init echo '1' > foo darcs rec -lam "add foo" cd .. darcs get R1 R2 cd R2 echo '2' > foo darcs rec -am "2" cd .. darcs get R1 R3 cd R3 echo '3' > foo darcs rec -am "3" echo '4' > foo darcs rec -am "4" # TODO: figure out behaviour of --all and test it # (should it answer 'yes' to both pulling and suspending? echo yyy | darcs rebase pull -a ../R2 darcs changes --count 2>&1 | grep "Rebase in progress: 2 suspended patches" echo yny | darcs rebase unsuspend | grep "We have conflicts" cat > expected < foo echo yyy | darcs amend --patch '3' echo yy | darcs rebase unsuspend | grep "We have conflicts" cat > expected < foo echo yyy | darcs amend --patch '4' cd .. darcs-2.14.5/tests/rebase-remote.sh0000755000000000000000000000347707346545000015336 0ustar0000000000000000#!/bin/sh -e ## ## Test that remote operations on rebase-in-progress repos fail ## or ignore the rebase patch ## ## Copyright (C) 2012-3 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R1 R2 R3 R4 mkdir R1 cd R1 darcs init echo '1' > foo darcs rec -lam "add foo" echo '2' > foo darcs rec -am "change foo" echo yny | darcs rebase suspend cd .. not darcs get R1 R2 mkdir R3 cd R3 darcs init not darcs pull -a ../R1 2>&1 | grep "Cannot transfer patches from a repository where a rebase is in progress" cd .. mkdir R4 cd R4 darcs init cd ../R1 darcs push -a ../R4 cd ../R4 not darcs rebase unsuspend cd .. mkdir R5 cd R5 darcs init cd ../R1 darcs send -a ../R5 -o bundle.dpatch not grep "DO NOT TOUCH" bundle.dpatch grep "add foo" bundle.dpatch not grep "change foo" bundle.dpatch cd .. darcs-2.14.5/tests/rebase-repull.sh0000755000000000000000000000254507346545000015341 0ustar0000000000000000#!/bin/sh -e ## ## Repulling a suspended patch ## ## Copyright (C) 2012 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init echo 'wibble' > wibble darcs rec -lam "add wibble" cd .. darcs get R R2 cd R echo 'yy' | darcs rebase suspend darcs pull -a ../R2 echo 'yy' | darcs rebase obliterate darcs-2.14.5/tests/rebase-skip-conflicts.sh0000755000000000000000000000312007346545000016754 0ustar0000000000000000#!/bin/sh -e ## ## Test of rebase unsuspend --skip-conflicts ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init cat > foo < foo < foo < foo < foo-expected < wibble darcs add wibble darcs rec -am"wibble" --ignore-times echo 'yy' | darcs rebase suspend darcs tag 'ugh' darcs check darcs changes # because darcs check doesn't complain about a corrupt rebase state :-( darcs-2.14.5/tests/rebase-unsuspend-to-patch.sh0000755000000000000000000000273607346545000017601 0ustar0000000000000000#!/bin/sh -e ## ## Test rebase unsuspend --to-patch ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init touch foo darcs rec -lam 'add foo' touch bar darcs rec -lam 'add bar' touch baz darcs rec -lam 'add baz' echo 'yyyy' | darcs rebase suspend darcs rebase unsuspend --to-patch 'bar' -a darcs changes | grep 'add foo' darcs changes | grep 'add bar' darcs changes | not grep 'add baz' darcs-2.14.5/tests/rebase-warns-lost-deps.sh0000755000000000000000000000337507346545000017102 0ustar0000000000000000#!/usr/bin/env bash ## ## Check that lost explicit dependencies are reported on during rebase ## ## Copyright (C) 2015 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf t1 mkdir t1 cd t1 darcs init echo 'A' > A darcs add A darcs rec -am"patch A" --ignore-times echo 'B' > B darcs add B darcs rec -am"patch B" --ignore-times echo 'C' > C darcs add C echo 'yyy' | darcs rec -am"patch C" --ignore-times --ask-deps echo 'ydy' | darcs rebase suspend darcs unpull -a -p 'patch A' echo 'ydy' | darcs rebase unsuspend > unsuspend-output.txt grep "following explicit dependency" unsuspend-output.txt grep "patch A" unsuspend-output.txt not grep "patch B" unsuspend-output.txt darcs-2.14.5/tests/record.sh0000755000000000000000000001116307346545000014051 0ustar0000000000000000#!/usr/bin/env bash # Some tests for 'darcs record ' . lib rm -rf temp1 mkdir temp1 cd temp1 darcs init # issue308 - no patches and no deps for record should abort darcs record -am foo --ask-deps | grep -i "Ok, if you don't want to record anything, that's fine!" # RT#476 - --ask-deps works when there are no patches if echo $OS | grep -i windows; then echo This test does not work on Windows else touch t.f darcs add t.f darcs record -am add echo a | darcs record -am foo --ask-deps | grep -i 'finished recording' fi # RT#231 - special message is given for nonexistent directories not darcs record -am foo not_there.txt > log 2>&1 grep -i 'non-existing' log # RT#231 - a nonexistent file before an existing file is handled correctly # test disabled, see tests/issue2494-output-of-record-with-file-arguments.sh # which contains an updated test # touch b.t # darcs record -lam foo a.t b.t > log # grep -i 'WARNING:.*a.t' log # grep -iv 'WARNING:.*b.t' log DIR="`pwd`" touch date.t darcs add date.t darcs record -a -m foo "$DIR/date.t" | grep -i 'finished recording' # issue396 - record -l "" touch 'notnull.t' darcs record -am foo -l "" notnull.t | grep -i 'finished recording' # basic record date >> date.t darcs record -a -m basic_record date.t | grep -i 'finished recording' # testing --logfile date >> date.t echo "second record\n" >> log.txt darcs record -a -m 'second record' --logfile=log.txt date.t | grep -i 'finished recording' # refuse empty patch name export DARCS_EDITOR="cat -n" date >> date.t echo "patchname" | darcs record -a -m "" | grep WARNING date >> date.t darcs record -a -m "some name" cd .. rm -rf temp1 # record race rm -rf foo1 foo2 mkdir foo1 foo2 cd foo1 darcs init echo zig > foo darcs add foo sleep 1 darcs record -a -m add_foo -A x #sleep 1 echo zag >> foo darcs record --ignore-time -a -m mod_foo -A x cd ../foo2 darcs init darcs pull -a ../foo1 cd .. cmp foo1/foo foo2/foo rm -rf foo1 foo2 # record interactive rm -rf temp1 mkdir temp1 cd temp1 darcs init touch foo darcs add foo darcs record -a -m addfoo darcs replace one two foo darcs replace three four foo darcs replace five six foo echo sa | darcs record -m cancelled darcs whatsnew darcs changes > ch not grep cancelled ch cd .. rm -rf temp1 # Some tests for 'darcs rec --edit-long-comment' rm -rf temp1 export DARCS_EDITOR="cat -n" # editor: space in command mkdir temp1 cd temp1 darcs init touch file.t darcs add file.t echo y | darcs record --edit-long-comment -a -m foo file.t | grep '# Please enter' cd .. rm -rf temp1 # editor: space in path mkdir temp2\ dir cd temp2\ dir darcs init touch file.t darcs add file.t echo y | darcs record --edit-long-comment -a -m foo file.t | grep '# Please enter' cd .. rm -rf temp2\ dir # make sure summaries are coalesced mkdir temp3 cd temp3 darcs init cat > file < file < test-command << FOO #!/bin/sh echo EVIL FOO chmod u+x test-command echo y | darcs record --logfile='; test-command' --edit-long-comment -a -m foo file.t > log not grep EVIL log cd .. rm -rf temp1 ## Test for issue142 - darcs record --logfile foo should not darcs init temp1 cd temp1 touch f g touch log darcs record -alm f --logfile log f not darcs record -alm g --logfile missing g cd .. rm -rf temp1 ## Test for issue1845 - darcs record f, for f a removed file should work ## Public domain - 2010 Petr Rockai darcs init temp1 cd temp1 echo 'Example content.' > f darcs rec -lam "first" rm -f f echo ny | darcs record f 2>&1 | tee log not grep "None of the files" log cd .. rm -rf temp1 # issue1472 - "darcs record ./foo" shouldn't even TRY to read ./bar darcs init temp1 mkdir temp1/d/ echo 'Example content.' >temp1/f echo 'Similar content.' >temp1/d/f chmod 0 temp1/f # Make temp1/f unreadable darcs record --repo temp1 -lam 'Only changes to temp1/d/.' d rm -rf temp1 # issue1871 - `darcs record .` should work for tracked changes # in a subdirectory even if the subdirectory itself is not known yet. darcs init temp1 cd temp1 mkdir d echo 'Example content.' > d/f darcs add d/f echo ny | darcs record echo ny | darcs record . > log not grep "None of the files" log cd .. rm -rf temp1 darcs-2.14.5/tests/remove.sh0000755000000000000000000000401107346545000014062 0ustar0000000000000000#!/usr/bin/env bash ## ## Copyright (C) 2009 Roman Plasil ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R S # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R mkdir d e # Change the working tree. mkdir d/f d/f/g echo 'Example content.' > d/f/1.txt echo 'Example content.' > d/f/g/2.txt echo 'Example content.' > e/3.txt darcs add -r . darcs wh -s > before.lst grep -i d before.lst grep -i e before.lst grep -i d/f before.lst darcs remove -r d darcs wh -s > after.lst not grep -i d after.lst not grep -i d/f after.lst not grep -i d/f/g after.lst not grep -i d/f/g/2.txt after.lst not grep -i d/f/1.txt after.lst cd .. rm -rf temp1 # issue1765 recursive remove on root darcs init temp1 cd temp1 mkdir d e # Change the working tree. echo 'Example content.' > d/f darcs record -lam 'Add d/f and e.' darcs remove * -r cd .. rm -rf temp1 darcs-2.14.5/tests/rename_shouldnt_affect_prefixes.sh0000755000000000000000000000340307346545000021175 0ustar0000000000000000#!/usr/bin/env bash ## Renaming a -> b should not affect any filenames with prefix b, when looking ## for the original name of the files in changes --xml, or when annotating. ## ## Copyright (C) 2012 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R darcs init --repo R cd R echo -e 'a\nb\nc' > a cp a bb darcs rec -alm 'Add a bb' darcs move a b darcs rec -am 'Move a -> b' darcs changes --xml b bb > changes.xml grep "original_name='./a'" < changes.xml # Ensure we've not used a prefix of the filename for the move. not grep "original_name='./ab'" < changes.xml # Ensure that we are able to annotate bb (if the rename has affected bb # internally, we'll not be able to annotate the file) darcs annotate bb | not grep unknown darcs-2.14.5/tests/renames.sh0000755000000000000000000000231407346545000014223 0ustar0000000000000000#!/usr/bin/env bash ## Test various renames ## ## Copyright (C) 2014 Owen Stephens ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE . lib rm -rf R && darcs init --repo R cd R runghc $TESTBIN/renameHelper.hs darcs-2.14.5/tests/repair.sh0000755000000000000000000000570607346545000014063 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 darcs init temp1 cd temp1 echo ALL ignore-times >> _darcs/prefs/defaults echo A1 > foo mkdir d echo A2 > d/bar darcs record -lam AA echo B > foo darcs record -lam BB echo C > foo darcs record -lam CC for i in _darcs/pristine*; do echo Empty the pristine directory: $i rm -rf $i mkdir $i done darcs repair cd .. rm -rf temp1 # issue1977: repair complains when there is no pristine.hashed directory darcs init temp1 cd temp1 echo "a" > a darcs rec -lam a rm -rf _darcs/pristine.hashed/ darcs repair cd .. rm -rf temp1 # check that repair doesn't do anything to a clean repository darcs init temp1 cd temp1 touch baz darcs record -lam moo darcs repair | grep 'already consistent' cd .. rm -rf temp1 # test that we can repair incorrect adds darcs init temp1 cd temp1 echo foo > file mkdir dir darcs rec -lam 'initial' # produce a corrupt addfile patch echo 'addfile ./file' > _darcs/patches/pending echo 'yny' | darcs rec -m 're-add file' not darcs check darcs repair darcs check # produce a corrupt adddir patch echo 'adddir ./dir' > _darcs/patches/pending echo 'yy' | darcs rec -m 're-add dir' not darcs check darcs repair darcs check cd .. rm -rf temp1 # test for repair of a corrupt repository darcs init temp1 cd temp1 echo foo > bar darcs rec -lam 'foo' echo hey > foo darcs rec -lam 'more foo' hashed=false test -e _darcs/hashed_inventory && hashed=true cp -R _darcs _clean_darcs # produce a corrupt patch echo 'rmfile foo' > _darcs/patches/pending $hashed || echo -n > _darcs/pristine/foo darcs rec -a -m 'remove foo' not darcs check # unapplicable patch! cp -R _darcs/ _backup_darcs darcs repair # repairs the patch darcs check rm -rf _darcs mv _backup_darcs _darcs # get the bad patch back # stash away contents of _darcs cp -R _darcs/ _backup_darcs echo here > bar darcs rec -a -m 'here' # corrupt pristine content corrupt_pristine() { $hashed && inv=`grep ^pristine _darcs/hashed_inventory` cp _backup_darcs/patches/* _darcs/patches/ cp _backup_darcs/*inventory* _darcs/ if $hashed; then cp _darcs/hashed_inventory hashed.tmp sed -e "s,^pristine:.*$,$inv," < hashed.tmp > _darcs/hashed_inventory rm hashed.tmp fi } corrupt_pristine not darcs check # just a little paranoia darcs repair # repair succeeds darcs check # and the resulting repo is consistent # *AND* it contains what we expect... darcs show contents bar > foobar echo foo > foobar1 diff foobar foobar1 rm -rf _backup_darcs mv _clean_darcs _backup_darcs corrupt_pristine # without the unapplicable patch not darcs check darcs repair darcs check cd .. rm -rf temp1 # issue2001: check (alias for repair --dry-run) is not read-only darcs init temp1 cd temp1 mkdir d e echo 'Example content.' > d/f darcs record -lam 'Add d/f and e.' darcs mv d/f e/ darcs record -am 'Move d/f to e/f.' rm _darcs/pristine.hashed/* # Make the repository bogus cp -r _darcs archive not darcs check diff -r _darcs archive cd .. rm -rf temp1 darcs-2.14.5/tests/replace.sh0000755000000000000000000000337707346545000014216 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp mkdir temp cd temp darcs init echo "X X X" > foo echo $'A A,A\tA,A\vA' >> foo darcs rec -alm "Added" # These should fail until replace handles tokens and # token-chars with leteral spaces in them darcs replace ' X ' ' XX ' --token-chars '[ X]' foo && exit 1 || true darcs replace $'A A' 'aaa' --token-chars '[^,]' foo && exit 1 || true darcs replace $'A\tA' 'aaa' --token-chars '[^,]' foo && exit 1 || true darcs replace $'A\vA' 'aaa' --token-chars '[^,]' foo && exit 1 || true # Check that replace is not fooled by duplicate file names # (i.e. not trying to performe the replace twice in the same file) darcs replace X Y foo foo darcs replace Y Z foo ../temp/foo darcs replace Z Q foo foo --repodir=../temp/ darcs rec -am "xyzq" # Try to "overwrite" a hunk with a replace. # # v1.0.8 accepts this without error or warning, # but should perhaps require the --force option? # # current unstable sometimes(!) fails with bug: invalid pending # which is surely a bug. # this succeeds echo "x" > foo darcs rec -am xx echo "y" > foo darcs replace --ignore-times x y foo # this fails echo "hej" > foo darcs rec -am hej echo "hopp" > foo darcs replace hej hopp foo darcs whatsnew echo "src" > foo echo "dst" >> foo darcs rec -am hop darcs replace src dst foo || true darcs replace --force src dst foo darcs whatsnew darcs whatsnew -ls cd .. rm -rf temp # replace after pending add mkdir temp1 cd temp1 darcs init echo a b a b a b > A darcs add A if darcs replace a c A | grep Skipping; then exit 1 fi cd .. rm -fr temp1 # replace after pending mv mkdir temp1 cd temp1 darcs init echo a b a b a b > A darcs add A darcs record --all --name=p1 darcs mv A B if darcs replace a c B | grep Skipping; then exit 1 fi cd .. rm -fr temp1 darcs-2.14.5/tests/repodir.sh0000755000000000000000000000100607346545000014232 0ustar0000000000000000#!/usr/bin/env bash ### http://bugs.darcs.net/issue496 ### _darcs/prefs/defaults ignored when using --repodir ## All these commands SHOULD fail (hence leading NOTs). . lib rm -rf temp mkdir temp cd temp mkdir repo darcs initialize --repodir repo cd repo date > foo darcs add foo darcs record -a -m auth echo > _darcs/prefs/defaults ALL disable # try to disable all not darcs changes not darcs changes --repodir "`pwd`" cd .. not darcs changes --repodir repo not darcs changes --repodir "`pwd`/repo" rm -rf temp darcs-2.14.5/tests/repoformat.sh0000755000000000000000000000444107346545000014752 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf garbage mkdir garbage cd garbage darcs init echo gobbledygook >> _darcs/format cd .. rm -rf future mkdir future cd future darcs init touch titi darcs add titi darcs record -am titi cat > _darcs/format < log grep -i "read repository.*unknown format" log # pull from garbage repo rm -rf temp1 mkdir temp1 cd temp1 darcs init not darcs pull ../garbage 2> log grep -i "read repository.*unknown format" log cd .. # apply in garbage repo rm -rf temp1 mkdir temp1 cd temp1 darcs init darcs changes --context > empty-context darcs tag -m "just a patch" darcs send -a --context=empty-context -o ../bundle.dpatch . cd ../garbage not darcs apply ../bundle.dpatch 2> log grep -i "read repository.*unknown format" log cd .. # add in garbage repo cd garbage touch toto not darcs add toto 2> log grep -i "read repository.*unknown format" log cd .. # rebase suspend in garbage repo cd garbage not darcs rebase suspend --last=1 2> log grep -i "read repository.*unknown format" log # issue2650 not grep 'Unknown format' _darcs/format cd .. ## future repo: we don't understand one # alternative of a line of format # only look at future vs darcs2 skip-formats darcs-1 # get future repo: ok # --to-match is needed because of bug### rm -rf temp1 darcs get future temp1 --to-match "name titi" cd temp1 darcs changes touch toto darcs add toto darcs record -am 'blah' cd .. # pull from future repo: ok rm -rf temp1 mkdir temp1 cd temp1 darcs init darcs pull ../future -a darcs changes | grep titi cd .. # apply in future repo: !ok rm -rf temp1 mkdir temp1 cd temp1 darcs init darcs changes --context > empty-context darcs tag -m "just a patch" darcs send -a --context=empty-context -o ../bundle.dpatch . cd ../future not darcs apply ../bundle.dpatch 2> log cat log grep -i "write repository.*unknown format" log cd .. # record in future repo: !ok cd future touch toto not darcs add toto 2> log grep -i "write repository.*unknown format" log cd .. # rebase suspend in future repo cd future not darcs rebase suspend --last=1 2> log grep -i "write repository.*unknown format" log # issue2650 not grep 'Unknown format' _darcs/format cd .. darcs-2.14.5/tests/revert.sh0000755000000000000000000000234107346545000014100 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 mkdir temp1 cd temp1 darcs init echo hello world > foo darcs add foo darcs record -lam add echo goodbye world >> foo darcs revert -a darcs show contents foo | cmp foo - # Now let's test a trickier revert where changes commute nontrivially. cat > foo < foo echo "nyy" | darcs revert DARCS_DONT_COLOR=1 darcs wh > whatsnew cat > correct < bar echo hello world > foo darcs add bar darcs replace hello goodbye bar foo echo "cnnnyy/y" | tr / \\012 | darcs revert DARCS_DONT_COLOR=1 darcs wh > whatsnew cat > correct < foo darcs add foo darcs revert -a darcs-2.14.5/tests/rmconflict.sh0000755000000000000000000000054507346545000014735 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf tempA tempB mkdir tempA tempB cd tempA darcs init touch foo darcs add foo darcs record -a -m addA -A x cd ../tempB darcs init darcs pull -a ../tempA darcs remove foo # rm foo darcs record -a -m rmB -A x cd ../tempA darcs remove foo darcs record -a -m rmA -A x cd ../tempB darcs pull -a ../tempA cd .. rm -rf tempA tempB darcs-2.14.5/tests/rmdir.sh0000755000000000000000000000264107346545000013711 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 temp3 # initialise temp1 mkdir temp1 cd temp1 darcs initialize mkdir foo echo hello world > foo/bar darcs add foo foo/bar darcs record -a -m add cd .. # get temp1 into temp2 darcs get temp1 temp2 cd temp2 echo hello world > foo/baz cd .. # remove a directory from temp1 and record cd temp1 rm -rf foo darcs record -a -m del cd .. cd temp2 test -e foo/baz test -e foo/bar test -d foo darcs show files --no-pending --no-dir >> files grep foo/bar files darcs show files --no-pending --no-fil >> dirs grep foo dirs cd .. darcs pull -a --repodir=temp2 > pullresult cat pullresult grep 'Warning: .ot deleting' pullresult # get temp1 into temp3 darcs get temp1 temp3 cd temp3 darcs obliterate --last 1 -a echo hello world > foo/baz cd .. cd temp3 test -e foo/baz test -e foo/bar test -d foo darcs show files --no-pending --no-dir >> files grep foo/bar files darcs show files --no-pending --no-fil >> dirs grep foo dirs cd .. darcs pull -q -a --repodir=temp3 > pullresult cat pullresult test ! -s pullresult rm -rf temp1 temp2 temp3 # issue1749 - darcs remove corrupts the patch sequence darcs init temp1 cd temp1 mkdir dir touch dir/file darcs rec -lam "add dir and file" not darcs remove dir # removed dir but not file - should be nothing to add not darcs rec -a -m"remove dir" darcs obliterate -a --patch "remove dir" | grep 'No patches selected!' darcs check cd .. rm -rf temp1 darcs-2.14.5/tests/rollback.sh0000755000000000000000000000171607346545000014367 0ustar0000000000000000#!/usr/bin/env bash . ./lib # rollback nothing rm -rf temp1 darcs init temp1 cd temp1 date > file1 darcs record -lam "test" rm file1 darcs record -am "rm" echo yYd | tr [A-Z] [a-z] | darcs rollback --last=1 | grep 'No changes selected' cd .. rm -rf temp1 # issue1848 - interactive selection of primitive patches # should still work with rollback -p darcs init temp1 cd temp1 echo 'f' > f echo 'g' > g darcs record -lam 'Add f and g' echo ynq | darcs rollback -p 'f and g' cd .. rm -rf temp1 # issue2242 - rollback of a mv patch generates bogus changes darcs init temp1 cd temp1 # Setup dir with empty file in it mkdir A touch A/foo darcs rec -alm 'Add A' # Mv dir and add content to file darcs mv A B echo -e 'line1\nline2' > B/foo darcs rec -alm 'Move A -> B and change foo' # Rollback everything in the move/change patch echo ynya | darcs roll # We shouldn't see any rm'd dirs/files (just a move and line removal hunk) darcs wh | not grep rm cd .. rm -rf temp1 darcs-2.14.5/tests/sametwice.sh0000755000000000000000000000117507346545000014556 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init echo record author me > _darcs/prefs/defaults echo ALL all >> _darcs/prefs/defaults echo ALL verbose >> _darcs/prefs/defaults echo ALL ignore-times >> _darcs/prefs/defaults touch foo darcs add foo darcs whatsnew darcs record -m add_foo echo hello >> foo darcs record -m mod_foo cd .. darcs get --repo-name temp2 temp1 cd temp2 cp ../temp1/_darcs/prefs/defaults _darcs/prefs echo y/d/y | tr / \\012 | darcs unpull --interactive test -f foo -a ! -s foo echo hello >> foo darcs record -m mod_foo_again darcs pull ../temp1 test -s foo cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/send-dont-prompt-deps.sh0000755000000000000000000000130007346545000016726 0ustar0000000000000000#!/usr/bin/env bash . ./lib # Check that the right patches get sent using --dont-prompt-for-dependencies rm -rf temp1 rm -rf temp2 mkdir temp2 mkdir temp1 cd temp2 darcs init cd .. cd temp1 darcs init echo foo > f darcs record -Ax -alm foo1 echo bar > b darcs rec -Ax -alm bar1 echo foo2 > f darcs record -Ax -alm foo2 echo bar2 > b darcs record -Ax -alm bar2 echo yy | darcs send ../temp2 -i --dont-prompt-for-dependencies -p foo2 --dry-run > toto #on the previous line, we get asked about foo2, and we take it grep foo2 toto | wc -l | grep 2 #we don't get asked about foo1, but we take it anyway, so grep foo1 toto | wc -l | grep 1 #and we don't send bar not grep bar toto cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/send-encoding.sh0000755000000000000000000000326507346545000015314 0ustar0000000000000000#!/usr/bin/env bash ## Copyright (C) 2011 Ganesh Sittampalam ## ## Test that darcs send uses the UTF-8 encoding for emails ## when non-ASCII characters are in the message ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. switch_to_utf8_locale darcs init --repo empty darcs init --repo send cd send echo 'file1' > file1 darcs record -lam 'file1' LANG=en_GB.UTF-8 \ DARCS_EDITOR='echo Non-ASCII chars: é è ề Ψ ޡ ߐ ह ჴ Ᏻ ‱ ⁂ ∰ ✈ ⢅ .. >' \ darcs send -a ../empty --to=invalid@invalid --edit \ --sendmail-command='grep "Content-Type: text/plain; charset=\"utf-8\"" %<' darcs-2.14.5/tests/send-external.sh0000755000000000000000000000226107346545000015343 0ustar0000000000000000#!/usr/bin/env bash . ./lib # The argument quoting in the test script below breaks on Windows paths # Actually sending email from Windows is very unlikely anyway, so just # skip this test. abort_windows DARCS_EDITOR=echo export DARCS_EDITOR rm -rf temp1 temp2 mkdir temp1 temp2 cd temp2 darcs init cd .. cd temp1 darcs init date > foobar darcs add foobar darcs rec -a -m add-foobar cat > saveit.sh <>saved.out echo \$6 contains: >>saved.out ls -ltr >>saved.out cat "\$6" >>saved.out echo End of \$6 contents >>saved.out grep add-foobar \$6 CNT=0 while [ "\$#" != "0" ]; do CNT=`expr \$CNT + 1` echo \$0: arg[\$CNT] = \"\$1\" >>saved.out shift done echo \$0: Total \$CNT arguments >>saved.out echo \$0: Input: >>saved.out cat >>saved.out echo \$0: End of input: >>saved.out EOF chmod +x saveit.sh # foobar darcs send --mail\ --author=me -a --to=random@random \ --sendmail-command='bash ./saveit.sh %s %t %c %b %f %a %S %t %C %B %F %A something' ../temp2 cat saved.out grep add-foobar saved.out grep 'addfile ./foobar' saved.out cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/send-output-v1.sh0000755000000000000000000000401007346545000015377 0ustar0000000000000000#!/usr/bin/env bash ## Test that we produce exactly correct output when sending v1 patches ## ## Copyright (C) 2010 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. skip-formats darcs-2 rm -rf empty mkdir empty cd empty darcs init cd .. rm -rf repo gunzip -c $TESTDATA/simple-v1.tgz | tar xf - cd repo darcs send --no-minimize -o repo.dpatch -a ../empty day=$(grep "Date: " $TESTDATA/simple-v1.dpatch | head -n 1 | cut -f1-3 -d' ') diff -u -I'1 patch for repository ' -I'patches for repository ' -I"$day" $TESTDATA/simple-v1.dpatch repo.dpatch cd .. # context-v1 tests that we are including some context lines in hunk patches rm -rf repo gunzip -c $TESTDATA/context-v1.tgz | tar xf - cd repo darcs send --no-minimize -o repo.dpatch -a ../empty day=$(grep "Date: " $TESTDATA/context-v1.dpatch | head -n 1 | cut -f1-3 -d' ') diff -u -I'1 patch for repository ' -I'patches for repository ' -I"$day" $TESTDATA/context-v1.dpatch repo.dpatch cd .. darcs-2.14.5/tests/send-output-v2.sh0000755000000000000000000000401107346545000015401 0ustar0000000000000000#!/usr/bin/env bash ## Test that we produce exactly correct output when sending v2 patches ## ## Copyright (C) 2010 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. skip-formats darcs-1 rm -rf empty mkdir empty cd empty darcs init cd .. rm -rf repo gunzip -c $TESTDATA/simple-v2.tgz | tar xf - cd repo darcs send --no-minimize -o repo.dpatch -a ../empty day=$(grep "Date: " $TESTDATA/simple-v2.dpatch | head -n 1 | cut -f1-3 -d' ') diff -u -I'1 patch for repository ' -I'patches for repository ' -I"$day" $TESTDATA/simple-v2.dpatch repo.dpatch cd .. # context-v1 tests that we are including some context lines in hunk patches rm -rf repo gunzip -c $TESTDATA/context-v2.tgz | tar xf - cd repo darcs send --no-minimize -o repo.dpatch -a ../empty day=$(grep "Date: " $TESTDATA/context-v2.dpatch | head -n 1 | cut -f1-3 -d' ') diff -u -I'1 patch for repository ' -I'patches for repository ' -I"$day" $TESTDATA/context-v2.dpatch repo.dpatch cd .. darcs-2.14.5/tests/send.sh0000755000000000000000000000343107346545000013523 0ustar0000000000000000#!/usr/bin/env bash . ./lib DARCS_EDITOR=echo export DARCS_EDITOR rm -rf temp1 temp2 mkdir temp1 temp2 cd temp2 darcs init # setup test cd ../temp1 darcs init touch foo bar darcs add foo bar darcs record -a -m add_foo_bar -A x # Test that a default preference value is not needed to send darcs send --author=me -a --to=random@random --sendmail-command='grep "^To: random@random$" %<' ../temp2 # Test that a default preference will be used when no --to value is specified echo "default@email" > ../temp2/_darcs/prefs/email darcs send --author=me -a --sendmail-command='grep "^To: default@email$" %<' ../temp2 # Test that the --to parameter overrides the default value in the repository darcs send --author=me -a --to=override@default --sendmail-command='grep "^To: override@default$" %<' ../temp2 darcs send --author=me -a --in-reply-to=some-thread-id --sendmail-command='grep "^In-Reply-To: some-thread-id$" %<' ../temp2 darcs send --author=me -a --in-reply-to=some-thread-id --sendmail-command='grep "^References: some-thread-id$" %<' ../temp2 # Test that the --subject parameter sets the subject # Test that the --output-auto-name parameter outputs what we expect darcs send --author=me -a --subject="it works" --output test1.dpatch ../temp2 darcs send --author=me -a --subject="it works" --output-auto-name ../temp2 cmp test1.dpatch add_foo_bar.dpatch # test --output-auto-name works with optional argument. mkdir patchdir darcs send --author=me -a --subject="it works" --output-auto-name=patchdir ../temp2 cmp test1.dpatch patchdir/add_foo_bar.dpatch # checking --output-auto-name=dir when run in different directory cd patchdir rm add_foo_bar.dpatch darcs send --author=me -a --subject="it works" --output-auto-name=. ../../temp2 cmp ../test1.dpatch add_foo_bar.dpatch cd .. cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/send_apply.sh0000755000000000000000000000117607346545000014734 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 mkdir temp1 temp2 cd temp2 darcs init cd ../temp1 darcs init touch foo bar darcs add foo bar darcs record -a -m add_foo_bar -A x darcs mv foo zig darcs mv bar foo darcs mv zig bar darcs record -a -m swap_foo_bar -A x darcs send --author=me --output=funpatch --dont-sign -a ../temp2 cd ../temp2 darcs apply ../temp1/funpatch cd .. cmp temp1/bar temp2/bar rm -rf temp2 mkdir temp2 cd temp2 darcs init darcs apply ../temp1/funpatch ## Also test that "darcs apply" can accept a patch on stdin. darcs obl -a darcs apply < ../temp1/funpatch cd .. cmp temp1/bar temp2/bar rm -rf temp1 temp2 darcs-2.14.5/tests/set-default-hint.sh0000755000000000000000000000406207346545000015750 0ustar0000000000000000#!/usr/bin/env bash ## Test that set-default hint messages are produced at the right times ## ## Copyright (C) 2011 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R1 R2 R3 # Another script may have left a mess. darcs init --repo R1 darcs get R1 R2 darcs get R1 R3 HINTSTRING="issue the same command with the --set-default flag" cd R3 for command in pull push send do opt= test "$command" = "send" && opt=-O # R1 should be the default for R3 darcs $command $opt ../R1 | not grep "$HINTSTRING" darcs $command $opt ../R2 | grep "$HINTSTRING" # can disable message on the command-line darcs $command $opt --no-set-default ../R2 | not grep "$HINTSTRING" # or using defaults echo "$command no-set-default" >> ../.darcs/defaults darcs $command $opt ../R2 | not grep "$HINTSTRING" darcs $command $opt --set-default ../R2 | not grep "$HINTSTRING" darcs $command $opt --set-default ../R1 | not grep "$HINTSTRING" done darcs-2.14.5/tests/set_scripts_executable.sh0000755000000000000000000000220507346545000017333 0ustar0000000000000000#!/usr/bin/env bash # Some tests for the --set-scripts-executable option. . lib abort_windows rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init cat > script.pl << FOO #!/usr/bin/env perl print "Hello\n"; FOO chmod 0644 script.pl date > nonscript # pre-tests test -r script.pl test -r nonscript test ! -x script.pl test ! -x nonscript darcs add script.pl nonscript darcs record --name 'uno' --all cd .. # sans --set-scripts-executable (should not be executable) mkdir temp2 cd temp2 darcs init darcs pull -a ../temp1 # sanity check test -r script.pl test -r nonscript # nothing should be executable test ! -x script.pl test ! -x nonscript cd .. rm -rf temp2 # with --set-scripts-executable mkdir temp2 cd temp2 darcs init darcs pull -a ../temp1 --set-scripts-executable # sanity check test -r script.pl test -r nonscript # script should be executable test -x script.pl test ! -x nonscript cd .. rm -rf temp2 # now let's try the same thing with get darcs get --set-scripts-executable temp1 temp2 cd temp2 # sanity check test -r script.pl test -r nonscript # script should be executable test -x script.pl test ! -x nonscript cd .. rm -rf temp1 temp2 darcs-2.14.5/tests/setpref.sh0000755000000000000000000000065607346545000014250 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init echo 'test file 1' > foo darcs record --look-for-adds --all -m"Patch 1" echo 'test boringfile' > bar darcs setpref boringfile bar darcs record --look-for-adds --all -m"Patch 2" echo 'test file 3' > baz # there should be no -R darcs record --look-for-adds --all -m"Patch 3" > ../temp2 cat ../temp2 not grep R ../temp2 cd .. rm -rf temp1 rm -f temp2 darcs-2.14.5/tests/show-authors.sh0000755000000000000000000000063307346545000015236 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf R darcs init --repo R cd R echo zig > foo darcs add foo darcs record -a -m add_foo -A x echo zag >> foo darcs record -a -m mod_foo -A y echo bar > foo darcs record -a -m mod2 -A y darcs show authors > authors grep "#1 2 y" authors grep "#2 1 x" authors head -1 authors | grep y darcs show authors --verbose [[ $(darcs show authors --verbose | grep y | wc -l) -eq 2 ]] darcs-2.14.5/tests/show-removed-file.sh0000755000000000000000000000353507346545000016133 0ustar0000000000000000#!/usr/bin/env bash ## Test that 'show files --hash' acts as expected ## when selecting changes up to a given patch ## ## Copyright (C) 2015 Ben Franksen ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. darcs init --repo R # Create our test repos. cd R touch f darcs add f darcs record -am 'add f' hash1=$(darcs log --last=1 | grep '^patch' | cut -d ' ' -f 2) darcs show files > add-f.1 rm f darcs record -am 'removed f' darcs show files --hash $hash1 --no-pending > add-f.2 diff add-f.1 add-f.2 mkdir d touch d/f darcs add d/f darcs record -am 'add d/f' hash2=$(darcs log --last=1 | grep '^patch' | cut -d ' ' -f 2) darcs show files > add-df.1 rm -rf d darcs record -am 'removed d and d/f' darcs show files --hash $hash2 --no-pending > add-df.2 diff add-df.1 add-df.2 darcs-2.14.5/tests/show_contents.sh0000755000000000000000000000315107346545000015466 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp1 mkdir temp1 cd temp1 darcs init touch foo darcs add foo echo first > foo darcs record -a -m "first edit" -A author1 echo second > foo darcs record -a -m "second edit" -A author2 darcs tag t1 -A moi echo third > foo darcs record -a -m "third edit" -A author3 echo fourth > foo darcs record -a -m "fourth edit" -A author4 echo unrecorded > foo darcs show contents foo | grep fourth darcs show contents foo -p third | grep third darcs show contents foo --match="author author1" first | grep first darcs show contents foo --tag t1 | grep second not darcs show contents foo --match "hash bla" 2>&1 | tee out grep "Couldn't match pattern" out darcs show contents -n 2 foo | grep third cd .. rm -rf temp1 ## issue1705 - darcs show contents --index=1 => darcs failed: Pattern not specified in get_nonrange_match darcs init temp1 cd temp1 echo 111 > 1 darcs record -lam 'add file 1' darcs show contents --index=1 1 cd .. rm -rf temp1 ## issue2447 - get contents of deleted file darcs init temp1 cd temp1 echo 'example content' > f darcs record -lam 'add f' hash1=$(darcs log --last=1 | grep '^patch' | cut -d ' ' -f 2) rm f darcs record -am 'removed f' darcs show contents --hash $hash1 f | grep 'example content' mkdir d echo 'example content' > d/f darcs record -lam 'add d/f' hash2=$(darcs log --last=1 | grep '^patch' | cut -d ' ' -f 2) rm d/f darcs record -am 'removed d/f' darcs show contents --hash $hash2 d/f | grep 'example content' darcs obliterate -a --last=1 rm -rf d darcs record -am 'removed d and d/f' darcs show contents --hash $hash2 d/f | grep 'example content' cd .. rm -rf temp1 darcs-2.14.5/tests/show_files.sh0000755000000000000000000000656507346545000014747 0ustar0000000000000000#!/usr/bin/env bash . ./lib check_manifest () { : > files.tmp echo . > dirs.tmp echo . > files-dirs.tmp for x in $1 ; do echo "./$x" >> files.tmp echo "./$x" >> files-dirs.tmp done for x in $2 ; do echo "./$x" >> dirs.tmp echo "./$x" >> files-dirs.tmp done darcs show files $3 --files --no-directories > darcsraw-files.tmp darcs show files $3 --no-files --directories > darcsraw-dirs.tmp darcs show files $3 --files --directories > darcsraw-files-dirs.tmp for x in files dirs files-dirs ; do sort $x.tmp | sed -e 's,\\,/,' > expected-$x.tmp sort darcsraw-$x.tmp | sed -e 's,\\,/,' > darcs-$x.tmp diff -u expected-$x.tmp darcs-$x.tmp done } rm -rf temp mkdir temp cd temp darcs init check_manifest "" "" "--no-pending" check_manifest "" "" "--pending" touch a b darcs add a check_manifest "" "" "--no-pending" check_manifest "a" "" "--pending" darcs add b mkdir c check_manifest "" "" "--no-pending" check_manifest "a b" "" "--pending" darcs add c touch c/1 c/2 check_manifest "" "" "--no-pending" check_manifest "a b" "c" "--pending" darcs add c/1 c/2 check_manifest "" "" "--no-pending" check_manifest "a b c/1 c/2" "c" "--pending" mkdir d touch d/3 d/4 darcs add d/3 d/4 check_manifest "" "" "--no-pending" check_manifest "a b c/1 c/2 d/3 d/4" "c d" "--pending" darcs record -A test --all --name "patch 1" --skip-long-comment check_manifest "a b c/1 c/2 d/3 d/4" "c d" "--no-pending" check_manifest "a b c/1 c/2 d/3 d/4" "c d" "--pending" darcs mv d e check_manifest "a b c/1 c/2 d/3 d/4" "c d" "--no-pending" check_manifest "a b c/1 c/2 e/3 e/4" "c e" "--pending" rm c/1 check_manifest "a b c/1 c/2 d/3 d/4" "c d" "--no-pending" check_manifest "a b c/1 c/2 e/3 e/4" "c e" "--pending" darcs remove c/1 check_manifest "a b c/1 c/2 d/3 d/4" "c d" "--no-pending" check_manifest "a b c/2 e/3 e/4" "c e" "--pending" darcs mv c/2 c/1 check_manifest "a b c/1 c/2 d/3 d/4" "c d" "--no-pending" check_manifest "a b c/1 e/3 e/4" "c e" "--pending" darcs record -A test --all --name "patch 2" --skip-long-comment check_manifest "a b c/1 e/3 e/4" "c e" "--no-pending" check_manifest "a b c/1 e/3 e/4" "c e" "--pending" darcs remove c/1 check_manifest "a b c/1 e/3 e/4" "c e" "--no-pending" check_manifest "a b e/3 e/4" "c e" "--pending" darcs remove c check_manifest "a b c/1 e/3 e/4" "c e" "--no-pending" check_manifest "a b e/3 e/4" "e" "--pending" darcs record -A test --all --name "patch 3" --skip-long-comment check_manifest "a b e/3 e/4" "e" "--no-pending" check_manifest "a b e/3 e/4" "e" "--pending" darcs mv b b2 darcs mv b2 b3 check_manifest "a b e/3 e/4" "e" "--no-pending" check_manifest "a b3 e/3 e/4" "e" "--pending" darcs record -A test --all --name "patch 3" --skip-long-comment check_manifest "a b3 e/3 e/4" "e" "--no-pending" check_manifest "a b3 e/3 e/4" "e" "--pending" cd .. rm -rf temp darcs init --repo R cd R for file in foo bar baz quux do touch "$file" darcs add "$file" darcs record --all --name "Add $file" done darcs unrecord --all --patches "quux" darcs rebase suspend --all --patches "foo" # (pending, match): (False, False) check_manifest "bar baz" "" "--no-pending" # (pending, match): (False, True) check_manifest "bar" "" "--no-pending --patch bar" # (pending, match): (True, False) check_manifest "bar baz quux" "" "--pending" # (pending, match): (True, True) not darcs show files --pending --patch "bar" cd .. rm -rf R darcs-2.14.5/tests/show_tags.sh0000755000000000000000000000102707346545000014567 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 mkdir temp1 cd temp1 darcs initialize echo ALL ignore-times >> _darcs/prefs/defaults echo A > foo darcs add foo darcs record -a -m AA -A x echo B > foo darcs record -a -m BB -A x echo C > foo darcs record -a -m CC -A x darcs tag -m 1.0 -A x echo D > foo darcs record -a -m DD -A x echo E > foo darcs record -a -m EE -A x echo F > foo darcs record -a -m FF -A x darcs tag -m 2.0 -A x darcs show tags > my cat my cat > ref < 'Texte/böse Zeichen' darcs record -lam 'Erste Änderung' darcs log -v darcs send -ao bundle tail -n+7 bundle > u_bundle LC_ALL=C darcs log -v darcs send -ao bundle tail -n+7 bundle > c_bundle diff u_bundle c_bundle darcs apply u_bundle | grep 'already .*applied' darcs obliterate -a darcs apply u_bundle | grep 'Finished applying' darcs unrecord -a darcs revert -a darcs apply u_bundle | grep 'Finished applying' LC_ALL=$lc_utf8 darcs apply c_bundle | grep 'already .*applied' darcs obliterate -a darcs apply c_bundle | grep 'Finished applying' darcs unrecord -a darcs revert -a darcs apply c_bundle | grep 'Finished applying' LC_ALL=C cd .. darcs clone U C diff -r U/Texte C/Texte cd C darcs pull ../E --set-default darcs apply ../U/u_bundle | grep 'already .*applied' diff -r ../U/Texte Texte darcs obliterate -ao ou_bundle diff ../U/u_bundle ou_bundle darcs apply ou_bundle | grep 'Finished applying' diff -r ../U/Texte Texte darcs unrecord -a darcs revert -a darcs pull ../U -a diff -r ../U/Texte Texte darcs send -ao bundle tail -n+7 bundle > c_bundle LC_ALL=$lc_utf8 darcs send -ao bundle tail -n+7 bundle > u_bundle diff u_bundle c_bundle darcs apply c_bundle | grep 'already .*applied' diff -r ../U/Texte Texte darcs obliterate -ao oc_bundle diff c_bundle oc_bundle darcs apply c_bundle | grep 'Finished applying' diff -r ../U/Texte Texte darcs unrecord -a darcs revert -a darcs pull ../U -a diff -r ../U/Texte Texte darcs send -ao bundle tail -n+7 bundle > c_bundle cd .. diff U/u_bundle C/u_bundle diff -r U/Texte C/Texte darcs-2.14.5/tests/tag-ask-deps.sh0000755000000000000000000000257207346545000015057 0ustar0000000000000000#!/bin/sh -e ## ## Basic test of tag --ask-deps ## ## Copyright (C) 2014 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R S mkdir R cd R darcs init touch file1 darcs rec -lam 'file1' touch file2 darcs rec -lam 'file2' echo 'nyy' | darcs tag --ask-deps file1 cd .. darcs get --tag file1 R S cd S test -f file1 test ! -f file2 darcs-2.14.5/tests/tag.sh0000755000000000000000000000066607346545000013354 0ustar0000000000000000#!/usr/bin/env bash . lib # Some tests for 'darcs tag' rm -rf temp1 log mkdir temp1 cd temp1 darcs init touch one darcs add one darcs record --name 'uno' --all darcs tag soup > log not grep failed log grep TAG log darcs changes --last 1 > log grep tagged log cd .. rm -rf temp1 log # issue2244: warn about duplicate tags darcs init temp1 cd temp1 darcs tag shouldbeunique darcs tag shouldbeunique | grep 'WARNING' cd .. rm -rf temp1 darcs-2.14.5/tests/tentative_revert.sh0000755000000000000000000000350107346545000016162 0ustar0000000000000000#!/usr/bin/env bash ## Test for clearing tentative state after a failed transaction ## ## Copyright (C) 2009 Kamil Dworakowski ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . ./lib rm -rf R darcs init --repo R touch R/foo darcs record --repo R -lam 'foo' touch R/bar darcs record --repo R -lam 'bar' echo "this change should stay uncommitted" >> R/foo darcs setpref --repo R test false echo 'y' | not darcs amend --repo R -am 'change everything' R/foo --test darcs setpref --repo R test true # if tentative state was not cleared, the previous changes # from failed transaction would piggy back on the next echo "xx" >> R/bar echo 'y' | darcs amend --repo R -am 'bar2' R/bar --test # should have uncommitted changes darcs wh --repo R > changes grep "this change should stay uncommitted" changes darcs-2.14.5/tests/test.sh0000755000000000000000000000343007346545000013550 0ustar0000000000000000#!/usr/bin/env bash ## Ensure that "darcs test" succeeds when run in a complete ## repository with a dummy test that always succeeds. ## ## Copyright (C) 2008 David Roundy ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. rm -rf R # Another script may have left a mess. darcs init --repo R darcs setpref --repo R test 'grep hello f' not darcs record --repo R -am 'true test' --test darcs record --repo R -am 'true test' --no-test touch R/f darcs record --repo R -lam 'added foo' --no-test darcs tag --repo R -m 'got f?' echo hello > R/f darcs record --repo R -lam 'hellofoo' --test darcs test --repo R rm -rf R # Clean up after ourselves. darcs-2.14.5/tests/three_way_conflict.sh0000755000000000000000000000103607346545000016441 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 temp2 temp3 mkdir -p temp1 temp2 temp3 cd temp1 darcs init cd ../temp2 darcs init cd ../temp3 darcs init touch foo darcs add foo darcs record -a -A author -m add darcs push -a ../temp2 darcs push -a ../temp1 echo A > foo darcs record -a -A author -m AA cd ../temp2 echo B > foo darcs record -a -A author -m BB cd ../temp1 echo C > foo darcs record -a -A author -m CC darcs pull -a ../temp2 darcs pull -a ../temp3 cd ../temp2 darcs pull -a ../temp3 darcs pull -a ../temp1 rm -rf temp1 temp2 temp3 darcs-2.14.5/tests/trackdown-bisect.sh0000755000000000000000000000521207346545000016034 0ustar0000000000000000#!/bin/env bash # A test for test --linear, test --bisect and test --backoff. # In general it construct various repositories and try # to find the last recent failing patch and match it with # expected position. ################################################################ . ./lib if echo $OS | grep -i windows; then echo I do not know how to run a test program under windows exit 0 fi ghc -o trackdown-bisect-helper $TESTBIN/trackdown-bisect-helper.hs function make_repo_with_test { rm -fr temp1 mkdir temp1 ; cd temp1 ; darcs init touch ./i touch ./j darcs add ./i darcs add ./j ../trackdown-bisect-helper $1 } function cleanup_repo_after { cd .. rm -fr temp1 } # You can replace --bisect by --linear for compare with linear trackdown test_args='--bisect' # Function return true if given patch was found. # It expects that last line has finish with # For the linear it is second last from the end, and last line # is sentence if test failed or succeed. function is_found_good_patch { if [ "$test_args" == "--linear" ]; then tail -n 2 | grep " $1\$" else tail -n 1 | grep " $1\$" fi } # Test command - Success condition is that file 'j' have one inside (1) # That means if it has zero (0) it is failing test. test_cmd='grep -q 1 j' ############################################################################# # Section with test-cases ############################################################################# # TEST01: Repo with success in the half testTrackdown() { make_repo_with_test $1 if darcs test $test_args "$test_cmd" | is_found_good_patch $2; then echo "ok 1" else echo "not ok 1. the trackdown should find last failing patch = $2." exit 1 fi cleanup_repo_after } # TEST01: Repo with success in the half test01() { testTrackdown '[1,1,0,0,0]' 3 } # TEST02: Repo without success condition test02() { testTrackdown '[0,0,0,0,0]' 1 } # TEST03: Repo with success condition at before last patch test03() { testTrackdown '[1,1,1,1,0]' 5 } # TEST04: Repo with success condition as first patch ever test04() { testTrackdown '[1,0,0,0,0]' 2 } ############################################# # call test-cases for linear trackdown ############################################# test_args='--linear' test01 test02 ############################################# # Call test-cases for bisect trackdown ############################################# test_args='--bisect' test01 test02 test03 test04 ############################################# # Call test-cases for backoff trackdown ############################################# test_args='--backoff' test01 test02 test03 test04 darcs-2.14.5/tests/trailing-newlines.sh0000755000000000000000000000125007346545000016222 0ustar0000000000000000#!/usr/bin/env bash . lib rm -rf temp && mkdir temp cd temp darcs init echo -n > no_newline echo -n > newline darcs rec -lam "empty" echo -n foo > no_newline echo foo > newline wc -l no_newline | grep 0 wc -l newline | grep 1 darcs wh > diff1 darcs rec -am "add bits" darcs revert -a | grep "no changes" echo -n > no_newline echo -n > newline darcs wh > diff2 darcs rec -lam "bar" darcs revert -a | grep "no changes" darcs check cat > diff1.expected < diff2.expected < $i uniq $i > uni$i if cmp $i uni$i; then echo passed. else echo failed! diff -c uni$i $i exit 1 fi done cd .. rm -rf temp1 darcs-2.14.5/tests/unrecord.sh0000755000000000000000000000402007346545000014406 0ustar0000000000000000#!/usr/bin/env bash . ./lib # unrecord remove rm -rf temp1 darcs init temp1 cd temp1 echo foo > foo darcs record -lam 'addfoo' darcs remove foo darcs whatsnew > correct darcs record -a -m 'rmfoo' darcs unrecord -a --last 1 darcs whatsnew > unrecorded diff -u correct unrecorded cd .. rm -rf temp1 # unrecord setpref darcs init temp1 cd temp1 darcs setpref boringfile foobar darcs whatsnew > correct cat correct darcs record -a -m 'boringfoobar' darcs unrecord -a darcs whatsnew > unrecorded cat unrecorded diff -u correct unrecorded cd .. rm -rf temp1 # unrecord add darcs init temp1 cd temp1 echo foo > foo darcs add foo darcs whatsnew > correct cat correct darcs record -a -m 'addfoo' darcs unrecord -a darcs whatsnew > unrecorded cat unrecorded diff -u correct unrecorded cd .. rm -rf temp1 # tricky unrecord darcs init temp1 cd temp1 date > temp.c darcs record -lam hi mkdir d darcs add d darcs mv temp.c d/ darcs record -am mvetc darcs show contents d/temp.c | cmp d/temp.c - echo y/d/y | tr / \\012 | darcs unrecord darcs whatsnew darcs record -a -m again darcs show contents d/temp.c | cmp d/temp.c - cd .. rm -rf temp1 # Check that the right patches get unrecorded using --dont-prompt-for-dependencies darcs init temp1 cd temp1 echo foo > f darcs record -Ax -alm foo1 echo bar > b darcs rec -Ax -alm bar1 echo foo2 > f darcs record -Ax -alm foo2 echo bar2 > b darcs record -Ax -alm bar2 darcs unrec --no-deps -p foo1 darcs changes -p foo --count | grep 2 #foo1 is depended upon, we don't unpull it echo yy | darcs unrec --dont-prompt-for-dependencies -p foo1 #on the previous line, we don't get asked about foo2. darcs changes -p foo --count | grep 0 #yet, it is unrecorded. darcs changes -p bar --count | grep 2 cd .. rm -rf temp1 # issue1012: rm/record/unrecord/record => inconsistent repository darcs init temp1 cd temp1 echo temp1 >File.hs darcs add File.hs darcs record File.hs -a -m "add File" rm File.hs darcs record -a -m "rm File" darcs unrecord -p "rm File" -a darcs record -a -m "re-rm File" cd .. rm -rf temp1 darcs-2.14.5/tests/unrevert.sh0000755000000000000000000000406207346545000014445 0ustar0000000000000000#!/usr/bin/env bash . ./lib rm -rf temp1 darcs init temp1 cd temp1 echo hello world > foo darcs record -lam add echo goodbye world >> foo cp foo bar darcs revert -a darcs show contents foo | cmp foo - darcs unrevert -a cmp foo bar cd .. rm -rf temp1 # unrevert replace moved darcs init temp1 cd temp1 echo hello world > foo darcs record -lam 'addfoo' darcs replace hello goodbye foo darcs revert -a not darcs whatsnew darcs mv foo bar echo hello my good friends >> bar darcs unrevert -a darcs whatsnew > unrecorded cat unrecorded grep 'bar .* hello goodbye' unrecorded cat bar grep 'goodbye world' bar grep 'goodbye my good friends' bar cd .. rm -rf temp1 # unrevert cancel # From issue366 bug report darcs init temp1 cd temp1 touch a b darcs record -lam init echo plim >> a echo plim >> b echo yyyy | darcs revert echo ploum >> a echo nyyy | darcs unrevert cd .. rm -rf temp1 # unrevert add darcs init temp1 cd temp1 echo foo > foo darcs add foo darcs whatsnew > correct cat correct darcs revert -a not darcs whatsnew darcs unrevert -a darcs whatsnew > unrecorded cat unrecorded diff -u correct unrecorded cd .. rm -rf temp1 # double unrevert # This demonstrates a bug that happens if you revert followed by # a partial unrevert and a full unrevert. It requires that # the second unrevert is working with patches who's contents need # to be modified by the commute in the first unrevert. darcs init temp1 cd temp1 echo line1 >> A echo line2 >> A echo line3 >> A echo line4 >> A echo line5 >> A echo line6 >> A darcs add A darcs record -am A sed 's/line2/Line2/' A > A1; rm A; mv A1 A sed '4d' A > A1; rm A; mv A1 A sed 's/line6/Line6/' A > A1; rm A; mv A1 A darcs revert -a echo nyny | darcs unrev darcs unrev -a cd .. rm -rf temp1 # impossible unrevert darcs init temp1 cd temp1 echo ALL ignore-times > _darcs/prefs/defaults echo a > foo darcs record -lam aa echo b > foo echo yy | darcs revert -a echo ydyy | darcs unrecord # since the unrevert is impossible, we should fail if it succeeds... echo yy | darcs unrevert && exit 1 || true cd .. rm -rf temp1 darcs-2.14.5/tests/utf8-display.sh0000755000000000000000000000321407346545000015122 0ustar0000000000000000#!/bin/sh -e ## ## Basic test of displaying metadata in the UTF8 locale ## ## Copyright (C) 2014 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib abort_windows # TODO make this work switch_to_utf8_locale #is now the default, must use DARCS_ESCAPE_8BIT to disable #export DARCS_DONT_ESCAPE_8BIT=1 rm -rf R mkdir R cd R darcs init echo 'Société nationale des chemins de fer français' > f darcs rec -lam 'creació de a i b' | grep 'creació de a i b' darcs changes | grep 'creació de a i b' darcs annotate f | grep 'creació de a i b' darcs annotate f | grep 'Société nationale des chemins de fer français' darcs-2.14.5/tests/v1-braced.sh0000755000000000000000000000311207346545000014332 0ustar0000000000000000#!/usr/bin/env bash ## Test for correct handling of Darcs v1 patches with nested { } ## ## Copyright (C) 2010 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. skip-formats darcs-2 rm -rf braced gunzip -c $TESTDATA/braced.tgz | tar xf - cd braced darcs check cd .. rm -rf empty mkdir empty cd empty darcs init darcs apply $TESTDATA/braced.dpatch cd .. cd braced darcs pull -a ../empty | grep 'No remote patches to pull in' cd ../empty darcs pull -a ../braced | grep 'No remote patches to pull in' darcs-2.14.5/tests/whatsnew-adds-no-summary.sh0000755000000000000000000000302407346545000017446 0ustar0000000000000000#!/bin/sh -e ## ## Test for the interaction of --look-for-adds and --no-summary in darcs whatsnew ## ## Copyright (C) 2017 Ganesh Sittampalam ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib rm -rf R mkdir R cd R darcs init echo A > A echo B > B darcs add A darcs rec -am "add A" echo "A 2" > A darcs whatsnew --look-for-adds --no-summary > output.txt grep "hunk \./A 1" output.txt grep "\-A" output.txt grep "+A 2" output.txt grep "addfile \./B" output.txt grep "hunk \./B 1" output.txt grep "+B" output.txt darcs-2.14.5/tests/whatsnew.sh0000755000000000000000000000567507346545000014446 0ustar0000000000000000#!/usr/bin/env bash . lib # Some tests for 'darcs whatsnew ' rm -rf temp1 mkdir temp1 cd temp1 # RT#505 whatsnew -s after removal of file without a newline darcs init echo -n foobar > foo darcs record -la -m "add foo" | grep "Finished record" rm -f foo darcs whatsnew -s | grep R darcs record -a -m "remove foo" # RT#245 --look-for-adds implies --summary touch look_summary.txt darcs whatsnew -l | grep -i "a ./look_summary.txt" # whatsnew works with uncommon file names and does NOT display # the internal "white space encoded" filename if echo $OS | grep -i windows; then echo test does not work on windows exit 0; else echo foo > \\ darcs add \\ darcs whatsnew | tee log grep 'hunk ./\\' log fi echo foo > "foo bar" darcs add "foo bar" darcs wh | tee log grep 'hunk ./foo bar' log # check that filename encoding does not botch up the index darcs rec -am "weird filenames" not darcs wh # whatsnew works with absolute paths DIR="`pwd`" echo date.t > date.t touch date.t darcs add date.t darcs whatsnew "$DIR/date.t" | grep hunk cd .. rm -rf temp1 ## Part 2 ## This tests the basic fascilities of `whatsnew --interactive` ## Copyright (C) 2014 Daniil Frumin rm -rf wn-i darcs init --repo wn-i cd wn-i echo lolz > foo darcs add foo echo n | darcs whatsnew -i > what grep "Will not ask whether to view 1" what rm what echo yxgq | darcs whatsnew -i > what2 grep "M ./foo +1" what2 addfileCount=`grep -c "addfile" what2` if [ "$addfileCount" -ne 3 ]; then exit 1 fi; cd .. ## Part 3 ## Ensure that darcs whatsnew only lists relevant bits. ## Public Domain, 2010, Petr Rockai rm -rf R # Another script may have left a mess. darcs init --repo R # Create our test repos. cd R mkdir d e # Change the working tree. echo 'Example content.' > d/f darcs record -lam 'Add d/f and e.' darcs remove d/f not darcs wh e # | not grep f cd .. ## Part 4 # Some tests for 'darcs whatsnew ' rm -rf temp1 darcs init temp1 cd temp1 date > foo mkdir bar echo hello world > bar/baz darcs record -la -m "add foo" echo goodbye world >> bar/baz # goodbye should show up precisely once darcs wh > out cat out grep goodbye out | wc -l | grep 1 darcs wh bar bar/baz > out cat out grep goodbye out | wc -l | grep 1 darcs mv foo bar echo not date > bar/foo darcs wh bar bar/baz > out cat out grep date out | wc -l | grep 1 darcs wh foo > out cat out grep date out | wc -l | grep 1 darcs wh foo foo foo > out cat out grep date out | wc -l | grep 1 darcs wh foo ./foo ../temp1/foo > out cat out grep date out | wc -l | grep 1 darcs wh foo bar/../foo > out cat out grep date out | wc -l | grep 1 darcs wh foo foo/../foo/. > out cat out grep date out | wc -l | grep 1 cd .. rm -rf temp1 ## Part 5 darcs init temp1 cd temp1 touch foo darcs add foo darcs rec -m t1 -a -A tester echo 1 >> foo darcs what -s | grep -v No\ changes darcs what -l | grep -v No\ changes darcs what -sl | grep -v No\ changes cd .. rm -rf temp1 darcs-2.14.5/tests/workingdir.sh0000755000000000000000000000300107346545000014742 0ustar0000000000000000#!/usr/bin/env bash . lib # test for working dir woes # the setup... rm -rf temp1 temp2 mkdir temp1 cd temp1 darcs init mkdir a echo temp0 > a/x darcs add a darcs add a/x darcs record -am "aa" darcs mv a/x a/y darcs record -am "x to y" echo temp1 > b darcs add b darcs record -am "bb" mkdir d darcs add d darcs record -am "dd" darcs tag 1 echo 1-b2 > b darcs record -am "b2" cd .. # try to move a file that we don't have the right to do darcs get temp1 temp2 --to-patch aa cd temp2 chmod u-w a darcs pull -a test -e b chmod u+w a cd .. rm -rf temp2 # [issue319] try to overwrite file(s) in our working dir darcs get temp1 temp2 --to-patch aa cd temp2 echo temp2 > b echo temp2 > d darcs pull -a -t 1 grep temp1 b grep temp2 b.~0~ grep temp2 d.~0~ # now make sure we didn't overdo it darcs pull -a grep '1-b2' b test -e b.~0~ test ! -e b.~1~ cd .. rm -rf temp2 # [issue298] backup working dir files with conflicts darcs get temp1 temp2 --tag 1 cd temp2 echo 2-b2 > b darcs pull -a grep "v v v" b grep "2-b2" b.~0~ not grep "v v v" b.~0~ cd .. rm -rf temp2 # [issue440] a) try to overwrite a file in our working dir darcs get temp1 temp2 --to-patch a cd temp2 echo temp2 > a/y echo old-bak > a/y.~0~ darcs pull -a grep temp0 a/y grep old-bak a/y.~0~ grep temp2 a/y.~1~ cd .. rm -rf temp2 # [issue440] b) try to overwrite a directory in our working dir darcs get temp1 temp2 --to-patch a cd temp2 mkdir a/y echo old-bak > a/y.~0~ darcs pull -a grep temp0 a/y grep old-bak a/y.~0~ test -d a/y.~1~ cd .. rm -rf temp2 rm -rf temp1 darcs-2.14.5/tests/xmlschema.sh0000755000000000000000000001056307346545000014557 0ustar0000000000000000#!/usr/bin/env bash ## Test for XML schema - ## ## Copyright (C) 2011 Radoslav Dorcik ## ## Permission is hereby granted, free of charge, to any person ## obtaining a copy of this software and associated documentation ## files (the "Software"), to deal in the Software without ## restriction, including without limitation the rights to use, copy, ## modify, merge, publish, distribute, sublicense, and/or sell copies ## of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: ## ## The above copyright notice and this permission notice shall be ## included in all copies or substantial portions of the Software. ## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. . lib # Load some portability helpers. repod="$TESTDATA/../../" xsdf="$repod/contrib/darcs.xsd" tmpf="changes_tmp.xml" if [ -z "$(which xmllint)" ]; then echo this test does not work on this machine echo it needs xmllint for XML validation. exit 200 fi if [ ! -d "$repod/_darcs" ]; then echo this test does not work on this machine echo it needs source repo exit 200 fi if [ ! -f "$xsdf" ]; then echo this test does not work on this machine echo it needs $(basename $xsdf) exit 200 fi ####################################################### # Test preparation ####################################################### # Create repository with all kind of operations darcs init --repo R # Create our test repos. cd R # Add File and Dir mkdir dir1 dir2 echo "Example content." > dir1/file1 echo "Example content." > dir2/file2 darcs record -lam 'Add dir1 and dir2' # Modify (add) echo "Example content." >> dir1/file1 echo "Example content." >> dir2/file2 echo "Example content." >> dir1/file1 echo "Example content." >> dir2/file2 darcs record -lam 'Modify dir1 and dir2 (add)' # Modify (add,del) echo "Example content." > dir1/file1 echo "Example content." > dir2/file2 echo "Example contentx." >> dir1/file1 echo "Example contentx." >> dir2/file2 darcs record -lam 'Modify dir1 and dir2 (add,del)' # Replace darcs replace contentx contenty dir1/file1 dir2/file2 darcs record -lam 'Replace contentx contenty' # Modify (del) echo "Example content." > dir1/file1 echo "Example content." > dir2/file2 darcs record -lam 'Modify dir1 and dir2 (del)' # Moving darcs mv dir1 dir11 darcs mv dir2 dir22 darcs record -lam 'Move dir1 and dir2' # Remove rm -fr dir11 rm -fr dir22 darcs record -lam 'Remove dir1 and dir2' # Complex patch Replace and Modify, Add and Delete mkdir dir3 dir4 echo "Example contentx." >> dir3/file3 echo "Example contentx." >> dir3/file3 echo "Example contentx." >> dir3/file3 echo "Example contentz." >> dir3/file3 echo "Example contentx." >> dir4/file4 darcs record -lam 'Complex patch (prep)' darcs replace contentx contenty dir3/file3 mkdir dir5 echo "Example contentx." >> dir5/file4 darcs mv dir3 dir7 echo "Example contentx." >> dir7/file3 darcs record -lam 'Complex patch (done)' rm -fr dir4 cd .. ####################################################### # Testing ####################################################### # Darcs produces XMLs with non-UTF8 characters. echo '' > $tmpf darcs log -s --xml-output --repodir=R >> $tmpf xmllint --noout --schema $xsdf $tmpf || exit 1 echo '' > $tmpf darcs log --xml-output --repodir=R >> $tmpf xmllint --noout --schema $xsdf $tmpf || exit 1 exit 0; # Comment this out for next long running tests ## Next tests are disabled by default because they are long running (~10 minutes) ## But they are be helpfull for manual verifications echo '' > $tmpf darcs log --xml-output -s --repodir=$repod >> $tmpf xmllint --noout --schema $xsdf $tmpf || exit 1