From nobody Thu Jan 16 16:03:52 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YYnjN3W1qz5kcCy; Thu, 16 Jan 2025 16:03:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YYnjN2kqjz3Dsb; Thu, 16 Jan 2025 16:03:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737043432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eW40lEsuNVOGALY6QmEu11h91+tbOlMVuLE1v+C3/i8=; b=xeli8kYOT8tog7oW3BLq0c1/JiePo0+iyjiU+pOJckxoaqagz6je/UoJEUgMRL3Fuy/b48 8xAPLcxI3VQedPvmZcAku2OsN4ZFTT2WVZURAhp6Xv0IaFweHhHn7LKKy1n/TC8m9aP0Dk HnwUb1KjMtpvVb8UaMCtMlirAYrTX4U2XyGjvMORMXAQsKd5GJcwTisg4AaYY7fPVhE4BJ bVajChIuZYWS7qpXlMZbkvSYSMSbXxbPkEXexxMlY7vCgwkfhHz7gBptmYQujcj4q4XUuO 9qndlS86s5ixYp629+yYkV/6MTPdCVsPzE+NF1eckd9PJlMpnPo6iFCXCwY3ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737043432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eW40lEsuNVOGALY6QmEu11h91+tbOlMVuLE1v+C3/i8=; b=QfXY/a56KjWu+8+srhg98tzPS1qlQHqfmklrSt9zRV0tNvAMJEZUDELBjYnK9uo+xxxTm0 /isTjl4ix0CFxN9AL/LOaxlcp2QbGNvssNFZBVT/8GxbTGh3dcMFe87uDz7t0HLQmPrh/q Y0C44E2EWzzSI6QQXv5wv4OuwGZan2iWj7LbqDEPV//BOk8sOf2jrI85PKB9YSTdlaDgCm h5NCNNxDn4uJCbt2HrqaPDlnItZQ7rhfRDnyfxIKCrdvx8wlGUc7k0DJbb08ZEH7ERckNb sBzKDpOvw/oxq8pNCdcJboZSw8Tut6fJ7JnFeCXr/Ug5/6paBgDlwS6kVTP4pw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737043432; a=rsa-sha256; cv=none; b=d4oLR7153Y9XdzS8ib648djr/69XpmhNBYi1F+wYw3py3Z6a/RIMzl27Ua+dgICbHtFeMN 1+pxyB4ojJTZXeP5gtVhQsQMlnjfcuKuYY/Au6EAatKuGt/HIan6UDRP+Olw8njq1mrNOU 3kouHNdzbxECpRGIEYY+JDq6H2JihlT9BrKkyY/qAR7U86cjj1MRvHEZxKAfELPwZWVawd iE29C19KRGEEb66Vol5RR79Hy69zjEK73I03FhFPfrZd8keD0w1uUjAEQ5b3TnZnyBxdS4 t4WfQVNSrHHXBMAJ5AYFVKlXXeaiOEZXcjrYXaA9U6rTBFbLzxgb3/ThkZqpzg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YYnjN2Kh6zg12; Thu, 16 Jan 2025 16:03:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50GG3q8t064540; Thu, 16 Jan 2025 16:03:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50GG3qM9064537; Thu, 16 Jan 2025 16:03:52 GMT (envelope-from git) Date: Thu, 16 Jan 2025 16:03:52 GMT Message-Id: <202501161603.50GG3qM9064537@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Pawel Stefaniak Subject: git: 82fa7f83b53b - main - ls -lh: humanize the total List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pstef X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 82fa7f83b53b3c5b7f3a5c5560edc7caeeaa1029 Auto-Submitted: auto-generated The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=82fa7f83b53b3c5b7f3a5c5560edc7caeeaa1029 commit 82fa7f83b53b3c5b7f3a5c5560edc7caeeaa1029 Author: Piotr Paweł Stefaniak AuthorDate: 2025-01-06 17:59:03 +0000 Commit: Piotr Paweł Stefaniak CommitDate: 2025-01-16 16:00:17 +0000 ls -lh: humanize the total Before this change, the total printed on the first line was always in blocks. Now the long format with -h will print the "humanized number" instead. `ls -sh` never provided sizes in anything other than blocks, total or individual, and this commit doesn't change that. The total number of blocks is a sum of fts_statp->st_blocks, so it's multiplied by 512 and not by blocksize. $ ls -lh /usr/bin | head -n 2 total 442 MB -r-xr-xr-x 1 root wheel 70B Dec 20 21:06 CC Differential Revision: https://reviews.freebsd.org/D48329 --- bin/ls/ls.1 | 4 ++++ bin/ls/print.c | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/bin/ls/ls.1 b/bin/ls/ls.1 index d86250b82db2..6aaa5025a6e1 100644 --- a/bin/ls/ls.1 +++ b/bin/ls/ls.1 @@ -539,6 +539,10 @@ which are listed as the directory's contents and .Pa .. and other files which start with a dot, depending on other options). +If the +.Fl h +option is given, +the total size is displayed as the number of bytes. .Pp The default block size is 512 bytes. The block size may be set with option diff --git a/bin/ls/print.c b/bin/ls/print.c index f651dea5de90..a504ec63dc26 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -210,7 +210,14 @@ printlong(const DISPLAY *dp) if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) && (f_longform || f_size)) { - (void)printf("total %lu\n", howmany(dp->btotal, blocksize)); + if (!f_humanval) + (void)printf("total %lu\n", howmany(dp->btotal, blocksize)); + else { + (void)humanize_number(buf, 7 /* "1024 KB" */, + dp->btotal * 512, "B", HN_AUTOSCALE, HN_DECIMAL); + + (void)printf("total %s\n", buf); + } } for (p = dp->list; p; p = p->fts_link) {