From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25586 invoked from network); 29 Mar 2021 10:39:55 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 29 Mar 2021 10:39:55 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1617014395; b=Y8x0UkabKCAkBk0Giw0vR+P2PIdl092Y9SSBqzIZiLMdJ2jpW/abdvOHuD4pVc+svfyrOrUhNQ 7DgZGtt99kXgiflMhoIeJOcJK9AOKjrC9KiML2b2F3y01jG1IGVUjoMEi4SH6jTF6tOemPNT1/ +JFKBtaNoa5UIycJfihkWaqZrENfdxgvT3IRHuoj/mjrtsuP0jDgoo9MSia+ZenMVx6Z/9JyzK SYfJXFuJVQZTp4xR79ddEm/LFh+jrWgxfD+i9jyOSl0LZJBkBEMarpeC+262rWWsWtQj4gxjf/ TyF/0QpgHMRZgGWOp6WZIZBtXpZX+lvF8ubmC2rx2yaSEA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-pl1-f182.google.com) smtp.remote-ip=209.85.214.182; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1617014395; bh=1TajQ1rq4TDFzM5JEaTLWQ3g6UVlukIHz/Xx/XL8L9A=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature; b=GaMiZFAnpa07AwN2Gzxb8mRdrG9v48C376gVapkfo8HRIPwhFLdfFxjCuNdeHy1jo470KBdQwO 43G5IQR9XNWDWWo5Syyaa+zkBBdPkf/yYb+7WMG/jRgE8fhjh9egIagbE0RGSIorlusofoXEoI OXGSpXhU0faAy1GQGZ7E24lG4Mc2OGhCB1tRzIHAjk9jORTgazR85xSPXzOZqqDc02hJOibyX1 aUgNX827TalU7dfyIR19TsU7cFO5vt8Q7lv/WFiSj1GiYdK4virybw1ne7K2EmdJtzaaUfYMxL C9aWmJ6GjDfJfcDm2mMfaFfunwyb8+kVIypHCXtwrdibJQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=Y6tzSXWBXqhcgf4nlstoSR2UmjAcGaAXCUeEgodURYQ=; b=EwzKGNqXJSl7DzQ3HHU4mLD1s7 /ZiuTH7GxdYsOGpjmpu6TNJCMiQ/aOhdeXVMamXOVQeN0qd+mSeKfBd+UKZTYslFigYqMMET9QFDp TIQWazlexwUt2dOaSYGIRk63FUFaxcguGuip2E7f3fM+EBqMdYsmFSLmJHyVP/MWv17BpVLy4GYcK RuNkrXsANYkqVFAxOikFauAj3l7QwfGM5qv1dtSVbEFHvGxlp4QOa53FRlWikfFVX5egG7gekTXQM 3L2tWutLSmbQVH0tCWB07KA/GimBzSvEARId0d4i/xNRXg9MfNtnO/mL/mzp3egO0JF1EhcI4ePzH ybVmEDzA==; Received: from authenticated user by zero.zsh.org with local id 1lQpJG-000PRs-V4; Mon, 29 Mar 2021 10:39:50 +0000 Authentication-Results: zsh.org; iprev=pass (mail-pl1-f182.google.com) smtp.remote-ip=209.85.214.182; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-pl1-f182.google.com ([209.85.214.182]:46651) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lQpIz-000PH9-Ih; Mon, 29 Mar 2021 10:39:34 +0000 Received: by mail-pl1-f182.google.com with SMTP id t20so4190113plr.13 for ; Mon, 29 Mar 2021 03:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=Y6tzSXWBXqhcgf4nlstoSR2UmjAcGaAXCUeEgodURYQ=; b=TAS/hxAb5LvBGph3woOsxfJ+/6Wvc1LpuFVMgmrrFvqT/jD4gwaYcsnOYVorG4ULsl iyomhoBvjUj/VBxzQtAs1J2DpNFwNcdh8bxdFu6p4s3gif/ZloRKNVc76eWRipIJTkuE AIVxyKpMACeasFgal+1M6SLlCEZUqjNzr8+g7mj6EvPDEG3AG/xfncShBctdNHY7XlV6 d93C/p9d9fmbIMf5RELwjbs+JUnVuKUJyMKUGeZgz8eKWN185egpwZT/LbHk/bHOLKQu Q8WchJ5AijoUppXCDVDMH2dGjzOOGL8XSU4JBfMisKQzie++x4XBJJoIqA54m1qvTo/a 6/Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=Y6tzSXWBXqhcgf4nlstoSR2UmjAcGaAXCUeEgodURYQ=; b=di8rQrn6EQVuRNreK3Lipq9D761x5dgy74V4pNZ5uSuNYDtQAYAmmDT64HsOZDGtud STaGHM9fyZV5xgbaG9B472g94Q0aJ/gLt4uBKpxcML0IrMtTSIJLFb2IyXco1/inNU58 ygwr7HDydJ+tN/Qz6/ooAM83Vac5EcnEaOK+eqm4TKXucH2mShqPsdisxK5OKQPTHVUj A5SEtyTUUVOORUOziPuuZda3TznUqUYIlV3EQl9zxkMxpEoVKFfvHfxZKHTvczdwKb4n 1RNB6JQCwN4Buqn91f8uXIybzhun1hCdQdCLdW37KqXs4G5cizjzGm/b6EV1Sb2ESqqr D1bg== X-Gm-Message-State: AOAM532hITvqVVePyTChQxD/Kw0RR5zrzIk+eOZDjJAtXpQw06ZMQClY zbrhN/VDwehFHnE4RlDj5O62Lm3zJm8= X-Google-Smtp-Source: ABdhPJwuGfhPUQVPe34IhpCae+jWeHm/3omkzZIGJsDFmE5dmCKMlsKIHqJdC+FLeWXXCFAIdWVeTg== X-Received: by 2002:a17:90b:b0d:: with SMTP id bf13mr25376869pjb.7.1617014372142; Mon, 29 Mar 2021 03:39:32 -0700 (PDT) Received: from home-guest ([61.6.235.67]) by smtp.gmail.com with ESMTPSA id q10sm15403955pgs.44.2021.03.29.03.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 03:39:31 -0700 (PDT) Date: Mon, 29 Mar 2021 18:39:27 +0800 From: Tim Lee To: Daniel Shahaf Cc: zsh-workers@zsh.org Subject: Re: [PATCH] Improve vcs_info example for ahead/behind git commits Message-ID: <20210329103927.qzky3fyevptfflvj@home-guest> References: <20210328213628.7rwz62bq5p2isd6b@home-guest> <20210329070611.GM18178@tarpaulin.shahaf.local2> <20210329093056.fegqam75id4yfkiq@home-guest> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Seq: 48313 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: > > > > diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples > > > > index 94b8a7b5e..36d4d3bf8 100644 > > > > --- a/Misc/vcs_info-examples > > > > +++ b/Misc/vcs_info-examples > > > > @@ -179,14 +179,18 @@ function +vi-git-st() { > > > > local ahead behind > > > > local -a gitstatus > > > > > > > > - # for git prior to 1.7 > > > > + # for git prior to 1.7.0 > > > > # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l) > > > > - ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l) > > > > + # for git 1.7.0 and 1.7.1 > > > > + # ahead=$(git rev-list @{upstream}..HEAD 2>/dev/null | wc -l) > > > > + ahead=$(git rev-list --count @{upstream}..HEAD 2>/dev/null) > > > > (( $ahead )) && gitstatus+=( "+${ahead}" ) > > > > > > The version of this function in my zshrc starts like this: > > > . > > > git rev-parse @{upstream} >/dev/null 2>&1 || return 0 > > > local -a x=( $(git rev-list --left-right --count HEAD...@{upstream} ) ) > > > > The snippet below displays N/M. How would you make it display +N/-M > > instead? > > Change the last line to hook_com[misc]="+${x[1]} -${x[2]}". But hook_com[misc]="+${x[1]} -${x[2]}" would display a '+0' and/or '-0' when the local git branch is not ahead-of or behind the remote branch. The existing example does not display '+0' or '-0'. > > git rev-parse @{upstream} >/dev/null 2>&1 || return 0 > > local -a x=( $(git rev-list --left-right --count HEAD...@{upstream} ) ) > > hook_com[misc]="${(j:/:)x}" > > > > > The first line is to handle a detached HEAD, I think, and should > > > presumably be added? > > > > Why not do this instead: > > > > local -a x=( $(git rev-list --left-right --count HEAD...@{upstream} 2>/dev/null ) ) > > You mean, why not discard stderr? Out of general principles ("Errors > shouldn't be silenced"), plus the fact that I've never had that line > generate an error that needed to be silenced — not with the «git > rev-parse … || return» right above it. > > Or do you mean that line instead of the git-rev-parse(1) call too? Yes, I mean: instead of this: git rev-parse @{upstream} >/dev/null 2>&1 || return 0 local -a x=( $(git rev-list --left-right --count HEAD...@{upstream} ) ) Replace both of the lines above with this: local -a x=( $(git rev-list --left-right --count HEAD...@{upstream} 2>/dev/null ) ) > First, that would run the rest of the function even though $x might be > an empty array rather than a two-element one. Two, suppose there is an > error after resolving «@{upstream}» to a commit but before rev-list > finishes (for instance, an error while walking the commits history). > With an explicit git-rev-parse(1) call that error would be reported, but > if the rev-parse and the history walking are lumped into one step any > failure from which is treated the same way, history walking failures > would be masked — even though they're probably interesting. > > > --- > > Note: when replying to my email, please ensure that my email address is > > included in the 'To:' field, since I am not subscribed to the mailing > > list. > > Ack, but for future reference, the customary signature delimiter is "-- " > (ASCII 0x2D 0x2D 0x20). Many MUAs syntax-highlight that, for example. Thank you for all this information. I've learned so much today. :-)