From: Junio C Hamano <gitster@pobox.com>
To: dturner@twopensource.com
Cc: git@vger.kernel.org, David Turner <dturner@twitter.com>
Subject: Re: [PATCH 2/3] sha1_name: get_sha1_with_context learns to follow symlinks
Date: Fri, 08 May 2015 14:31:39 -0700 [thread overview]
Message-ID: <xmqqoaluiwn8.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1431108819-6831-2-git-send-email-dturner@twopensource.com> (dturner@twopensource.com's message of "Fri, 8 May 2015 14:13:38 -0400")
dturner@twopensource.com writes:
> diff --git a/sha1_name.c b/sha1_name.c
> index 6d10f05..23863f7 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -1434,6 +1434,12 @@ static int get_sha1_with_context_1(const char *name,
> new_filename = resolve_relative_path(filename);
> if (new_filename)
> filename = new_filename;
> + if (flags & GET_SHA1_FOLLOW_SYMLINKS) {
> + ret = get_tree_enty_follow_symlinks(tree_sha1,
> + filename, sha1, oc->path, &oc->mode);
> + free(new_filename);
> + return ret;
> + }
> ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode);
> if (ret && only_to_die) {
> diagnose_invalid_sha1_path(prefix, filename,
In general, I'd prefer to avoid this kind of "I only need this part
of the existing codeflow and I'll ignore rest by returning early".
You cannot anticipate any future needs of callers (e.g. only-to-die
flag might want to be passed when doing follow-symlinks in the
future) and clean-ups that may be added to the later part of the
function that you are skipping with this early return.
In other words,
if (new_filename)
filename = new_filename;
- ret = get_tree_entry(...);
+ if (flags & GET_SHA1_FOLLOW_SYMLINKS) {
+ ret = ... whatever new thing you want to do ...
+ } else {
+ ret = get_tree_entry(... just reindented ... );
+ }
if (ret && ...)
is what we would prefer to see here.
> @@ -1469,5 +1475,7 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
>
> int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc)
> {
> + if (flags & GET_SHA1_FOLLOW_SYMLINKS && flags & GET_SHA1_ONLY_TO_DIE)
> + die(_("internal error: bad flags for get_sha1_with_context"));
> return get_sha1_with_context_1(str, flags, NULL, sha1, orc);
> }
next prev parent reply other threads:[~2015-05-08 21:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-08 18:13 [PATCH 1/3] tree-walk: learn get_tree_enty_follow_symlinks dturner
2015-05-08 18:13 ` [PATCH 2/3] sha1_name: get_sha1_with_context learns to follow symlinks dturner
2015-05-08 19:45 ` Eric Sunshine
2015-05-08 20:17 ` Junio C Hamano
2015-05-08 20:25 ` Junio C Hamano
2015-05-08 20:39 ` Jeff King
2015-05-08 21:22 ` Junio C Hamano
2015-05-08 20:27 ` David Turner
2015-05-08 20:38 ` Philip Oakley
2015-05-08 21:31 ` Junio C Hamano [this message]
2015-05-08 18:13 ` [PATCH 3/3] cat-file: add --follow-symlinks to --batch dturner
2015-05-08 19:51 ` Eric Sunshine
2015-05-08 19:26 ` [PATCH 1/3] tree-walk: learn get_tree_enty_follow_symlinks Junio C Hamano
2015-05-08 20:02 ` David Turner
2015-05-08 19:43 ` Eric Sunshine
-- strict thread matches above, loose matches on Subject: below --
2015-05-13 18:21 [PATCH v8 0/3] git cat-file --follow-symlinks David Turner
2015-05-13 18:21 ` [PATCH 2/3] sha1_name: get_sha1_with_context learns to follow symlinks David Turner
2015-05-13 18:23 [PATCH v9 0/3] David Turner
2015-05-13 18:23 ` [PATCH 2/3] sha1_name: get_sha1_with_context learns to follow symlinks David Turner
2015-05-14 20:17 [PATCH v10 0/3] David Turner
2015-05-14 20:17 ` [PATCH 2/3] sha1_name: get_sha1_with_context learns to follow symlinks David Turner
2015-05-14 20:38 [PATCH v11 0/3] cat-file --follow-symlinks David Turner
2015-05-14 20:38 ` [PATCH 2/3] sha1_name: get_sha1_with_context learns to follow symlinks David Turner
2015-05-14 21:58 [PATCH v12 0/3] git cat-file --follow-symlinks David Turner
2015-05-14 21:58 ` [PATCH 2/3] sha1_name: get_sha1_with_context learns to follow symlinks David Turner
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqoaluiwn8.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=dturner@twitter.com \
--cc=dturner@twopensource.com \
--cc=git@vger.kernel.org \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.