git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Emily Shaffer via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Emily Shaffer <emilyshaffer@google.com>
Subject: Re: [PATCH 1/1] documentation: add lab for first contribution
Date: Fri, 12 Apr 2019 12:20:21 +0900	[thread overview]
Message-ID: <xmqqef67zz7u.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <8b71fe78719aa40feee509e6a6229775daa79a2f.1555007520.git.gitgitgadget@gmail.com> (Emily Shaffer via GitGitGadget's message of "Thu, 11 Apr 2019 11:32:01 -0700 (PDT)")

"Emily Shaffer via GitGitGadget" <gitgitgadget@gmail.com> writes:

> diff --git a/Documentation/MyFirstContribution b/Documentation/MyFirstContribution
> new file mode 100644
> index 0000000000..9b87e424d6
> --- /dev/null
> +++ b/Documentation/MyFirstContribution
> @@ -0,0 +1,674 @@
> +My First Contribution
> +=====================
> +
> +== Summary

Just a minor nit but only the document title uses the underlined
mark-up format, but not each of its sections?

Is the goal of this document to help those who want to contribute to
*THIS* project, or to any project that happens to use Git as their
source control tool of choice?  I take it to be the former, but if
that is the case, perhaps extend the title to "My First Contribution
to the Git Project" or something, so that those who use us merely as
a tool can tell that it can be ignored more easily?

> +=== Set Up Your Workspace
> +
> +Let's start by making a development branch to work on our changes. Per
> +`Documentation/SubmittingPatches`, since a brand new command is a new feature,
> +it's fine to base your work on `master`. However, in the future for bugfixes,
> +etc., you should check that doc and base it on the appropriate branch.
> +
> +For the purposes of this doc, we will base all our work on `master`. Before
> +running the command below, ensure that you are on `master` first so your
> +branch diverges at the right point.
> +
> +----
> +git checkout -b psuh
> +----

An obvious and more explicit alternative, which may be better both
for tutorial purposes (as it illustrates what is going on better by
not relying on an implicit default) and for real-life (as it does
not require checking out 'master' only to switch away from a new
branch, saving a entry of two in the HEAD reflog) is

	For the purposes of this doc, we will base all our work on
	the `master` branch of the upstream project.  Fork the
	`psuh` branch you use for your development like so:

	----
	$ git checkout -b psuh origin/master
	----

> +=== Adding a new command
> +
> +Lots of the main useful commands are written as builtins, which means they are

Drop 'useful', and possibly 'main' as well.  I would have written
"Many of the Git subcommands are..." if I were writing it myself
without reading yours.

> +implemented in C and compiled into the main `git` executable.. So it is
> +informative to implement `git psuh` as a builtin.
> +Create a new file in `builtin/` called `psuh.c`.

I am not sure what "informative" in this context means.

	Typically a built-in subcommand is implemented as a function
	whose name is "cmd_" followed by the name of the subcommand
	and stored in a C source file that is named after the name
	of the subcommand inside `builtin/` directory, so it is
	natural to implement your `psuh` command as a cmd_psuh()
	function in `builtin/psuh.c`.

> +The entry point of your new command needs to match a certain signature:
> +----
> +int cmd_psuh(int argc, const char **argv, const char *prefix)
> +----
> +
> +We'll also need to add the extern declaration of psuh; open up `builtin.h`,
> +find the declaration for cmd_push, and add a new line for psuh:
> +
> +----
> +extern int cmd_psuh(int argc, const char **argv, const char *prefix);
> +----

I think there is a push to drop the "extern " from decls of
functions in *.h header files.

> +Be sure to `#include "builtin.h"` in your `psuh.c`.
> +
> +Go ahead and add some throwaway printf to that method. This is a decent
> +starting point as we can now add build rules and register the command.

We are writing in C; don't call a function method.

> +
> +NOTE: Your throwaway text, as well as much of the text you will be adding over
> +the course of this lab, is user-facing. That means it needs to be localizable.
> +Take a look at `po/README` under "Marking strings for translation". Throughout
> +the lab, we will mark strings for translation as necessary; you should also do
> +so when writing your user-facing commands in the future.

Good.  I think that it is beneficial to give a more concrete
example, rather than leaving at saying "type any throwaway printf",
perhaps like:

	----
	int cmd_psuh(int ac, const char *av, const char *prefix)
	{
		printf(_("Pony says Uh, hello!\n"));
		return 0;
	}
	----

at this point.  That illustrates _() and also the fact that
successful command execution is concluded by returning 0 from the
service function.

> +Let's try to build it.  Open Makefile, find where `builtin/push.o` is added
> +to BUILTIN_OBJS, and add `builtin/psuh.o` in the same way. Once you've done so,

In the same way "next to it"?  Do we want to say taht we are trying
to keep these lines sorted?

> +move to the root directory and build simply with `make -j$(nproc)`. Optionally, add
> +the DEVELOPER=1 variable to turn on some additional warnings:

We tend to avoid saying `root` and instead say the top-level
directory, to avoid clueless literally doing "cd / && make" ;-).

