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=-3.9 required=3.0 tests=AWL,BAYES_00, 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 52DC51F619 for ; Tue, 17 Mar 2020 17:18:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726767AbgCQRSz (ORCPT ); Tue, 17 Mar 2020 13:18:55 -0400 Received: from cloud.peff.net ([104.130.231.41]:41932 "HELO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726619AbgCQRSz (ORCPT ); Tue, 17 Mar 2020 13:18:55 -0400 Received: (qmail 3592 invoked by uid 109); 17 Mar 2020 17:18:54 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with SMTP; Tue, 17 Mar 2020 17:18:54 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 8034 invoked by uid 111); 17 Mar 2020 17:28:29 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Tue, 17 Mar 2020 13:28:29 -0400 Authentication-Results: peff.net; auth=none Date: Tue, 17 Mar 2020 13:18:53 -0400 From: Jeff King To: Robert Dailey Cc: Git Subject: Re: Conditional newline in pretty format Message-ID: <20200317171853.GA6598@coredump.intra.peff.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Tue, Mar 17, 2020 at 10:37:13AM -0500, Robert Dailey wrote: > > It works perfectly right now except for the case where `%b` is empty. > > In that case, I just want one newline after `%s` instead of 2. Is > > there a way to make my second `%n` conditional on `%b` having a value? > [...] > Another solution I tried is `%+b`, based on this documentation: That's what I would have suggested. And it does seem to work if you do: git log --format='* %s%n%+b' but not when you add in the indentation and wrapping: git log --format='* %s%n%w(100,2,2)%+b' Which is unfortunate, but I think makes sense: the wrapping sees the extra newline as part of the text to be wrapped, so it gets folded into the first line. I think what you really want is a conditional that can cover multiple placeholders, and put the wrapped body inside that. You can do that with the for-each-ref placeholders, which have a real "%(if)...%(end)" block. But I don't think the pretty-format placeholders have an equivalent. It would be nice to unify them one day, but progress has been slow on that front. I wonder in the meantime if it would be possible to introduce a block syntax to the pretty formats, like: git log --format='* %s%n%+{%w(100,2,2)%b}' or something. I don't know the conditional code well enough to say whether that would be a trivial patch or a horribly complicated one. :) -Peff