From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Harm Van der Vegt Newsgroups: gmane.emacs.bugs Subject: bug#72919: 29.1; chart-space-usage in chart.el does not work correctly on windows Date: Sun, 1 Sep 2024 21:06:58 +0200 Message-ID: References: <86seujaj0r.fsf@gnu.org> <86bk179q94.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000003b5ae206211388b8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18352"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 72919@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 01 23:48:06 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sksQW-0004b2-Ty for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 01 Sep 2024 23:48:05 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sksPd-0005yu-RR; Sun, 01 Sep 2024 17:47:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sksPa-0005xf-OT for bug-gnu-emacs@gnu.org; Sun, 01 Sep 2024 17:47:06 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sksPa-00008B-FV for bug-gnu-emacs@gnu.org; Sun, 01 Sep 2024 17:47:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:From:In-Reply-To:References:MIME-Version:To:Subject; bh=pW4JGIbaIH+w6ktdeNdKXvCl6PXXGCL/FH5Naa8OYXk=; b=I/ZWkQepnrICL0d7Tf5hyKPYQBXwJ39zcZkmaQ7aQoWIKVRgs0FCUO7+yjcBtsOMtyaMIpPbnlUmubOzqxJj7FCEmArs5wPPUjCW5X+xCVLAbi+AU+aw4ajBRdNqYdNrpRk6GCuzBgsZJ7dkEvRKM2MkHhAsk+/Da/MWlefpDMHf8OJ/ikGCJFdRVCr8BJbZgRYKqejD62JGVGi02UEbb2pI9/GcArMASsU1QVb/gGshSlIKJqfCAL1jgSUXmzcjAeVQM3Ov6EjH7/M/MvevktKYTPzgEIDm2WQIGKyWd3pr3y7XEr7CJ+Pq03LjrG+s6fHCPyBOq2uejbvj5F7juQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sksQY-0008IG-DP for bug-gnu-emacs@gnu.org; Sun, 01 Sep 2024 17:48:06 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Harm Van der Vegt Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Sep 2024 21:48:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72919 X-GNU-PR-Package: emacs Original-Received: via spool by 72919-submit@debbugs.gnu.org id=B72919.172522723631656 (code B ref 72919); Sun, 01 Sep 2024 21:48:06 +0000 Original-Received: (at 72919) by debbugs.gnu.org; 1 Sep 2024 21:47:16 +0000 Original-Received: from localhost ([127.0.0.1]:40866 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sksPj-0008ER-80 for submit@debbugs.gnu.org; Sun, 01 Sep 2024 17:47:15 -0400 Original-Received: from mail-ej1-f45.google.com ([209.85.218.45]:58668) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1skpwv-0002EN-9K for 72919@debbugs.gnu.org; Sun, 01 Sep 2024 15:09:22 -0400 Original-Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a86acbaddb4so408322866b.1 for <72919@debbugs.gnu.org>; Sun, 01 Sep 2024 12:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725217634; x=1725822434; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pW4JGIbaIH+w6ktdeNdKXvCl6PXXGCL/FH5Naa8OYXk=; b=TXn8PVfgRK4NdA67EPn0KmmEL6phE5WtGJcYHhyiAS4AwFwMfVth7BtM507FiP/7QM PvstV9Nh0LZqvQY1VKYIYoHsBoXkXmxxWTE4B3sXQndc4IqamavTDq0j7waf4UonXQFi CQ2chjRnZXt7Cos/cXmsvswA8wvy5lv6OshtUkF0nhf24XOePXD73EKycROhA9loqHJL m5hd7uPdTdistp/o+aat0KsI58HADBB7XC2WOe/PM4hWIdG/MSsBM/BAmL15QMSd9dx/ u+W9tmmjOMyNIc4e7dfrIj2a7LAfZhW7Rjs1pm1RXyrH3wPR4VHab7fF4c2k9ZKiBkSJ SKuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725217634; x=1725822434; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pW4JGIbaIH+w6ktdeNdKXvCl6PXXGCL/FH5Naa8OYXk=; b=RLDipKqq5bUmMTtBMu3ufrZPpQB+N4JzoLd+2O1Q4sXtlJVLjB1ZSTJm2zmo02PdoC wsFqok3jWhsqjR2/fL9PatMi3Ca63GvRmW6fdxF7nlRjsq/XroZDXEIoUvRPktZ6Gh4Z ynl27AsiQrwLcXSulR+RbSlhiRj+7cm1Bi4RgApzoEylBugGn7x2R86IRv63goDY3EYu ubR2OTEtopd0F1CRnmjk8XmXN+0TCP24rObDcM6pnwf5mFqVBIxmHObnV9CzGDKcFqRZ 4msszQwEJopohAdXHTuWfm5M7H0Isa7zwb49FCsvab5fxMzH1MmirXG3vQW/OLKcXHvN t26w== X-Gm-Message-State: AOJu0YwVV1vC81eA8dJRlHHVy54NK+VJagqR9unJ6I+ilZWM6N5rrTrx JT3eRNqvPEBrVEXZk6ojVZugCIIfOIHX55OruGkpXbFRNcz0UW34z+W/iczoAXUjBGq+d0lV7ph xqJVrcsAUE7RtMA6zJawcFzD0DKs= X-Google-Smtp-Source: AGHT+IFy9JKSqbQ7sGt7pc0olF8GhxMK419Uj1/n89XNM9Z68dU1xerD4sNBWVgFnYIGye3yPgwDJr11stxI5hY/jto= X-Received: by 2002:a17:907:97c3:b0:a7a:b1a8:6a2e with SMTP id a640c23a62f3a-a897f860feemr959917966b.28.1725217633948; Sun, 01 Sep 2024 12:07:13 -0700 (PDT) In-Reply-To: <86bk179q94.fsf@gnu.org> X-Mailman-Approved-At: Sun, 01 Sep 2024 17:47:03 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:291076 Archived-At: --0000000000003b5ae206211388b8 Content-Type: text/plain; charset="UTF-8" Clear, thanks for the response! Op zo 1 sep 2024 om 20:35 schreef Eli Zaretskii : > [Please use Reply All to reply, so that the bug tracker is CC'ed.] > > > From: Harm Van der Vegt > > Date: Sun, 1 Sep 2024 20:11:39 +0200 > > > > >Thanks. However, I think your changes are not entirely correct: they > > >fail to account for space usage of files inside subdirectories of the > > >directory which the user types at the prompt, whereas the > > >implementation with "du" does account for that. > > > > That is indeed a pretty major difference, my bad! > > > > >In addition, I think if someone has 'du' on Windows, it should be used. > > > > Is there a preference for using system binaries above elisp for cases > like these? > > I think 'du' has some tricks up its sleeve (like accounting correctly > for block size), which a Lisp implementation can only approximate. I > don't think minor differences matter here, since this command is just > an illustration of what chart.el can be used for, but I do want to use > 'du' if it's available. > > > >So I came up with the following changes instead. Could you please try > > >them, both with and without du.exe on PATH? If these changes give > > >good results, I will install them. > > > > Thanks. > > > > I've tried your changes with and without du. This uncovered something in > the > > original implementation, namely that the original implementation did not > count > > hidden files and directories. du * skips dotfiles for me. > > > > With du present chart-space-usage shows the lisp directory as the > largest in the > > emacs repository root. Without du it shows .git as the largest. > > This just means minor adjustments in the code I posted: we need to use > a different regexp in the call to directory-files-recursively, and > also ignore files that start with a dot in the command itself. I will > make those changes, thanks for pointing them out > > > I'm not sure which output is the wanted output. > > I think we want to be as close to 'du' as possible. > > > I've attempted to find a shell independent way to have du show dotfiles, > but it > > appears to be rather tricky. > > I don't think we want that. > > > I've made a new patch that makes the elisp implementation recursive, > uses the > > rounding function provided by you and shows dotfiles. > > I'd prefer to avoid recursion (in addition to what > directory-files-recursively already does), because that could overflow > the stack. > > I will post a version that ignores dotfiles. > > Here's the version you sent, repeated for the bug tracker: > > >From 6f53d65f9ae5e1c61a2ca2650b149c895ce9794c Mon Sep 17 00:00:00 2001 > >From: Harm van der Vegt > Date: Sun, 1 Sep 2024 20:03:34 +0200 > Subject: [PATCH] Make chart-space-usage OS and shell independent > > --- > lisp/emacs-lisp/chart.el | 41 +++++++++++++++++++++++++++++------------ > 1 file changed, 29 insertions(+), 12 deletions(-) > > diff --git a/lisp/emacs-lisp/chart.el b/lisp/emacs-lisp/chart.el > index c195ccb7165..b0302b55278 100644 > --- a/lisp/emacs-lisp/chart.el > +++ b/lisp/emacs-lisp/chart.el > @@ -641,27 +641,44 @@ SORT-PRED if desired." > (lambda (a b) (> (cdr a) (cdr b)))) > )) > > +;; This assumes 4KB blocks > +(defun chart--file-size (size) > + (* (/ (+ size 4095) 4096) 4096)) > + > +(defun chart--directory-size (dir) > + "Compute total size of files in directory DIR and its subdirectories. > +DIR is assumed to be a directory, verified by the caller." > + (let ((total-size 0)) > + (dolist (file (directory-files dir t > directory-files-no-dot-files-regexp)) > + (cond > + ((file-regular-p file) > + (setq total-size (+ total-size (chart--file-size (nth 7 > (file-attributes file)))))) > + ((file-directory-p file) > + (setq total-size (+ total-size (chart--directory-size file)))))) > + total-size)) > + > (defun chart-space-usage (d) > "Display a top usage chart for directory D." > (interactive "DDirectory: ") > (message "Collecting statistics...") > (let ((nmlst nil) > - (cntlst nil)) > - (dolist (file (directory-files d t)) > - (when (file-regular-p file) > - (let ((size (nth 7 (file-attributes file)))) > + (cntlst nil)) > + > + (dolist (file (directory-files d t > directory-files-no-dot-files-regexp)) > + (let ((size (if (file-regular-p file) > + (nth 7 (file-attributes file)) > + (chart--directory-size file)))) > (setq nmlst (cons (file-name-nondirectory file) nmlst)) > - (setq cntlst (cons size cntlst))))) > + (setq cntlst (cons (chart--file-size size) cntlst)))) > > (if (not nmlst) > - (error "No files found!")) > - > - ;; Display the chart if files are found > + (error "No files found!")) > (chart-bar-quickie 'vertical (format "Largest files in %s" d) > - nmlst "File Name" > - cntlst "File Size" > - 10 > - (lambda (a b) (> (cdr a) (cdr b)))))) > + nmlst "File Name" > + cntlst "File Size" > + 10 > + (lambda (a b) (> (cdr a) (cdr b)))) > + )) > > (defun chart-emacs-storage () > "Chart the current storage requirements of Emacs." > -- > 2.11.0.windows.3 > > --0000000000003b5ae206211388b8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Clear, thanks for the response!

