git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Joel Teichroeb <joel@teichroeb.net>
To: Christian Couder <christian.couder@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Thomas Gummerer <t.gummerer@gmail.com>,
	Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH v2 3/6] stash: convert apply to builtin
Date: Tue, 27 Mar 2018 20:32:15 -0700	[thread overview]
Message-ID: <CA+CzEk8xDG39Fb5GU2gHDvsPo=xGXxwNCdBOg4D+eQ2wPVaTOg@mail.gmail.com> (raw)
In-Reply-To: <CAP8UFD0wc2i3W4FNZPcDs3ELJGJj=4NaP8mhd-zMAkdK=vXT1A@mail.gmail.com>

On Mon, Mar 26, 2018 at 12:05 AM, Christian Couder
<christian.couder@gmail.com> wrote:
> On Mon, Mar 26, 2018 at 3:14 AM, Joel Teichroeb <joel@teichroeb.net> wrote:
>> Signed-off-by: Joel Teichroeb <joel@teichroeb.net>
>
> The commit message in this patch and the following ones could be a bit
> more verbose. It could at least tell that the end goal is to convert
> git-stash.sh to a C builtin.
>
>> +static void destroy_stash_info(struct stash_info *info)
>> +{
>> +       strbuf_release(&info->revision);
>> +}
>
> Not sure if "destroy" is the right word in the function name. I would
> have used "free" instead.
>
>> +static int get_stash_info(struct stash_info *info, int argc, const char **argv)
>> +{
>> +       struct strbuf w_commit_rev = STRBUF_INIT;
>> +       struct strbuf b_commit_rev = STRBUF_INIT;
>> +       struct strbuf w_tree_rev = STRBUF_INIT;
>> +       struct strbuf b_tree_rev = STRBUF_INIT;
>> +       struct strbuf i_tree_rev = STRBUF_INIT;
>> +       struct strbuf u_tree_rev = STRBUF_INIT;
>> +       struct strbuf symbolic = STRBUF_INIT;
>> +       struct strbuf out = STRBUF_INIT;
>> +       int ret;
>> +       const char *revision;
>> +       const char *commit = NULL;
>> +       char *end_of_rev;
>> +       info->is_stash_ref = 0;
>> +
>> +       if (argc > 1) {
>> +               int i;
>> +               fprintf(stderr, _("Too many revisions specified:"));
>> +               for (i = 0; i < argc; ++i) {
>> +                       fprintf(stderr, " '%s'", argv[i]);
>> +               }
>
> The brackets are not needed.
>
>> +               fprintf(stderr, "\n");
>> +
>> +               return -1;
>> +       }
>> +
>> +       if (argc == 1)
>> +               commit = argv[0];
>> +
>> +       strbuf_init(&info->revision, 0);
>> +       if (commit == NULL) {
>> +               if (have_stash()) {
>> +                       destroy_stash_info(info);
>> +                       return error(_("No stash entries found."));
>> +               }
>> +
>> +               strbuf_addf(&info->revision, "%s@{0}", ref_stash);
>> +       } else if (strspn(commit, "0123456789") == strlen(commit)) {
>> +               strbuf_addf(&info->revision, "%s@{%s}", ref_stash, commit);
>> +       } else {
>> +               strbuf_addstr(&info->revision, commit);
>> +       }
>> +
>> +       revision = info->revision.buf;
>> +
>> +       strbuf_addf(&w_commit_rev, "%s", revision);
>
> Maybe use strbuf_addstr()?
>
>> +
>> +
>
> Spurious new line.
>
> [...]
>
>> +static int diff_cached_index(struct strbuf *out, struct object_id *c_tree)
>> +{
>> +       struct child_process cp = CHILD_PROCESS_INIT;
>> +    const char *c_tree_hex = oid_to_hex(c_tree);
>
> Indent looks weird.
>
>> +
>> +       cp.git_cmd = 1;
>> +       argv_array_pushl(&cp.args, "diff-index", "--cached", "--name-only", "--diff-filter=A", NULL);
>> +       argv_array_push(&cp.args, c_tree_hex);
>> +       return pipe_command(&cp, NULL, 0, out, 0, NULL, 0);
>> +}
>> +
>> +static int update_index(struct strbuf *out) {
>
> The opening bracket should be on its own line.
>
>> +       struct child_process cp = CHILD_PROCESS_INIT;
>
> Maybe add a new line here to be more consistent with other such functions.
>
>> +       cp.git_cmd = 1;
>> +       argv_array_pushl(&cp.args, "update-index", "--add", "--stdin", NULL);
>> +       return pipe_command(&cp, out->buf, out->len, NULL, 0, NULL, 0);
>> +}
>
> [...]
>
>> +       if (info->has_u) {
>> +               struct child_process cp = CHILD_PROCESS_INIT;
>> +               struct child_process cp2 = CHILD_PROCESS_INIT;
>> +               int res;
>> +
>> +               cp.git_cmd = 1;
>> +               argv_array_push(&cp.args, "read-tree");
>> +               argv_array_push(&cp.args, oid_to_hex(&info->u_tree));
>> +               argv_array_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", stash_index_path);
>> +
>> +               cp2.git_cmd = 1;
>> +               argv_array_pushl(&cp2.args, "checkout-index", "--all", NULL);
>> +               argv_array_pushf(&cp2.env_array, "GIT_INDEX_FILE=%s", stash_index_path);
>
> Maybe use small functions for the above read-tree and checkout-index.
>
>> +               res = run_command(&cp) || run_command(&cp2);
>> +               remove_path(stash_index_path);
>> +               if (res)
>> +                       return error(_("Could not restore untracked files from stash"));
>> +       }
>
> Thanks.

Thanks for your detailed comments! I've fixed them all in my next patch set.

  reply	other threads:[~2018-03-28  3:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-26  1:14 [PATCH v2 0/6] Convert some stash functionality to a builtin Joel Teichroeb
2018-03-26  1:14 ` [PATCH v2 1/6] stash: Add tests for passing in too many refs Joel Teichroeb
2018-03-26 19:21   ` Johannes Schindelin
2018-03-26  1:14 ` [PATCH v2 2/6] stash: Add test for branch with no arguments Joel Teichroeb
2018-03-26  1:14 ` [PATCH v2 3/6] stash: convert apply to builtin Joel Teichroeb
2018-03-26  7:05   ` Christian Couder
2018-03-28  3:32     ` Joel Teichroeb [this message]
2018-03-26  1:14 ` [PATCH v2 4/6] stash: convert drop and clear " Joel Teichroeb
2018-03-26  1:14 ` [PATCH v2 5/6] stash: convert branch " Joel Teichroeb
2018-03-26  1:14 ` [PATCH v2 6/6] stash: convert pop " Joel Teichroeb

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='CA+CzEk8xDG39Fb5GU2gHDvsPo=xGXxwNCdBOg4D+eQ2wPVaTOg@mail.gmail.com' \
    --to=joel@teichroeb.net \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    --cc=t.gummerer@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).