From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: Re: [SHEPHERD] [PATCH] service: Improve 'service-list'. Date: Mon, 25 Jan 2016 11:39:33 +0300 Message-ID: <87powqdpdm.fsf_-_@gmail.com> References: <1453649591-3478-1-git-send-email-alezost@gmail.com> <87oacak73e.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNcgW-00045F-Qc for guix-devel@gnu.org; Mon, 25 Jan 2016 03:39:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNcgR-0004ae-Qu for guix-devel@gnu.org; Mon, 25 Jan 2016 03:39:40 -0500 In-Reply-To: <87oacak73e.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sun, 24 Jan 2016 22:20:21 +0100") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s (2016-01-25 00:20 +0300) wrote: > Alex Kost skribis: [...] >> [PATCH 1/5] service: Rename 'services' variable to '%services'. >> [PATCH 2/5] service: Improve style of 'for-each-service'. >> >> [PATCH 3/5] service: 'service-list' returns unique services. >> >> Without this change, if the root service provides 2 names, 'herd status' >> would display: >> >> Started: (root root) >> Stopped: () >> >> [PATCH 4/5] service: Add docstring to 'lookup-services'. >> [PATCH 5/5] Rename 'dmd' service to 'root'. > > Excellent! I=E2=80=99ve pushed all 5 patches. Ah, I'm late :-) I suddenly realized that for the 3rd patch it would be better to use 'lookup-canonical-service' instead of 'delete-duplicates'. It is guaranteed that there will be no duplicates since services have a single canonical name, so for each name from %services hash-table there will be either zero or one service with this canonical name. (Hm, I probably didn't describe it well, but I hope it's clear enough) So would it be OK to push the attached patch? > While I was at it, I=E2=80=99ve added Mathieu and you as committers. Thank you! --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-service-Improve-service-list.patch >From f3d21e3ec8a100a966153d03264639ebe48e8872 Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Mon, 25 Jan 2016 11:18:00 +0300 Subject: [PATCH] service: Improve 'service-list'. * modules/shepherd/service.scm (service-list): Use 'lookup-canonical-service' on each name instead of removing duplicates from the final list. --- modules/shepherd/service.scm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index f84d1dd..94f2aae 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -871,12 +871,13 @@ Return #f if service is not found." (define (service-list) "Return the list of services currently defined." - (delete-duplicates - (hash-fold (lambda (key services result) - (append services result)) - '() - %services) - eq?)) + (hash-fold (lambda (name services result) + (let ((service (lookup-canonical-service name services))) + (if service + (cons service result) + result))) + '() + %services)) (define (find-service pred) "Return the first service that matches PRED, or #f if none was found." -- 2.6.3 --=-=-=--