Op zo 1 sep 2024 om 20:35 s= chreef Eli Zaretskii <eliz@gnu.org&g= t;:
[Please use = Reply All to reply, so that the bug tracker is CC'ed.]

> From: Harm Van der Vegt <harmvegt@gmail.com>
> Date: Sun, 1 Sep 2024 20:11:39 +0200
>
> >Thanks.=C2=A0 However, I think your changes are not entirely corre= ct: they
> >fail to account for space usage of files inside subdirectories of = the
> >directory which the user types at the prompt, whereas the
> >implementation with "du" does account for that.
>
> That is indeed a pretty major difference, my bad!
>
> >In addition, I think if someone has 'du' on Windows, it sh= ould be used.
>
> Is there a preference for using system binaries above elisp for cases = like these?

I think 'du' has some tricks up its sleeve (like accounting correct= ly
for block size), which a Lisp implementation can only approximate.=C2=A0 I<= br> don't think minor differences matter here, since this command is just an illustration of what chart.el can be used for, but I do want to use
'du' if it's available.

> >So I came up with the following changes instead.=C2=A0 Could you p= lease try
> >them, both with and without du.exe on PATH?=C2=A0 If these changes= give
> >good results, I will install them.
>
> Thanks.
>
> I've tried your changes with and without du. This uncovered someth= ing in the
> original implementation, namely that the original implementation did n= ot count
> hidden files and directories. du * skips dotfiles for me.
>
> With du present chart-space-usage shows the lisp directory as the larg= est in the
> emacs repository root. Without du it shows .git as the largest.

This just means minor adjustments in the code I posted: we need to use
a different regexp in the call to directory-files-recursively, and
also ignore files that start with a dot in the command itself.=C2=A0 I will=
make those changes, thanks for pointing them out

> I'm not sure which output is the wanted output.

I think we want to be as close to 'du' as possible.

> I've attempted to find a shell independent way to have du show dot= files, but it
> appears to be rather tricky.

I don't think we want that.

> I've made a new patch that makes the elisp implementation recursiv= e, uses the
> rounding function provided by you and shows dotfiles.

I'd prefer to avoid recursion (in addition to what
directory-files-recursively already does), because that could overflow
the stack.

