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_SPAM,RCVD_IN_SORBS_WEB,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 27A512047F for ; Tue, 25 Jul 2017 10:19:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751679AbdGYKTS (ORCPT ); Tue, 25 Jul 2017 06:19:18 -0400 Received: from mout.gmx.net ([212.227.15.18]:51839 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751677AbdGYKTR (ORCPT ); Tue, 25 Jul 2017 06:19:17 -0400 Received: from virtualbox ([37.201.192.198]) by mail.gmx.com (mrgmx002 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MHHZT-1dLwJ22SzD-00E9sM; Tue, 25 Jul 2017 12:19:11 +0200 Date: Tue, 25 Jul 2017 12:19:10 +0200 (CEST) From: Johannes Schindelin X-X-Sender: virtualbox@virtualbox To: Junio C Hamano cc: Jonathan Tan , git@vger.kernel.org Subject: Re: [PATCH] sha1_file: use access(), not lstat(), if possible In-Reply-To: Message-ID: References: <20170719171251.11906-1-jonathantanmy@google.com> 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:N2FDkYDWBt0KkWLAKkl7KgasvifYdF0qS/BuzuGaj8wHtbHE6RI yP+TerYy0nSmNEcERR6X6r9VZ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.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Hi, On Sat, 22 Jul 2017, Junio C Hamano wrote: > Johannes Schindelin writes: > > > But this whole thread taps into a gripe I have with parts of Git's code > > base: part of the code is not clear at all in its intent by virtue of > > calling whatever POSIX function may seem to give the answer for the > > intended question, instead of implementing a function whose name says > > precisely what question is asked. > > > > In this instance, we do not call a helper get_file_size(). Oh no. That > > would make it too obvious. We call lstat() instead. > > I agree with you for this case and a case like this in general. > > In codepaths at a lot lower level (they tend to be the ancient and > quite fundamental ones) in our codebase, lstat() is often directly > used by the caller because they are interested not only in a single > aspect of a path but many fields in struct stat are of interest. > > When the code is interested in existence or size or whatever single > aspect of a path and nothing else, however, the code would become > easier to read if a helper function with a more specific name is > used. And it may even help individual platforms that do not want to > use the full lstat() emulation, by telling them that other fields in > struct stat are not needed. > > Of course, then the issue becomes what to do when we are interested > in not just one but a selected few attributes. Perhaps we create a > helper "get_A_B_and_C_attributes_for_path()", which may use lstat() > on POSIX and the most efficient way to get only A, B and C attributes > on non-POSIX platforms. The implementation would be OK, but the naming > becomes a bit hard; we need to give it a good name. > > Things gets even more interesting when the set of attributes we are > interested in grows by one and we need to rename the function to > "get_A_B_C_and_D_attributes_for_path()". When it is a lot easier to > fall back to the full lstat() emulation on non-POSIX platforms, the > temptation to just use it even though it would grab attributes that > are not needed in that function grows, which needs to be resisted by > those who are doing the actual implementation for a particular platform. It becomes a lot easier to fall back to lstat(), if a lot less readable, yes. Until, that is, one realises that the function name does not have to encode what information is sought. It can be a bit field in a parameter instead. There are even precendents in Git's own source code for that rather smart paradigm. Ciao, Dscho