amp 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.hgignore +26 -0
- data/AUTHORS +2 -0
- data/History.txt +6 -0
- data/LICENSE +37 -0
- data/MANIFESTO +7 -0
- data/Manifest.txt +294 -0
- data/README.md +129 -0
- data/Rakefile +102 -0
- data/SCHEDULE.markdown +12 -0
- data/STYLE +27 -0
- data/TODO.markdown +149 -0
- data/ampfile.rb +47 -0
- data/bin/amp +30 -0
- data/bin/amp1.9 +30 -0
- data/ext/amp/bz2/README.txt +39 -0
- data/ext/amp/bz2/bz2.c +1582 -0
- data/ext/amp/bz2/extconf.rb +77 -0
- data/ext/amp/bz2/mkmf.log +29 -0
- data/ext/amp/mercurial_patch/extconf.rb +5 -0
- data/ext/amp/mercurial_patch/mpatch.c +405 -0
- data/ext/amp/priority_queue/extconf.rb +5 -0
- data/ext/amp/priority_queue/priority_queue.c +947 -0
- data/ext/amp/support/extconf.rb +5 -0
- data/ext/amp/support/support.c +250 -0
- data/lib/amp.rb +200 -0
- data/lib/amp/commands/command.rb +507 -0
- data/lib/amp/commands/command_support.rb +137 -0
- data/lib/amp/commands/commands/config.rb +143 -0
- data/lib/amp/commands/commands/help.rb +29 -0
- data/lib/amp/commands/commands/init.rb +10 -0
- data/lib/amp/commands/commands/templates.rb +137 -0
- data/lib/amp/commands/commands/version.rb +7 -0
- data/lib/amp/commands/commands/workflow.rb +28 -0
- data/lib/amp/commands/commands/workflows/git/add.rb +65 -0
- data/lib/amp/commands/commands/workflows/git/copy.rb +27 -0
- data/lib/amp/commands/commands/workflows/git/mv.rb +23 -0
- data/lib/amp/commands/commands/workflows/git/rm.rb +60 -0
- data/lib/amp/commands/commands/workflows/hg/add.rb +53 -0
- data/lib/amp/commands/commands/workflows/hg/addremove.rb +86 -0
- data/lib/amp/commands/commands/workflows/hg/annotate.rb +46 -0
- data/lib/amp/commands/commands/workflows/hg/archive.rb +126 -0
- data/lib/amp/commands/commands/workflows/hg/branch.rb +28 -0
- data/lib/amp/commands/commands/workflows/hg/branches.rb +30 -0
- data/lib/amp/commands/commands/workflows/hg/bundle.rb +115 -0
- data/lib/amp/commands/commands/workflows/hg/clone.rb +95 -0
- data/lib/amp/commands/commands/workflows/hg/commit.rb +42 -0
- data/lib/amp/commands/commands/workflows/hg/copy.rb +31 -0
- data/lib/amp/commands/commands/workflows/hg/debug/dirstate.rb +32 -0
- data/lib/amp/commands/commands/workflows/hg/debug/index.rb +36 -0
- data/lib/amp/commands/commands/workflows/hg/default.rb +9 -0
- data/lib/amp/commands/commands/workflows/hg/diff.rb +30 -0
- data/lib/amp/commands/commands/workflows/hg/forget.rb +11 -0
- data/lib/amp/commands/commands/workflows/hg/heads.rb +25 -0
- data/lib/amp/commands/commands/workflows/hg/identify.rb +23 -0
- data/lib/amp/commands/commands/workflows/hg/import.rb +135 -0
- data/lib/amp/commands/commands/workflows/hg/incoming.rb +85 -0
- data/lib/amp/commands/commands/workflows/hg/info.rb +18 -0
- data/lib/amp/commands/commands/workflows/hg/log.rb +21 -0
- data/lib/amp/commands/commands/workflows/hg/manifest.rb +13 -0
- data/lib/amp/commands/commands/workflows/hg/merge.rb +53 -0
- data/lib/amp/commands/commands/workflows/hg/move.rb +28 -0
- data/lib/amp/commands/commands/workflows/hg/outgoing.rb +61 -0
- data/lib/amp/commands/commands/workflows/hg/pull.rb +74 -0
- data/lib/amp/commands/commands/workflows/hg/push.rb +20 -0
- data/lib/amp/commands/commands/workflows/hg/remove.rb +45 -0
- data/lib/amp/commands/commands/workflows/hg/resolve.rb +83 -0
- data/lib/amp/commands/commands/workflows/hg/revert.rb +53 -0
- data/lib/amp/commands/commands/workflows/hg/root.rb +13 -0
- data/lib/amp/commands/commands/workflows/hg/serve.rb +38 -0
- data/lib/amp/commands/commands/workflows/hg/status.rb +116 -0
- data/lib/amp/commands/commands/workflows/hg/tag.rb +69 -0
- data/lib/amp/commands/commands/workflows/hg/tags.rb +27 -0
- data/lib/amp/commands/commands/workflows/hg/tip.rb +13 -0
- data/lib/amp/commands/commands/workflows/hg/update.rb +27 -0
- data/lib/amp/commands/commands/workflows/hg/verify.rb +9 -0
- data/lib/amp/commands/commands/workflows/hg/view.rb +36 -0
- data/lib/amp/commands/dispatch.rb +181 -0
- data/lib/amp/commands/hooks.rb +81 -0
- data/lib/amp/dependencies/amp_support.rb +1 -0
- data/lib/amp/dependencies/amp_support/ruby_amp_support.rb +103 -0
- data/lib/amp/dependencies/minitar.rb +979 -0
- data/lib/amp/dependencies/priority_queue.rb +18 -0
- data/lib/amp/dependencies/priority_queue/c_priority_queue.rb +1 -0
- data/lib/amp/dependencies/priority_queue/poor_priority_queue.rb +46 -0
- data/lib/amp/dependencies/priority_queue/ruby_priority_queue.rb +525 -0
- data/lib/amp/dependencies/python_config.rb +211 -0
- data/lib/amp/dependencies/trollop.rb +713 -0
- data/lib/amp/dependencies/zip/ioextras.rb +155 -0
- data/lib/amp/dependencies/zip/stdrubyext.rb +111 -0
- data/lib/amp/dependencies/zip/tempfile_bugfixed.rb +186 -0
- data/lib/amp/dependencies/zip/zip.rb +1850 -0
- data/lib/amp/dependencies/zip/zipfilesystem.rb +609 -0
- data/lib/amp/dependencies/zip/ziprequire.rb +90 -0
- data/lib/amp/encoding/base85.rb +97 -0
- data/lib/amp/encoding/binary_diff.rb +82 -0
- data/lib/amp/encoding/difflib.rb +166 -0
- data/lib/amp/encoding/mercurial_diff.rb +378 -0
- data/lib/amp/encoding/mercurial_patch.rb +1 -0
- data/lib/amp/encoding/patch.rb +292 -0
- data/lib/amp/encoding/pure_ruby/ruby_mercurial_patch.rb +123 -0
- data/lib/amp/extensions/ditz.rb +41 -0
- data/lib/amp/extensions/lighthouse.rb +167 -0
- data/lib/amp/graphs/ancestor.rb +147 -0
- data/lib/amp/graphs/copies.rb +261 -0
- data/lib/amp/merges/merge_state.rb +164 -0
- data/lib/amp/merges/merge_ui.rb +322 -0
- data/lib/amp/merges/simple_merge.rb +450 -0
- data/lib/amp/profiling_hacks.rb +36 -0
- data/lib/amp/repository/branch_manager.rb +234 -0
- data/lib/amp/repository/dir_state.rb +950 -0
- data/lib/amp/repository/journal.rb +203 -0
- data/lib/amp/repository/lock.rb +207 -0
- data/lib/amp/repository/repositories/bundle_repository.rb +214 -0
- data/lib/amp/repository/repositories/http_repository.rb +377 -0
- data/lib/amp/repository/repositories/local_repository.rb +2661 -0
- data/lib/amp/repository/repository.rb +94 -0
- data/lib/amp/repository/store.rb +485 -0
- data/lib/amp/repository/tag_manager.rb +319 -0
- data/lib/amp/repository/updatable.rb +532 -0
- data/lib/amp/repository/verification.rb +431 -0
- data/lib/amp/repository/versioned_file.rb +475 -0
- data/lib/amp/revlogs/bundle_revlogs.rb +246 -0
- data/lib/amp/revlogs/changegroup.rb +217 -0
- data/lib/amp/revlogs/changelog.rb +338 -0
- data/lib/amp/revlogs/changeset.rb +521 -0
- data/lib/amp/revlogs/file_log.rb +165 -0
- data/lib/amp/revlogs/index.rb +493 -0
- data/lib/amp/revlogs/manifest.rb +195 -0
- data/lib/amp/revlogs/node.rb +18 -0
- data/lib/amp/revlogs/revlog.rb +1032 -0
- data/lib/amp/revlogs/revlog_support.rb +126 -0
- data/lib/amp/server/amp_user.rb +44 -0
- data/lib/amp/server/extension/amp_extension.rb +396 -0
- data/lib/amp/server/extension/authorization.rb +201 -0
- data/lib/amp/server/fancy_http_server.rb +252 -0
- data/lib/amp/server/fancy_views/_browser.haml +28 -0
- data/lib/amp/server/fancy_views/_diff_file.haml +13 -0
- data/lib/amp/server/fancy_views/_navbar.haml +17 -0
- data/lib/amp/server/fancy_views/changeset.haml +31 -0
- data/lib/amp/server/fancy_views/commits.haml +32 -0
- data/lib/amp/server/fancy_views/file.haml +35 -0
- data/lib/amp/server/fancy_views/file_diff.haml +23 -0
- data/lib/amp/server/fancy_views/harshcss/all_hallows_eve.css +72 -0
- data/lib/amp/server/fancy_views/harshcss/amy.css +147 -0
- data/lib/amp/server/fancy_views/harshcss/twilight.css +138 -0
- data/lib/amp/server/fancy_views/stylesheet.sass +175 -0
- data/lib/amp/server/http_server.rb +140 -0
- data/lib/amp/server/repo_user_management.rb +287 -0
- data/lib/amp/support/amp_config.rb +164 -0
- data/lib/amp/support/amp_ui.rb +287 -0
- data/lib/amp/support/docs.rb +54 -0
- data/lib/amp/support/generator.rb +78 -0
- data/lib/amp/support/ignore.rb +144 -0
- data/lib/amp/support/loaders.rb +93 -0
- data/lib/amp/support/logger.rb +103 -0
- data/lib/amp/support/match.rb +151 -0
- data/lib/amp/support/multi_io.rb +87 -0
- data/lib/amp/support/openers.rb +121 -0
- data/lib/amp/support/ruby_19_compatibility.rb +66 -0
- data/lib/amp/support/support.rb +1095 -0
- data/lib/amp/templates/blank.commit.erb +23 -0
- data/lib/amp/templates/blank.log.erb +18 -0
- data/lib/amp/templates/default.commit.erb +23 -0
- data/lib/amp/templates/default.log.erb +26 -0
- data/lib/amp/templates/template.rb +165 -0
- data/site/Rakefile +24 -0
- data/site/src/about/ampfile.haml +57 -0
- data/site/src/about/commands.haml +106 -0
- data/site/src/about/index.haml +33 -0
- data/site/src/about/performance.haml +31 -0
- data/site/src/about/workflows.haml +34 -0
- data/site/src/contribute/index.haml +65 -0
- data/site/src/contribute/style.haml +297 -0
- data/site/src/css/active4d.css +114 -0
- data/site/src/css/all_hallows_eve.css +72 -0
- data/site/src/css/all_themes.css +3299 -0
- data/site/src/css/amp.css +260 -0
- data/site/src/css/amy.css +147 -0
- data/site/src/css/blackboard.css +88 -0
- data/site/src/css/brilliance_black.css +605 -0
- data/site/src/css/brilliance_dull.css +599 -0
- data/site/src/css/cobalt.css +149 -0
- data/site/src/css/cur_amp.css +185 -0
- data/site/src/css/dawn.css +121 -0
- data/site/src/css/eiffel.css +121 -0
- data/site/src/css/espresso_libre.css +109 -0
- data/site/src/css/idle.css +62 -0
- data/site/src/css/iplastic.css +80 -0
- data/site/src/css/lazy.css +73 -0
- data/site/src/css/mac_classic.css +123 -0
- data/site/src/css/magicwb_amiga.css +104 -0
- data/site/src/css/pastels_on_dark.css +188 -0
- data/site/src/css/reset.css +55 -0
- data/site/src/css/slush_poppies.css +85 -0
- data/site/src/css/spacecadet.css +51 -0
- data/site/src/css/sunburst.css +180 -0
- data/site/src/css/twilight.css +137 -0
- data/site/src/css/zenburnesque.css +91 -0
- data/site/src/get/index.haml +32 -0
- data/site/src/helpers.rb +121 -0
- data/site/src/images/amp_logo.png +0 -0
- data/site/src/images/carbonica.png +0 -0
- data/site/src/images/revolution.png +0 -0
- data/site/src/images/tab-bg.png +0 -0
- data/site/src/images/tab-sliding-left.png +0 -0
- data/site/src/images/tab-sliding-right.png +0 -0
- data/site/src/include/_footer.haml +22 -0
- data/site/src/include/_header.haml +17 -0
- data/site/src/index.haml +104 -0
- data/site/src/learn/index.haml +46 -0
- data/site/src/scripts/jquery-1.3.2.min.js +19 -0
- data/site/src/scripts/jquery.cookie.js +96 -0
- data/tasks/stats.rake +155 -0
- data/tasks/yard.rake +171 -0
- data/test/dirstate_tests/dirstate +0 -0
- data/test/dirstate_tests/hgrc +5 -0
- data/test/dirstate_tests/test_dir_state.rb +192 -0
- data/test/functional_tests/resources/.hgignore +2 -0
- data/test/functional_tests/resources/STYLE.txt +25 -0
- data/test/functional_tests/resources/command.rb +372 -0
- data/test/functional_tests/resources/commands/annotate.rb +57 -0
- data/test/functional_tests/resources/commands/experimental/lolcats.rb +17 -0
- data/test/functional_tests/resources/commands/heads.rb +22 -0
- data/test/functional_tests/resources/commands/manifest.rb +12 -0
- data/test/functional_tests/resources/commands/status.rb +90 -0
- data/test/functional_tests/resources/version2/.hgignore +5 -0
- data/test/functional_tests/resources/version2/STYLE.txt +25 -0
- data/test/functional_tests/resources/version2/command.rb +372 -0
- data/test/functional_tests/resources/version2/commands/annotate.rb +45 -0
- data/test/functional_tests/resources/version2/commands/experimental/lolcats.rb +17 -0
- data/test/functional_tests/resources/version2/commands/heads.rb +22 -0
- data/test/functional_tests/resources/version2/commands/manifest.rb +12 -0
- data/test/functional_tests/resources/version2/commands/status.rb +90 -0
- data/test/functional_tests/resources/version3/.hgignore +5 -0
- data/test/functional_tests/resources/version3/STYLE.txt +31 -0
- data/test/functional_tests/resources/version3/command.rb +376 -0
- data/test/functional_tests/resources/version3/commands/annotate.rb +45 -0
- data/test/functional_tests/resources/version3/commands/experimental/lolcats.rb +17 -0
- data/test/functional_tests/resources/version3/commands/heads.rb +22 -0
- data/test/functional_tests/resources/version3/commands/manifest.rb +12 -0
- data/test/functional_tests/resources/version3/commands/status.rb +90 -0
- data/test/functional_tests/resources/version4/.hgignore +5 -0
- data/test/functional_tests/resources/version4/STYLE.txt +31 -0
- data/test/functional_tests/resources/version4/command.rb +376 -0
- data/test/functional_tests/resources/version4/commands/experimental/lolcats.rb +17 -0
- data/test/functional_tests/resources/version4/commands/heads.rb +22 -0
- data/test/functional_tests/resources/version4/commands/manifest.rb +12 -0
- data/test/functional_tests/resources/version4/commands/stats.rb +25 -0
- data/test/functional_tests/resources/version4/commands/status.rb +90 -0
- data/test/functional_tests/resources/version5_1/.hgignore +5 -0
- data/test/functional_tests/resources/version5_1/STYLE.txt +2 -0
- data/test/functional_tests/resources/version5_1/command.rb +374 -0
- data/test/functional_tests/resources/version5_1/commands/experimental/lolcats.rb +17 -0
- data/test/functional_tests/resources/version5_1/commands/heads.rb +22 -0
- data/test/functional_tests/resources/version5_1/commands/manifest.rb +12 -0
- data/test/functional_tests/resources/version5_1/commands/stats.rb +25 -0
- data/test/functional_tests/resources/version5_1/commands/status.rb +90 -0
- data/test/functional_tests/resources/version5_2/.hgignore +5 -0
- data/test/functional_tests/resources/version5_2/STYLE.txt +14 -0
- data/test/functional_tests/resources/version5_2/command.rb +376 -0
- data/test/functional_tests/resources/version5_2/commands/experimental/lolcats.rb +17 -0
- data/test/functional_tests/resources/version5_2/commands/manifest.rb +12 -0
- data/test/functional_tests/resources/version5_2/commands/newz.rb +12 -0
- data/test/functional_tests/resources/version5_2/commands/stats.rb +25 -0
- data/test/functional_tests/resources/version5_2/commands/status.rb +90 -0
- data/test/functional_tests/test_functional.rb +604 -0
- data/test/localrepo_tests/test_local_repo.rb +121 -0
- data/test/localrepo_tests/testrepo.tar.gz +0 -0
- data/test/manifest_tests/00manifest.i +0 -0
- data/test/manifest_tests/test_manifest.rb +72 -0
- data/test/merge_tests/base.txt +10 -0
- data/test/merge_tests/expected.local.txt +16 -0
- data/test/merge_tests/local.txt +11 -0
- data/test/merge_tests/remote.txt +11 -0
- data/test/merge_tests/test_merge.rb +26 -0
- data/test/revlog_tests/00changelog.i +0 -0
- data/test/revlog_tests/revision_added_changelog.i +0 -0
- data/test/revlog_tests/test_adding_index.i +0 -0
- data/test/revlog_tests/test_revlog.rb +333 -0
- data/test/revlog_tests/testindex.i +0 -0
- data/test/store_tests/store.tar.gz +0 -0
- data/test/store_tests/test_fncache_store.rb +122 -0
- data/test/test_amp.rb +9 -0
- data/test/test_base85.rb +14 -0
- data/test/test_bdiff.rb +42 -0
- data/test/test_commands.rb +122 -0
- data/test/test_difflib.rb +50 -0
- data/test/test_helper.rb +15 -0
- data/test/test_journal.rb +29 -0
- data/test/test_match.rb +134 -0
- data/test/test_mdiff.rb +74 -0
- data/test/test_mpatch.rb +14 -0
- data/test/test_support.rb +24 -0
- metadata +385 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
!!! 1.1
|
2
|
+
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
|
3
|
+
%head
|
4
|
+
%meta{ :content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type" }
|
5
|
+
%title
|
6
|
+
Amp | Version Control Revolution | About Amp
|
7
|
+
= stylesheets :reset, :amp, :all_themes
|
8
|
+
= javascripts "jquery-1.3.2.min.js", "jquery.cookie.js"
|
9
|
+
%body.oneColFixCtr
|
10
|
+
= render("include/_header.haml", :selected => "about")
|
11
|
+
.infopage#container
|
12
|
+
.body-width
|
13
|
+
.floatleft{ :style => "width:90%; padding:8px 0em 6px; margin-left:5%;"}
|
14
|
+
%h2 About #{blue_amp "Amp"}
|
15
|
+
%p
|
16
|
+
#{blue_amp "Amp"} is a general-purpose version-control system. It currently implements #{hg_link}, and we hope to support #{git_link}, #{link_to "http://bazaar-vcs.org/", "bazaar"}, #{link_to "http://subversion.tigris.org/", "svn"}, #{link_to "http://www.nongnu.org/cvs/", "cvs" }, and #{link_to "http://darcs.net/", "darcs" } in the future. Why? Well, that leads us to the question: "Why #{blue_amp "Amp"}?"
|
17
|
+
%h2 #{blue_amp "Amp"} is NOT:
|
18
|
+
%p
|
19
|
+
#{blue_amp "Amp"} does not define a repository format, and most likely never will.
|
20
|
+
%h2 Then why make a VCS?
|
21
|
+
%p
|
22
|
+
#{blue_amp "Amp"} exists because there's plenty of excellent repository formats out there, but none of them are truly good <em>software</em>. We chose #{hg_link} as our first VCS to implement because it comes closest to what we feel is a solid user experience, and that's what we're building upon.
|
23
|
+
%br/
|
24
|
+
%br/
|
25
|
+
#{blue_amp "Amp"} exists to make VCS work for you. Want to add your own commands? #{commands_link "Write a few lines of code"}. Want to use git's commands on a Mercurial repository, switches and all? #{blue_amp "Amp"} is #{workflows_link "working on it"}. Our goal is to produce a piece of software that lets you forget that you're working on #{git_link} project one moment and a #{hg_link} project the next.
|
26
|
+
%h2 #{blue_amp "Amp"}'s Features
|
27
|
+
%ul.bullets{:style => "margin-left:2em;"}
|
28
|
+
%li #{workflows_link "Workflows"} - customizable command sets (e.g. git's commands, svn's commands)
|
29
|
+
%li #{commands_link "Commands"} - work with your VCS on your terms
|
30
|
+
%li #{ampfile_link "Ampfiles"} - tweak amp's settings for a specific repository with one file
|
31
|
+
%li Want more features? #{link_to "/contribute/", "Help develop"} #{blue_amp "Amp"}! We've got a lot planned!
|
32
|
+
|
33
|
+
= render("include/_footer.haml")
|
@@ -0,0 +1,31 @@
|
|
1
|
+
!!! 1.1
|
2
|
+
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
|
3
|
+
%head
|
4
|
+
%meta{ :content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type" }
|
5
|
+
%title
|
6
|
+
Amp | Version Control Revolution | Ampfiles
|
7
|
+
= stylesheets :reset, :amp, :all_themes
|
8
|
+
= javascripts "jquery-1.3.2.min.js", "jquery.cookie.js"
|
9
|
+
%body.oneColFixCtr
|
10
|
+
= render("include/_header.haml", :selected => "about")
|
11
|
+
.infopage#container
|
12
|
+
.body-width
|
13
|
+
.floatleft{ :style => "width:90%; padding:8px 0em 6px; margin-left:5%;"}
|
14
|
+
%h2 Amp Performance
|
15
|
+
%p
|
16
|
+
We want #{blue_amp} to be fast. Like, as fast as possible. The biggest problem: Ruby isn't very fast. So here's our current goal: <b>we want #{blue_amp} to be as fast as mercurial</b>.
|
17
|
+
%p
|
18
|
+
#{hg_link "Mercurial"} is written in Python, which according to the #{link_to "http://shootout.alioth.debian.org/", "Great Language Shootout"} is #{link_to "http://shootout.alioth.debian.org/u64q/benchmark.php?test=all&lang=python&lang2=ruby&box=1", "3-10 times slower than Python"}. That's for MRI 1.8.6 - here's a link to #{link_to "http://shootout.alioth.debian.org/u64q/benchmark.php?test=all&lang=python&lang2=jruby&box=1", "JRuby"} and #{link_to "http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=yarv&lang2=python&box=1", "Ruby 1.9"}, which are similar though an improvement.
|
19
|
+
%h2 So how's that going?
|
20
|
+
%p
|
21
|
+
We hope to have some direct, auto-generated benchmarks up here soon. But for now - many amp operations are <b>only 1.5-2 times slower than Mercurial</b>. That's within the range that the language barrier is the major factor. Of course, we hope to do better.
|
22
|
+
%h2 Measuring Amp Performance
|
23
|
+
%p
|
24
|
+
What's interesting about #{blue_amp} is that most applications concerned with speed are optimizing long-running processes. Servers, web apps, graphics processes come to mind. But #{blue_amp} is completely different - VCS clients are invoked dozens of times a day. We need the process to just end fast. That means it needs to start quickly, run quickly, and clean up quickly.
|
25
|
+
%p
|
26
|
+
We're finding a lot of ways to achieve this, and will be writing some blog posts now that #{blue_amp} is being looked at.
|
27
|
+
%h2 How can I help?
|
28
|
+
%p
|
29
|
+
Head on over the #{contribute_link} page and join us! There's plenty of places where we can optimize code (or even if you want to help get some auto-generated benchmarks on this page, that'd be awesome too!)
|
30
|
+
|
31
|
+
= render("include/_footer.haml")
|
@@ -0,0 +1,34 @@
|
|
1
|
+
!!! 1.1
|
2
|
+
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
|
3
|
+
%head
|
4
|
+
%meta{ :content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type" }
|
5
|
+
%title
|
6
|
+
Amp | Version Control Revolution | Amp Workflows
|
7
|
+
= stylesheets :reset, :amp, :all_themes
|
8
|
+
= javascripts "jquery-1.3.2.min.js", "jquery.cookie.js"
|
9
|
+
%body.oneColFixCtr
|
10
|
+
= render("include/_header.haml", :selected => "about")
|
11
|
+
.infopage#container
|
12
|
+
.body-width
|
13
|
+
.floatleft{ :style => "width:90%; padding:8px 0em 6px; margin-left:5%;"}
|
14
|
+
%h2 What's a workflow?
|
15
|
+
%p
|
16
|
+
This might be a little confusing. We coined this term for ourselves before we realized that #{link_to "http://www.bazaar-vcs.org/", "bazaar"} had their own workflows. Ours are different. A workflow in #{blue_amp} parlance is <b>a set of commands that go together.</b> #{blue_amp "Amp"} currently has a #{hg_link} workflow: a set of commands that mimics #{hg_link}'s command interface. There is a 1-1 mapping between (most of) Mercurial's commands and the commands in the hg workflow. We're still working on matching them exactly, but we're close.
|
17
|
+
%h2 When does this get interesting?
|
18
|
+
%p
|
19
|
+
It gets interesting because we're working on a #{git_link} workflow. So, if you cut your teeth on git but are working on a project using Mercurial, we're going to let you use git's commands. Think about it - almost all of the basic operations in git have a similar command in Mercurial. The difference are in basic command syntax ( #{shellscript "git push origin master"} vs #{shellscript "hg push"} ) and in the options.
|
20
|
+
%h2 Why do options matter?
|
21
|
+
%p
|
22
|
+
The allowed options matter because they're what we get used to in our command-line software, and there often <i>is not</i> analogous options between VCS clients. #{git_link "Git"} has #{shellscript "git commit --reuse-message=123"}, but there's no such option in #{hg_link}. That's just one point. When you use the same software for long, you develop sets of options you get used to. Switch to a project with a different VCS, and your favorite options aren't there. Annoying. Think of workflows as theming your VCS.
|
23
|
+
%h2 How do I change my workflow?
|
24
|
+
%p
|
25
|
+
#{shellscript "amp workflow git"}. Or #{shellscript "amp workflow hg"}.
|
26
|
+
%h2 Git != Mercurial
|
27
|
+
%p
|
28
|
+
The fact remains that the different VCS systems have different commands, in part, because the underlying repositories are different. Git allows for destructive operations in it's repository and exposes that in in some of its options and commands. Mercurial doesn't allow it. So what happens when you do a #{shellscript "git filter-branch"} on a #{hg_link} repository?
|
29
|
+
%p
|
30
|
+
%b It will fail, and tell you that you requested an impossible action. Rely on that.
|
31
|
+
%h2 The git workflow sucks.
|
32
|
+
%p
|
33
|
+
We know. We're working on it. But #{commands_link "writing commands"} is actually pretty easy - do you want to #{contribute_link "help us out"}?
|
34
|
+
= render("include/_footer.haml")
|
@@ -0,0 +1,65 @@
|
|
1
|
+
!!! 1.1
|
2
|
+
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
|
3
|
+
%head
|
4
|
+
%meta{ :content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type" }
|
5
|
+
%title
|
6
|
+
Amp | Version Control Revolution | Contribute
|
7
|
+
= stylesheets :reset, :amp, :all_themes
|
8
|
+
= javascripts "jquery-1.3.2.min.js", "jquery.cookie.js"
|
9
|
+
%body.oneColFixCtr
|
10
|
+
= render("include/_header.haml", :selected => "contribute")
|
11
|
+
.infopage#container
|
12
|
+
.body-width
|
13
|
+
.floatleft{ :style => "width:90%; padding:8px 0em 6px; margin-left:5%;"}
|
14
|
+
%h2 How can I help?
|
15
|
+
%p
|
16
|
+
There's a ton you can do! We need people to write nice fancy writeups for the site, and we need developers who can add features. We've got #{link_to "#list", "lots of places you can help"}, and a #{link_to "#features", "good list of features"} we want to develop to reach #{blue_amp}'s goals, and developers will make that easier! Here's our online resources you can use to help:
|
17
|
+
%ul.bullets{:style => "margin-left:2em;"}
|
18
|
+
%li The #{link_to "http://bitbucket.org/carbonica/amp/", "BitBucket source"}. We accept pull requests!
|
19
|
+
%li Our #{link_to "http://github.com/michaeledgar/amp", "GitHub mirror"}. We accept GitHub pull requests!
|
20
|
+
%li We use #{link_to "http://bitbucket.org/carbonica/amp/issues/?status=new&status=open", "BitBucket's issue tracker."}...
|
21
|
+
%li ... and BitBucket's #{link_to "http://bitbucket.org/carbonica/amp/wiki/Home", "wiki, too."}
|
22
|
+
%li Lastly, we've got a #{link_to "http://groups.google.com/group/amp-vcs/", "Google Group"}.
|
23
|
+
%h2 OK, but how do I submit code?
|
24
|
+
%p
|
25
|
+
#{blue_amp "Amp"} is run on a "commit bit" policy. Get one patch approved, and you have full repo access. Our source is #{link_to "http://bitbucket.org/carbonica/amp/", "hosted at BitBucket"} - just fork us and send a pull request.
|
26
|
+
%p
|
27
|
+
We don't have strict requirements about how you format your patch, but keep in mind that we have to verify your patch is good before we accept the pull. So here's a list of things that will make that faster if you are submitting code:
|
28
|
+
%ul.bullets{:style => "margin-left:2em;"}
|
29
|
+
%li Try to stick to the #{link_to "/contribute/style.html", "code style guidelines"}.
|
30
|
+
%li Include tests! Not required, but it certainly makes it easier to check if your patch works.
|
31
|
+
%li Document your new code! Methods are always documented in #{blue_amp} - end of story.
|
32
|
+
%li Comments-in-code are great for non-trivial algorithms, but we'll be the first to admit our code doesn't have enough inline comments.
|
33
|
+
%li Provide some way for us to know what your patch does - even if you think it's obvious.
|
34
|
+
%p
|
35
|
+
Again, these aren't requirements, but we want you to work on #{blue_amp}, which means we want to approve your patches!
|
36
|
+
%a{:name => "list"}
|
37
|
+
%h2 I'm ready to jump in! Any ideas?
|
38
|
+
%p
|
39
|
+
Here's a list of things to think about, in order from least-to-most effort required:
|
40
|
+
%ul.bullets{:style => "margin-left:2em;"}
|
41
|
+
%li Write for this site! The source for the website is actually stored in the amp repository - a #{shellscript "rake build-website"} will rebuild the site from the source. We like write-ups on major amp features, especially, but anything you think could help, send it in!
|
42
|
+
%li Clean up code in general. If you see code violating style guidelines, fix it up. If you see obvious silliness (branches that never execute, superfluous conditionals, so on) then lend a hand and patch it up!
|
43
|
+
%li Comment existing code. Some methods are undocumented, some enormous methods don't have inline comments explaining things.
|
44
|
+
%li Write tests! We don't have nearly enough tests, and we want to maximize both unit test (where possible) and functional test coverage.
|
45
|
+
%li Ruby-tize the code. There are places where, in our innocent pursuit to port #{hg_link} to Ruby, we directly ported algorithms. We apologize. Help us make it idiomatic.
|
46
|
+
%li Fix bugs on #{lighthouse_link}. These might be simple fixes, they might not. Either way, we'll give you an e-hug.
|
47
|
+
%li Refactor huge methods. There's a few instances where there are simply enormous, mind-numbing methods that need to be cleaned up. They're often the most important methods too, which is probably why nobody has done it yet. Be a hero.
|
48
|
+
%li Take a look at our #{link_to "#features", "feature hit-list"}. These are major goals we hope to achieve in #{blue_amp}'s development. The core team focuses on these when possible.
|
49
|
+
%h2 Feature Hit-List
|
50
|
+
%p
|
51
|
+
These are the features that take the most work, and are the most important to #{blue_amp}'s development.
|
52
|
+
%a{:name => "features"}
|
53
|
+
%ul.bullets{:style => "margin-left:2em;"}
|
54
|
+
%li Support for other repository formats: #{git_link}, #{link_to "http://bazaar-vcs.org/", "bazaar"}, #{link_to "http://subversion.tigris.org/", "svn"}, #{link_to "http://www.nongnu.org/cvs/", "cvs" }, #{link_to "http://darcs.net/", "darcs" }. No shelling out (except when stubbing methods).
|
55
|
+
%li #{workflows_link "Workflows"} for other VCS systems - commands that emulate #{shellscript "bzr push"} instead of #{shellscript "hg push"}, for example.
|
56
|
+
%li Windows support. Honestly, this is primarily just going to be handling file and system paths differently.
|
57
|
+
%li GUI Application on top of #{blue_amp}. Think about that - the one app would support all major VCSs. Cool, eh?
|
58
|
+
%h2 Who works on #{blue_amp}?
|
59
|
+
%p Here's a list of all our contributors, sorted by number of commits:
|
60
|
+
%ul.contributor-list
|
61
|
+
- commit_count.each do |user, commits|
|
62
|
+
%li
|
63
|
+
%span{:style => "width:80px;"}= commits.to_s
|
64
|
+
%span{:style => "width:400px;"}= user
|
65
|
+
= render("include/_footer.haml")
|
@@ -0,0 +1,297 @@
|
|
1
|
+
!!! 1.1
|
2
|
+
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
|
3
|
+
%head
|
4
|
+
%meta{ :content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type" }
|
5
|
+
%title
|
6
|
+
Amp | Version Control Revolution | Contribute
|
7
|
+
= stylesheets :reset, :amp, :all_themes
|
8
|
+
= javascripts "jquery-1.3.2.min.js", "jquery.cookie.js"
|
9
|
+
%body.oneColFixCtr
|
10
|
+
= render("include/_header.haml", :selected => "contribute")
|
11
|
+
.infopage#container
|
12
|
+
.body-width
|
13
|
+
.floatleft{ :style => "width:90%; padding:8px 0em 6px; margin-left:5%;"}
|
14
|
+
%h2 Style Guidelines
|
15
|
+
%p
|
16
|
+
If you want to contribute to #{blue_amp}, we'd love for you to stick to these guidelines as best as you can. #{ruby_link} has a very flexible, beautiful syntax, which means it's quite easy to write quite ugly code in it. This is <b>not</b> a guide to idiomatic Ruby. It's not even a guide to good-looking Ruby. It's just how we like our code done. This document is a work in progress, so if you see something missing, let us know. If you submit code, we'll eventually end up reformatting it to this style anyway. So try to use this guide!
|
17
|
+
|
18
|
+
%h3 Table of Contents
|
19
|
+
%ul.tight
|
20
|
+
%li #{link_to "#general", "General Coding"}
|
21
|
+
%ul.tight
|
22
|
+
%li #{link_to "#multiple-assignment", "Multiple Assignment"}
|
23
|
+
%li #{link_to "#80-columns", "80 Columns"}
|
24
|
+
%li #{link_to "#block-bracing", "Block Bracing"}
|
25
|
+
%li #{link_to "#ternary", "Ternary and &&"}
|
26
|
+
%li #{link_to "#for-in", "for...in"}
|
27
|
+
%li #{link_to "#variables", "Variable Names"}
|
28
|
+
%ul.tight
|
29
|
+
%li #{link_to "#descriptive", "Be Descriptive!"}
|
30
|
+
%li #{link_to "#underscores", "Underscores"}
|
31
|
+
%li #{link_to "#method-defs", "Method Definitions"}
|
32
|
+
%ul.tight
|
33
|
+
%li #{link_to "#parens", "Parentheses"}
|
34
|
+
%li #{link_to "#descriptive-methods", "Descriptive Method Names"}
|
35
|
+
%li #{link_to "#one-liners", "Minimize One-line Methods"}
|
36
|
+
%li #{link_to "#spacing", "Spacing!"}
|
37
|
+
%li #{link_to "#class-methods", "Class (Singleton) Methods"}
|
38
|
+
%li #{link_to "#calling-methods", "Calling Methods"}
|
39
|
+
%ul.tight
|
40
|
+
%li #{link_to "#calling-parens", "Parentheses (Redux)"}
|
41
|
+
%li #{link_to "#options-hashes", "Options Hashes"}
|
42
|
+
|
43
|
+
%a.anchor{:name => "general"}
|
44
|
+
%h2 General Coding
|
45
|
+
%a.anchor{:name => "multiple-assignment"}
|
46
|
+
%h3 Multiple Assignment
|
47
|
+
%p
|
48
|
+
Assigning more than one variable on one line is awesome. As long as it makes sense. If the variables are not related, or the assignments are complex, then you just made things much more confusing. So if you use multiple assignment, the variables should be related, and the values should be concise.
|
49
|
+
%p <b>Unacceptable:</b>
|
50
|
+
.floatleft.dark.rounded.codeholder
|
51
|
+
:syntaxhighlighter
|
52
|
+
repo, user_msg, command_arg = options[:repo], gets, parse_args(2)
|
53
|
+
val1, val2 = proc { |input| input * input.to_i }, proc { |input| input + input.to_i }
|
54
|
+
%p <b>Acceptable:</b>
|
55
|
+
.floatleft.dark.rounded.codeholder
|
56
|
+
:syntaxhighlighter
|
57
|
+
list, others, queue = [], [], []
|
58
|
+
text, date, user = options[:text], options[:date], options[:user]
|
59
|
+
|
60
|
+
%a.anchor{:name => "80-columns"}
|
61
|
+
%h3 80 Columns. If not, 100 columns.
|
62
|
+
%p Self explanatory. We know our long method names make this difficult at times, and we sympathize. Please keep it skinny.
|
63
|
+
|
64
|
+
%a.anchor{:name => "block-bracing"}
|
65
|
+
%h3 Block Bracing
|
66
|
+
%p
|
67
|
+
Blocks can use "do...end" or "{ ... }" syntax. Braces are to be used for one-line blocks, do...end for multi-line blocks.
|
68
|
+
%p <b>Unacceptable:</b>
|
69
|
+
.floatleft.dark.rounded.codeholder
|
70
|
+
:syntaxhighlighter
|
71
|
+
list.map { |item|
|
72
|
+
item.to_s
|
73
|
+
}
|
74
|
+
list.map do |item|; item.to_s; end
|
75
|
+
%p <b>Acceptable:</b>
|
76
|
+
.floatleft.dark.rounded.codeholder
|
77
|
+
:syntaxhighlighter
|
78
|
+
list.map {|item| item.to_s}
|
79
|
+
list.map do |item|
|
80
|
+
item.to_s
|
81
|
+
end
|
82
|
+
|
83
|
+
%a.anchor{:name => "ternary"}
|
84
|
+
%h3 Ternary and &&
|
85
|
+
%p
|
86
|
+
Use ternary when possible. Ruby, sadly, makes a full-out if..else..end block a minimum of 5 lines. So use ternary when you can - it's idiomatic and good to get used to. Also, for short "if X then Y" statements, consider using the && syntax, see below.
|
87
|
+
%p <b>Unacceptable:</b>
|
88
|
+
.floatleft.dark.rounded.codeholder
|
89
|
+
:syntaxhighlighter
|
90
|
+
if index > 10
|
91
|
+
return 5
|
92
|
+
else
|
93
|
+
return 7
|
94
|
+
end
|
95
|
+
if idx
|
96
|
+
x = idx
|
97
|
+
end
|
98
|
+
%p <b>Acceptable:</b>
|
99
|
+
.floatleft.dark.rounded.codeholder
|
100
|
+
:syntaxhighlighter
|
101
|
+
return index > 10 ? 5 : 7
|
102
|
+
idx && x = idx
|
103
|
+
|
104
|
+
%a.anchor{:name => "for-in"}
|
105
|
+
%h3 Never use for..in.
|
106
|
+
%p
|
107
|
+
The #{shellscript "for x in list"} syntax doesn't fly with us. #{link_to "http://blog.grayproductions.net/articles/the_evils_of_the_for_loop", "It isn't exactly the same as calling #each"}. Plus, you can't use { brace } syntax with the for…in loop. So just use #each.
|
108
|
+
%p <b>Unacceptable:</b>
|
109
|
+
.floatleft.dark.rounded.codeholder
|
110
|
+
:syntaxhighlighter
|
111
|
+
for x in 0..9 do
|
112
|
+
p x
|
113
|
+
end
|
114
|
+
%p <b>Acceptable:</b>
|
115
|
+
.floatleft.dark.rounded.codeholder
|
116
|
+
:syntaxhighlighter
|
117
|
+
0..9.each {|i| p i }
|
118
|
+
|
119
|
+
%a.anchor{:name => "variables"}
|
120
|
+
%h2 Variable Names
|
121
|
+
%a.anchor{:name => "descriptive"}
|
122
|
+
%h3 Descriptive!
|
123
|
+
%p
|
124
|
+
Variable names must be descriptive. When dealing with complex systems, nothing more will scare off developers than these kind of variables: #{shellscript "ctx"}, #{shellscript "octx"}, #{shellscript "wctx"}. In #{blue_amp}'s source, those variables should be named #{shellscript "changeset"}, #{shellscript "other_changeset"}, #{shellscript "working_changeset"}. Yes, it's so much longer. We don't care. If you use descriptive variable names, anyone reading your code knows what that variable is for.
|
125
|
+
%p <b>Unacceptable:</b>
|
126
|
+
.floatleft.dark.rounded.codeholder
|
127
|
+
:syntaxhighlighter
|
128
|
+
acs = cs.ancestor
|
129
|
+
%p <b>Acceptable:</b>
|
130
|
+
.floatleft.dark.rounded.codeholder
|
131
|
+
:syntaxhighlighter
|
132
|
+
ancestor_changeset = current_changeset.ancestor
|
133
|
+
%a.anchor{:name => "underscores"}
|
134
|
+
%h3 under_scores, not CaMeLcAsE
|
135
|
+
%p
|
136
|
+
If your variable name has two words, and is longer than say, 6 letters, put an underscore between the words. Don't use camelcase.
|
137
|
+
%p <b>Unacceptable:</b>
|
138
|
+
.floatleft.dark.rounded.codeholder
|
139
|
+
:syntaxhighlighter
|
140
|
+
currentRepositoryList = currentRepository.changesets
|
141
|
+
%p <b>Acceptable:</b>
|
142
|
+
.floatleft.dark.rounded.codeholder
|
143
|
+
:syntaxhighlighter
|
144
|
+
current_repository_list = current_repository.changesets
|
145
|
+
|
146
|
+
%a.anchor{:name => "method-defs"}
|
147
|
+
%h2 Method Definitions
|
148
|
+
%a.anchor{:name => "parens"}
|
149
|
+
%h3 Parentheses!
|
150
|
+
%p
|
151
|
+
When defining a method that takes arguments, include the parentheses around the arguments. If the method has no arguments, do not include an empty set of parentheses.
|
152
|
+
%p <b>Unacceptable:</b>
|
153
|
+
.floatleft.dark.rounded.codeholder
|
154
|
+
:syntaxhighlighter
|
155
|
+
def silly_method message, *args
|
156
|
+
puts msg + args.join("\n")
|
157
|
+
end
|
158
|
+
def empty_method()
|
159
|
+
puts "Empty"
|
160
|
+
end
|
161
|
+
%p <b>Acceptable:</b>
|
162
|
+
.floatleft.dark.rounded.codeholder
|
163
|
+
:syntaxhighlighter
|
164
|
+
def silly_method(message, *args)
|
165
|
+
puts msg + args.join("\n")
|
166
|
+
end
|
167
|
+
def empty_method
|
168
|
+
puts "Empty"
|
169
|
+
end
|
170
|
+
%a.anchor{:name => "descriptive-methods"}
|
171
|
+
%h3 Descriptive Method Names
|
172
|
+
%p
|
173
|
+
The title of a method is like the title of a poem: it should provide insight. Make your method names mean something. Now, we have in some cases very long method names for clarity of those reading our documentation. It is acceptable to provide a nice, shorter alias to the method, after defining it with a descriptive name.
|
174
|
+
%p Below is a comparison between the #{hg_link} methods (slightly Ruby-tized) to the corresponding #{blue_amp} methods here. They perform the exact same operation.
|
175
|
+
%p <b>Unacceptable:</b>
|
176
|
+
.floatleft.dark.rounded.codeholder
|
177
|
+
:syntaxhighlighter
|
178
|
+
def parents(node)
|
179
|
+
def parentrevs(rev)
|
180
|
+
%p <b>Acceptable:</b>
|
181
|
+
.floatleft.dark.rounded.codeholder
|
182
|
+
:syntaxhighlighter
|
183
|
+
def parents_for_node(id)
|
184
|
+
def parent_indices_for_index(index)
|
185
|
+
|
186
|
+
%a.anchor{:name => "one-liners"}
|
187
|
+
%h3 Minimize One-line Definitions
|
188
|
+
%p
|
189
|
+
There's a time and a place for everything, and one-line methods have a place. If your method body (between <i>def</i> and <i>end</i>) is already one line, and contains no complex logic, then a one-line method might be acceptable. Otherwise, make it a normal, multiline method.
|
190
|
+
%p <b>Unacceptable:</b>
|
191
|
+
.floatleft.dark.rounded.codeholder
|
192
|
+
:syntaxhighlighter
|
193
|
+
# has 3 separate body lines packed into 1
|
194
|
+
def list_stuff(arg1, arg2); arg3 = arg1 + arg2; puts arg3; puts arg1+arg2; end
|
195
|
+
# one line method body, but it's complex enough to put on its own line
|
196
|
+
def silly_one_liner(arg1); arg1.map {|i| i.nil? ? "" : i.to_s}; end
|
197
|
+
%p <b>Acceptable:</b>
|
198
|
+
.floatleft.dark.rounded.codeholder
|
199
|
+
:syntaxhighlighter
|
200
|
+
def silly_one_liner(arg1)
|
201
|
+
arg1.map {|i| i.nil? ? "" : i.to_s}
|
202
|
+
end
|
203
|
+
# simple enough that one line might work
|
204
|
+
def get_value; self.value; end
|
205
|
+
|
206
|
+
%a.anchor{:name => "spacing"}
|
207
|
+
%h3 Spacing!
|
208
|
+
%p Spacing in your method definitions is a picky matter, and we'll be the first to admit that our style is pretty arbitrary. If you make a good case for a different spacing style, we'll hear it. But for now: put spaces between arguments, none between method name and the following open-parentheses. For optional arguments, but do put spaces around the equals sign. For "splat" or variable-argument holders, don't put spaces between the * and the variable name.
|
209
|
+
%p <b>Unacceptable:</b>
|
210
|
+
.floatleft.dark.rounded.codeholder
|
211
|
+
:syntaxhighlighter
|
212
|
+
def method_one(arg1,arg2)
|
213
|
+
def method_two (arg1, arg2, * rest)
|
214
|
+
def method_three(arg1, arg2, arg3 = {})
|
215
|
+
%p <b>Acceptable:</b>
|
216
|
+
.floatleft.dark.rounded.codeholder
|
217
|
+
:syntaxhighlighter
|
218
|
+
def method_one(arg1, arg2)
|
219
|
+
def method_two(arg1, arg2, *rest)
|
220
|
+
def method_three(arg1, arg2, arg3={})
|
221
|
+
|
222
|
+
%a.anchor{:name => "class-methods"}
|
223
|
+
%h3 Class (Singleton) Methods
|
224
|
+
%p
|
225
|
+
If you are going to be adding methods to a class, don't use #{shellscript "def self.method"}, use the #{shellscript "class << self"} syntax. This helps delineate which sections of the code belong to the class, and which sections are instance methods. Also, if you need to add class-level attr_accessors, the #{shellscript "class << self"} block is the best way to do that.
|
226
|
+
%p <b>Unacceptable:</b>
|
227
|
+
.floatleft.dark.rounded.codeholder
|
228
|
+
:syntaxhighlighter
|
229
|
+
class Silly
|
230
|
+
def self.monkey
|
231
|
+
puts "monkey"
|
232
|
+
end
|
233
|
+
def instance_method
|
234
|
+
puts "yarr"
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
%p <b>Acceptable:</b>
|
239
|
+
.floatleft.dark.rounded.codeholder
|
240
|
+
:syntaxhighlighter
|
241
|
+
class Silly
|
242
|
+
class << self
|
243
|
+
def monkey
|
244
|
+
puts "monkey"
|
245
|
+
end
|
246
|
+
end
|
247
|
+
def instance_method
|
248
|
+
puts "yarr"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
%a.anchor{:name => "calling-methods"}
|
252
|
+
%h2 Calling Methods
|
253
|
+
%a.anchor{:name => "calling-parens"}
|
254
|
+
%h3 Parentheses?
|
255
|
+
%p
|
256
|
+
This one's a tricky one. Generally speaking, you don't need to put parentheses around method arguments in Ruby unless you are nesting method calls. (This isn't always true, there are a few exceptions) This has the effect of making some method calls look like statements. However, you can't chain methods off of a no-parentheses method call, and they have some quirks in conditionals. However, for simple, single method calls, <b>we like this technique.</b> The examples should help clear this up.
|
257
|
+
%p <b>Unacceptable:</b>
|
258
|
+
.floatleft.dark.rounded.codeholder
|
259
|
+
:syntaxhighlighter
|
260
|
+
# always use parentheses on calls inside a block or as an argument to a method
|
261
|
+
puts list.map {|item| item.unshift "h"}
|
262
|
+
# You don't need parentheses here. Strip 'em.
|
263
|
+
puts("hi there")
|
264
|
+
# weirdly enough, this is a syntax error. The exist? call needs parentheses.
|
265
|
+
if file.any? && File.exist? file
|
266
|
+
%p <b>Acceptable:</b>
|
267
|
+
.floatleft.dark.rounded.codeholder
|
268
|
+
:syntaxhighlighter
|
269
|
+
puts list.map {|item| item.unshift("h") }
|
270
|
+
|
271
|
+
STDERR.puts message
|
272
|
+
|
273
|
+
if File.exist? file
|
274
|
+
input = File.read file
|
275
|
+
end
|
276
|
+
|
277
|
+
my_repo.commit revisions, files, :text => options[:text]
|
278
|
+
%a.anchor{:name => "options-hashes"}
|
279
|
+
%h3 Options Hashes
|
280
|
+
%p
|
281
|
+
Ruby has a neat way of doing named optional arguments, until Ruby 2.0 comes out: options hashes. If a method takes a hash as its last argument, you don't need to put { curly braces } around the hash argument. These hashes typically take #{link_to "http://www.troubleshooters.com/codecorn/ruby/symbols.htm", "Symbols"} as keys, instead of strings, due to memory savings. There are some methods in #{blue_amp} that can take many, many options, and formatting calls to these methods can be tricky. The general rule is: if your options wrap to another line, put each option on its own line. Here's how it's done:
|
282
|
+
%p <b>Unacceptable:</b>
|
283
|
+
.floatleft.dark.rounded.codeholder
|
284
|
+
:syntaxhighlighter
|
285
|
+
result = repo.commit arg1, arg2, "text" => "hi", "user" => "hello"
|
286
|
+
result = repo.commit arg1, arg2, :text => "hi", :user => "hello", :date => Time.now,
|
287
|
+
:changeset_base => repo[arg1.to_i], :ancestor => some_other_changeset
|
288
|
+
%p <b>Acceptable:</b>
|
289
|
+
.floatleft.dark.rounded.codeholder
|
290
|
+
:syntaxhighlighter
|
291
|
+
result = repo.commit arg1, arg2, :text => "hi", :user => "hello"
|
292
|
+
result = repo.commit arg1, arg2, :text => "hi",
|
293
|
+
:user => "hello",
|
294
|
+
:date => Time.now,
|
295
|
+
:changeset_base => repo[arg1.to_i],
|
296
|
+
:ancestor => some_other_changeset
|
297
|
+
= render("include/_footer.haml")
|