Re: [HACKERS] Request - repeat value of \pset title during \watch interations

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: [HACKERS] Request - repeat value of \pset title during \watch interations
Date: 2016-03-20 13:31:39
Message-ID: CAB7nPqTfeT2e_WA01n996tTFiuhEbVCEMJfC=B_md-g510dsWw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Sat, Mar 19, 2016 at 11:42 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Thu, Mar 10, 2016 at 1:40 AM, David G. Johnston
> <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>> Adding -hackers for consideration in the Commitfest.
>
> I don't much like how this patch uses the arbitrary constant 50 in no
> fewer than 5 locations.
>
> Also, it seems like we could arrange for head_title to be "" rather
> than NULL when myopt.title is NULL. Then instead of this:
>
> + if (head_title)
> + snprintf(title, strlen(myopt.title) + 50,
> + _("Watch every %lds\t%s\n%s"),
> + sleep, asctime(localtime(&timer)), head_title);
> + else
> + snprintf(title, 50, _("Watch every %lds\t%s"),
> + sleep, asctime(localtime(&timer)));
>
> ...we could just the first branch of that if all the time.

OK, why not.

> if (res == -1)
> + {
> + pg_free(title);
> + pg_free(head_title);
> return false;
> + }
>
> Instead of repeating the cleanup code, how about making this break;
> then, change the return statement at the bottom of the function to
> return (res != -1).

OK.

And the patch attached gives the following output:
With title:
=# \watch 1
Watch every 1s Sun Mar 20 22:28:38 2016
popo
a
---
1
(1 row)

And without title:
Watch every 1s Sun Mar 20 22:29:31 2016

a
---
1
(1 row)
--
Michael

Attachment Content-Type Size
psql_watch_title-v3.patch binary/octet-stream 1.9 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Yi, Yi 2016-03-20 14:04:47 Re: Confused by the behavior of pg_basebackup with replication slot
Previous Message George Neuner 2016-03-20 07:04:02 Re: Error: insufficient data in the message

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2016-03-20 14:32:03 Re: [PATCH] fix DROP OPERATOR to reset links to itself on commutator and negator
Previous Message Thomas Munro 2016-03-20 12:31:30 Re: Performance degradation in commit ac1d794