As this is a developer-facing document, not making DEVELOPER=1
optional is preferrable.  Only when you are on a platform where
DEVELOPER=1 does not work well for you, optionally it is OK to drop
it.

Is it needed to say -j$(nproc) here, by the way?  That's a
preference highly personal.  I wouldn't write

	$ time nice -20 make -j

in a toturial I'd be writing, even if that is what I might often
use, and I expect those developers who are hacking Git to know how
to run $(MAKE) in a way appropriate for their boxes.

> +----
> +echo DEVELOPER=1 > config.mak

Follow the Documentation/CodingGuildelines when writing for our
developers.  Lose SP between the redirection operator and its
target filename.

> +make -j$(nproc)
> +----

> +
> +Great, now your new command builds happily on its own. But nobody invokes it.
> +Let's change that.

This is a tangent, but if we want to show off check-docs at this
point or perhaps a bit later, where it would notice that psuh is
implemented but not documented.

> +The list of commands lives in `git.c`. We can register a new command by adding
> +a cmd_struct to the commands[] array. struct cmd_struct takes a string with the
> +command name, a function pointer to the command implementation, and a setup
> +option flag. For now, let's keep cheating off of push. Find the line where
> +cmd_push is registered, copy it, and modify it for cmd_psuh. 

Right now, the elements in commands[] can be in any order, if I am
not mistaken in reading get_builtin().  It might want to be updated,
though, so recommanding to meek the list sorted may not be a bad
idea.

> +The options are documented in `builtin.h` under "Adding a new built-in." Since
> +we hope to print some data about the user's current workspace context later,
> +we need a Git directory, so choose `RUN_SETUP` as your only option.
> +
> +Go ahead and build again. You should see a clean build, so let's kick the tires
> +and see if it works. There's a binary you can use to test with in
> +`./bin-wrappers`.
> +
> +----
> +./bin-wrappers/git psuh
> +----
> +
> +Check it out! You've got a command! Nice work! Let's commit this.
> +
> +----
> +git add Makefile builtin.h builtin/psuh.c git.c
> +git commit -s
> +----
> +
> +Consider something like the following as your commit message. Start the commit
> +with a 50-column or less subject line, including the name of the component
> +you're working on. Remember to be explicit and provide the "Why" of your commit,
> +especially if it couldn't easily be understood from your diff. When editing
> +your commit message, don't remove the Signed-off-by line which was added by `-s`
> +above.

... then leave it in your example, perhaps?

> +
> +----
> +psuh: add a new built-in by popular demand
> +
> +Internal metrics indicate this is a command many users expect to be
> +present. So here's an implementation to help drive customer
> +satisfaction and engagement: a pony which doubtfully greets the user,
> +or, a Pony Saying "Um, Hello" (PSUH).
> +
> +This commit message is intentionally formatted to 72 columns per line,
> +starts with a single line as "commit message subject" that uses the
> +imperative present tense, and is designed to add information about the

There is no imperative past tense ;-) 

Use "that is written in the imperative mood" instead if you want to
be grammatical, or alternatively "that is written as if giving an
order to the codebase to 'be like so'" (it actually is giving an
order to the patch-monkey at the other end of your e-mail submission
to do so ;-).

> +commit that is not readily deduced from reading the associated diff,
> +such as answering the question "why?".

Nicely written.

Keep a sample sign-off by "A U Thor <author@example.com>" here.

