From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-1.7 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_WEB,T_RP_MATCHES_RCVD shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 1A25020282 for ; Tue, 13 Jun 2017 11:22:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753120AbdFMLV5 (ORCPT ); Tue, 13 Jun 2017 07:21:57 -0400 Received: from mout.gmx.net ([212.227.15.18]:64785 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752211AbdFMLV4 (ORCPT ); Tue, 13 Jun 2017 07:21:56 -0400 Received: from virtualbox ([37.201.192.198]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MI4yc-1dGsnk0AWc-003vmt; Tue, 13 Jun 2017 13:21:30 +0200 Date: Tue, 13 Jun 2017 13:21:28 +0200 (CEST) From: Johannes Schindelin X-X-Sender: virtualbox@virtualbox To: Jeff King cc: git@vger.kernel.org, Junio C Hamano Subject: Re: [PATCH v2 7/8] alias_lookup(): optionally return top-level directory In-Reply-To: <20170610101813.n26wmxcueicecptz@sigill.intra.peff.net> Message-ID: References: <20170610101813.n26wmxcueicecptz@sigill.intra.peff.net> User-Agent: Alpine 2.21.1 (DEB 209 2017-03-23) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Provags-ID: V03:K0:/ZPYlLiJMofWuC6UJG2K92Pciz6vStmKi4+aMTXQP3dpDEtoOH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List-ID: X-Mailing-List: git@vger.kernel.org Hi Peff, On Sat, 10 Jun 2017, Jeff King wrote: > On Thu, Jun 08, 2017 at 09:53:50PM +0200, Johannes Schindelin wrote: > > > -char *alias_lookup(const char *alias) > > [...] > > { > > - char *v = NULL; > > - struct strbuf key = STRBUF_INIT; > > - strbuf_addf(&key, "alias.%s", alias); > > - if (git_config_key_is_valid(key.buf)) > > - git_config_get_string(key.buf, &v); > > - strbuf_release(&key); > > - return v; > > + struct strbuf key; > > + char *v; > > +}; > > [...] > > +char *alias_lookup(const char *alias, struct strbuf *cdup_dir) > > +{ > > + struct config_alias_data data = { STRBUF_INIT, NULL }; > > + > > + strbuf_addf(&data.key, "alias.%s", alias); > > + if (git_config_key_is_valid(data.key.buf)) > > + read_early_config(config_alias_cb, &data, cdup_dir); > > + strbuf_release(&data.key); > > + > > + return data.v; > > } > > Two optional cleanups here: > > 1. We don't need to call config_key_is_valid when using a callback. We > only needed that to prevent the configset machinery from issuing a > warning. It does save us reading the config entirely when the > program name is syntactically invalid as an alias, but that's a > pretty rare case. It may be a pretty rare case, or it may not be. I do not want to think hard about this, so I just wanted to keep that test. But since you suggested it, I will simply blame all the fallout (if any) on you. ;-) > 2. Now that we're not using the configset machinery, we don't need to > have the alias name as a full string. Instead of using the strbuf, > we could just pass the "alias" string itself and do: > > if (skip_prefix(var, "alias.", &key) && !strcmp(key, data->key)) > > in the callback. As you probably guessed, I had tried that first and then figured that if I needed to keep the config_key_is_valid() test anyway, I could just as well keep the strbuf around for later use. Will change the code, Dscho