I will post a version that ignores dotfiles.

Here's the version you sent, repeated for the bug tracker:

>From 6f53d65f9ae5e1c61a2ca2650b149c895ce9794c Mon Sep 17 00:00:00 2001<= br> >From: Harm van der Vegt <harmvegt@gmail.com>
Date: Sun, 1 Sep 2024 20:03:34 +0200
Subject: [PATCH] Make chart-space-usage OS and shell independent

---
=C2=A0lisp/emacs-lisp/chart.el | 41 +++++++++++++++++++++++++++++----------= --
=C2=A01 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/lisp/emacs-lisp/chart.el b/lisp/emacs-lisp/chart.el
index c195ccb7165..b0302b55278 100644
--- a/lisp/emacs-lisp/chart.el
+++ b/lisp/emacs-lisp/chart.el
@@ -641,27 +641,44 @@ SORT-PRED if desired."
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(lambda (a b) (> (cdr a) (cdr b))))
=C2=A0 =C2=A0 =C2=A0))

+;; This assumes 4KB blocks
+(defun chart--file-size (size)
+=C2=A0 (* (/ (+ size 4095) 4096) 4096))
+
+(defun chart--directory-size (dir)
+=C2=A0 "Compute total size of files in directory DIR and its subdirec= tories.
+DIR is assumed to be a directory, verified by the caller."
+=C2=A0 (let ((total-size 0))
+=C2=A0 =C2=A0 (dolist (file (directory-files dir t directory-files-no-dot-= files-regexp))
+=C2=A0 =C2=A0 =C2=A0 (cond
+=C2=A0 =C2=A0 =C2=A0 =C2=A0((file-regular-p file)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq total-size (+ total-size (chart--file-si= ze (nth 7 (file-attributes file))))))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0((file-directory-p file)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq total-size (+ total-size (chart--directo= ry-size file))))))
+=C2=A0 =C2=A0 total-size))
+
=C2=A0(defun chart-space-usage (d)
=C2=A0 =C2=A0"Display a top usage chart for directory D."
=C2=A0 =C2=A0(interactive "DDirectory: ")
=C2=A0 =C2=A0(message "Collecting statistics...")
=C2=A0 =C2=A0(let ((nmlst nil)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 (cntlst nil))
-=C2=A0 =C2=A0 (dolist (file (directory-files d t))
-=C2=A0 =C2=A0 =C2=A0 (when (file-regular-p file)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((size (nth 7 (file-attributes file)))) +=C2=A0 =C2=A0 =C2=A0 =C2=A0(cntlst nil))
+
+=C2=A0 =C2=A0 (dolist (file (directory-files d t directory-files-no-dot-fi= les-regexp))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((size (if (file-regular-p file)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (nth 7 (file-attributes file))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (chart--directory-size file))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq nmlst (cons (file-name-nondi= rectory file) nmlst))
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq cntlst (cons size cntlst)))))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq cntlst (cons (chart--file-size si= ze) cntlst))))

=C2=A0 =C2=A0 =C2=A0(if (not nmlst)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 (error "No files found!"))
-
-=C2=A0 =C2=A0 ;; Display the chart if files are found
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(error "No files found!"))
=C2=A0 =C2=A0 =C2=A0(chart-bar-quickie 'vertical (format "Largest = files in %s" d)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0nmlst "File Name"
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0cntlst "File Size"
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A010
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(lambda (a b) (> (cdr a) (cdr b))))))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 nmlst "File Name"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 cntlst "File Size"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 10
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (lambda (a b) (> (cdr a) (cdr b))))
+=C2=A0 =C2=A0 ))

=C2=A0(defun chart-emacs-storage ()
=C2=A0 =C2=A0"Chart the current storage requirements of Emacs." --
2.11.0.windows.3

--0000000000003b5ae206211388b8--