> +----
> +
> +Go ahead and inspect your new commit with `git show`. "psuh:" indicates you
> +have modified mainly the `psuh` command. The subject line gives readers an idea
> +of what you've changed. The signed-off line (-s) indicates that you agree to
> +the Developer's Certificate of Origin 1.1 (see the SubmittingPatches [[dco]]
> +header). If you wish to add some context to your change, go ahead with
> +`git commit --amend`.
> +
> +For the remainder of the tutorial, the subject line only will be listed for the
> +sake of brevity. However, fully-fleshed example commit messages are available
> +on the reference implementation linked at the top of this document.

OK.

> +=== Implementation
> + ...
> +=== Adding documentation
> + ...

After skimming the remainder of your draft, i am not sure if this
order of presentation is the best one.

My personal preference is to make a small progress in the
implementation and then immediately after that add a test, whose
first iteration might even look like:

	#!/bin/sh
	test_description="test git psuh"
	. ./test-lib.sh

	test_expect_success setup '
		: nothing special yet
	'

	test_expect_success 'git psuh succeeds without an argument' '
		git psuh
	'

	test_done

But that may make the very initial step a bit too broad for a new
develoepr to grok.  I dunno.


  reply	other threads:[~2019-04-12  3:20 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11 18:32 [PATCH 0/1] documentation: add lab for first contribution Emily Shaffer via GitGitGadget
2019-04-11 18:32 ` [PATCH 1/1] " Emily Shaffer via GitGitGadget
2019-04-12  3:20   ` Junio C Hamano [this message]
2019-04-12 22:03     ` Emily Shaffer
2019-04-13  5:39       ` Junio C Hamano
2019-04-15 17:26         ` Emily Shaffer
2019-04-11 21:03 ` [PATCH 0/1] " Josh Steadmon
2019-04-12  2:35 ` Junio C Hamano
2019-04-12 22:58   ` Emily Shaffer
2019-04-16 20:26 ` [PATCH v2 " Emily Shaffer via GitGitGadget
2019-04-16 20:26   ` [PATCH v2 1/1] " Emily Shaffer via GitGitGadget
2019-04-17  5:32     ` Junio C Hamano
2019-04-17  8:07       ` Eric Sunshine
2019-04-18  0:05         ` Junio C Hamano
2019-04-17 23:16       ` Emily Shaffer
2019-04-16 21:13   ` [PATCH v2 0/1] " Emily Shaffer
2019-04-19 16:57   ` [PATCH v3] " Emily Shaffer
2019-04-21 10:52     ` Junio C Hamano
2019-04-22 22:27       ` Emily Shaffer
2019-04-23 19:34     ` [PATCH v4] documentation: add tutorial " Emily Shaffer
2019-04-30 18:59       ` Josh Steadmon
2019-05-02  0:57         ` Emily Shaffer
2019-05-03  2:11       ` Phil Hord
2019-05-07 19:05         ` Emily Shaffer
2019-05-06 22:28       ` Jonathan Tan
2019-05-07 19:59         ` Emily Shaffer
2019-05-07 20:32           ` Jonathan Tan
2019-05-08  2:45         ` Junio C Hamano
2019-05-07 21:30       ` [PATCH v5 0/2] documentation: add lab " Emily Shaffer
2019-05-07 21:30         ` [PATCH v5 1/2] documentation: add tutorial " Emily Shaffer
2019-05-07 23:25           ` Emily Shaffer
2019-05-08  3:46           ` Junio C Hamano
2019-05-08 18:58             ` Emily Shaffer
2019-05-08 19:53               ` Jonathan Tan
2019-05-07 21:30         ` [PATCH v5 2/2] documentation: add anchors to MyFirstContribution Emily Shaffer
2019-05-08  3:30         ` [PATCH v5 0/2] documentation: add lab for first contribution Junio C Hamano
2019-05-17 19:03         ` [PATCH v6 0/2] documentation: add tutorial " Emily Shaffer
2019-05-17 19:07           ` [PATCH v6 1/2] " Emily Shaffer
2019-05-26  7:48             ` Christian Couder
2019-05-29 20:09               ` Emily Shaffer
2019-10-18 16:40             ` SZEDER Gábor
2019-10-18 22:54               ` Emily Shaffer
2019-05-17 19:07           ` [PATCH v6 2/2] documentation: add anchors to MyFirstContribution Emily Shaffer
2019-05-29 20:18           ` [PATCH] doc: add some nit fixes " Emily Shaffer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqef67zz7u.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=emilyshaffer@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).