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: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-0.7 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,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id 3E3A41F4D7 for ; Tue, 21 Jun 2022 16:01:21 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=pobox.com header.i=@pobox.com header.b="tisYqah/"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351952AbiFUP6N (ORCPT ); Tue, 21 Jun 2022 11:58:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352731AbiFUP5j (ORCPT ); Tue, 21 Jun 2022 11:57:39 -0400 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0FE22E9EE for ; Tue, 21 Jun 2022 08:56:37 -0700 (PDT) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 03AA11333E5; Tue, 21 Jun 2022 11:56:37 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=aqrqoatEaGCaRk5CVQo8SmIbJWXTaAlGc2X+iK QY24I=; b=tisYqah/o1S1iTGXzjCsl3KFYlB0stnTPYrxnvYT9a6XPptMswATgW OCaGwVts1OmVOvY9Kn6dG6F6MRhM8+rGxvrlxq06TrN2hdV1NELcNJ4dPLywvgwS zkN7L/2O1FMbcAD4UZxKpF916H0C8P9meOJ6FJXgjpGoEo6lKmYb4= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id EEDBF1333E3; Tue, 21 Jun 2022 11:56:36 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.82.80.254]) (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 28E081333E2; Tue, 21 Jun 2022 11:56:36 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: Jeff King Cc: git@vger.kernel.org, Derrick Stolee Subject: Re: [PATCH 2/2] branch: drop unused worktrees variable References: Date: Tue, 21 Jun 2022 08:56:35 -0700 In-Reply-To: (Jeff King's message of "Sat, 18 Jun 2022 23:55:16 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: BAACCD34-F17A-11EC-8E6D-CB998F0A682E-77302942!pb-smtp2.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Jeff King writes: > After b489b9d9aa (branch: use branch_checked_out() when deleting refs, > 2022-06-14), we no longer look at our local "worktrees" variable, since > branch_checked_out() handles it under the hood. The compiler didn't > notice the unused variable because we call functions to initialize and > free it (so it's not totally unused, it just doesn't do anything > useful). > > Signed-off-by: Jeff King > --- > It would be neat if there was some way to mark a function as "this is > just allocating a structure, with no useful side effects" and another as > "this is just freeing", which would let the compiler notice that we > don't do anything useful with the structure in between the two. I have a > feeling adding such annotations might be more work than occasionally > finding and cleaning up such useless variables, though. :) Also it may be tricky to write correctly ;-) I recently got rid of a Coccinelle rule I wrote quite a while ago that was suggesting a completely bogus rewrite, and found it quite satisfying. After that experience, I got allergic to the idea of having to make sure a mechanical rewrite suggested by the tool if it gets too large X-<. For this particular pattern, presumably we won't have too many of them, though. Thanks. > builtin/branch.c | 4 ---- > 1 file changed, 4 deletions(-) > > diff --git a/builtin/branch.c b/builtin/branch.c > index f875952e7b..55cd9a6e99 100644 > --- a/builtin/branch.c > +++ b/builtin/branch.c > @@ -204,7 +204,6 @@ static void delete_branch_config(const char *branchname) > static int delete_branches(int argc, const char **argv, int force, int kinds, > int quiet) > { > - struct worktree **worktrees; > struct commit *head_rev = NULL; > struct object_id oid; > char *name = NULL; > @@ -242,8 +241,6 @@ static int delete_branches(int argc, const char **argv, int force, int kinds, > die(_("Couldn't look up commit object for HEAD")); > } > > - worktrees = get_worktrees(); > - > for (i = 0; i < argc; i++, strbuf_reset(&bname)) { > char *target = NULL; > int flags = 0; > @@ -314,7 +311,6 @@ static int delete_branches(int argc, const char **argv, int force, int kinds, > > free(name); > strbuf_release(&bname); > - free_worktrees(worktrees); > > return ret; > }