From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 5A0681F5A2 for ; Thu, 6 Feb 2020 18:26:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727778AbgBFS0P (ORCPT ); Thu, 6 Feb 2020 13:26:15 -0500 Received: from pb-smtp2.pobox.com ([64.147.108.71]:52381 "EHLO pb-smtp2.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbgBFS0P (ORCPT ); Thu, 6 Feb 2020 13:26:15 -0500 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id B7EE443476; Thu, 6 Feb 2020 13:26:12 -0500 (EST) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=kFc3My7Euft0nMVH1RAaoVOd6sE=; b=x1ML/M IdRmVWTBYa4Tt8RP/BRINb+jak37Hm4dyv4ZG8SBBxJNdFi2laecUxKWE00jLCvw VCrRNDNz2rKKx8N/93ixtFvurV+/jC3PhHORprOj7xrWPIEHmVvE3hTETPr98wcz IWpXx3T556gTB96Z5nOKCFgiO2NkNUg0YC4VE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=W4xih0Cl9xPUFBKwOdrtGnGDT+U2KMMR rjVA5w7AA5dJOXCOBaROlNPlIKRXTjW9IJU/meZVPok1ZS5TboMnpcLMCqqe38CY TSC6c5QJrP28U6FODcvpptL6/Q3S4IgjdWg4yG7O+BDbiKITgTUw9lbQWn0cMEJi FlKyr5aZzb0= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 82F8143475; Thu, 6 Feb 2020 13:26:12 -0500 (EST) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.76.80.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 7010343474; Thu, 6 Feb 2020 13:26:11 -0500 (EST) (envelope-from junio@pobox.com) From: Junio C Hamano To: Ben Keene Cc: Ben Keene via GitGitGadget , git@vger.kernel.org Subject: Re: [PATCH v2 2/4] git-p4: create new method gitRunHook References: <9cf8790e-6d13-4653-cddc-f5328f22b0df@gmail.com> Date: Thu, 06 Feb 2020 10:26:09 -0800 In-Reply-To: <9cf8790e-6d13-4653-cddc-f5328f22b0df@gmail.com> (Ben Keene's message of "Thu, 6 Feb 2020 09:00:17 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 26A3003E-490E-11EA-BD2F-D1361DBA3BAF-77302942!pb-smtp2.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Ben Keene writes: > On 2/5/2020 4:42 PM, Junio C Hamano wrote: >> Ben Keene writes: >> >>>>> + hooks_path = os.path.join(os.environ.get("GIT_DIR", ".git"), "hooks") >>>> This assumes that the process when his function is called (by the >>>> way, even though the title of the patch uses the word "method", this >>>> is not a method but a function, no?), it is always at the top level >>>> of the working tree. Is that a good assumption? I don't know the >>>> code well, so "yes it is good because a very early thing we do is to >>>> go up to the top" is a good answer. >>> ... > As best as I understand the mechanics, and I haven't examined the > source code of git, this is just experimental,... As I already said that I do not know the code well, it is useless for you to also speculate. One of us must read the code before speaking further ;-) I just scanned "def main()", and it seems that it always goes to the top-level of the working tree by doing chdir(cdup), where cdup is learned from "git rev-parse --show-cdup", i.e. "tell me how to chdir up to the top-level of the working tree". I am assuming that nobody runs "git p4" in a bare repository, so under that assumption, I think it would be safe to say that we can assume we are always at the top. Also, GIT_DIR is exported from there, so it probably is a good idea to make sure that the run-hook helper just uses os.environ.get("GIT_DIR") and barfs if the environ is not set (i.e. there is something funny going on) without pretending that it is prepared to deal with such a case, which is what the "[, default]" parameter to .get method is doing. I.e. hooks_path = os.path.join(os.environ["GIT_DIR"], "hooks") > Does this prompt the need to search the hierarchy if we don't find > the directory? No, we just saw that it is done early in "def main()". It is done by "rev-parse --git-dir" and "rev-parse --show-cdup".