master - tests: pick either python2 or python3 .so
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3bbdde808a9dcb55a9f...
Commit: 3bbdde808a9dcb55a9ffd092e931dff80814daa7
Parent: fbf64fe730ffa27ee94867017742174f270d3fa0
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri May 18 16:16:40 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri May 18 16:25:44 2018 +0200
tests: pick either python2 or python3 .so
Use matching PYTHON library implementation.
---
test/api/pytest.sh | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/test/api/pytest.sh b/test/api/pytest.sh
index bf31b39..ed9df5e 100644
--- a/test/api/pytest.sh
+++ b/test/api/pytest.sh
@@ -31,7 +31,11 @@ aux prepare_dmeventd
#Locate the python binding library to use.
if [[ -n "${abs_top_builddir+varset}" ]]; then
- python_lib=($(find "$abs_top_builddir" -name lvm*.so))
+ # For python2 look for lvm.so, python3 uses some lengthy names
+ case "$(head -1 $(which python_lvm_unit.py) )" in
+ *2) python_lib=($(find "$abs_top_builddir" -name lvm.so)) ;;
+ *) python_lib=($(find "$abs_top_builddir" -name lvm*gnu.so)) ;;
+ esac
if [[ ${#python_lib[*]} -ne 1 ]]; then
if [[ ${#python_lib[*]} -gt 1 ]]; then
# Unable to test python bindings if multiple libraries found:
@@ -58,9 +62,9 @@ aux prepare_pvs 6
PY_UNIT_PVS=$(cat DEVICES)
export PY_UNIT_PVS
-python_lvm_unit.py -v -f TestLvm.test_lv_persistence
-exit
-#python_lvm_unit.py -v -f
+#When needed to run 1 single individual python test
+#python_lvm_unit.py -v -f TestLvm.test_lv_persistence
+#exit
# Run individual tests for shorter error trace
for i in \
5 years, 10 months
master - tests; make sure python_lvm_unit.py is executable
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=fbf64fe730ffa27ee94...
Commit: fbf64fe730ffa27ee94867017742174f270d3fa0
Parent: 43fb32e761a2c4d1ebaec5eff9d9f0f372563cf9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri May 18 16:16:09 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri May 18 16:25:44 2018 +0200
tests; make sure python_lvm_unit.py is executable
---
test/api/Makefile.in | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/test/api/Makefile.in b/test/api/Makefile.in
index e953675..1659b87 100644
--- a/test/api/Makefile.in
+++ b/test/api/Makefile.in
@@ -38,6 +38,8 @@ SOURCES2 = \
endif
+PYTEST = python_lvm_unit.py
+
include $(top_builddir)/make.tmpl
DEFS += -D_REENTRANT
@@ -48,6 +50,9 @@ LIBS += @LVM2APP_LIB@ $(DMEVENT_LIBS) -ldevmapper
%.t: %.o $(DEPLIBS)
$(CC) -o $@ $(<) $(CFLAGS) $(LDFLAGS) $(ELDFLAGS) $(LIBS)
+all:
+ test -x $(PYTEST) || chmod 755 $(PYTEST)
+
test: $(OBJECTS) $(DEPLIBS)
$(CC) -o $@ $(OBJECTS) $(CFLAGS) $(LDFLAGS) $(ELDFLAGS) $(LIBS) $(READLINE_LIBS)
5 years, 10 months
master - python: use python3 paths directly
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=43fb32e761a2c4d1eba...
Commit: 43fb32e761a2c4d1ebaec5eff9d9f0f372563cf9
Parent: 5b86b0e3dca804fce7c3e6adcd636c0a6d341a9b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu May 17 23:03:36 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri May 18 16:25:44 2018 +0200
python: use python3 paths directly
Do not use /usr/bin/env for path of python3 as this is seen
as 'unwanted' and should be avoided.
---
test/dbus/lvmdbustest.py | 2 +-
test/dbus/testlib.py | 2 +-
test/dbus/validatestate.py | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index 0914b7a..bab9986 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
# Copyright (C) 2015-2016 Red Hat, Inc. All rights reserved.
#
diff --git a/test/dbus/testlib.py b/test/dbus/testlib.py
index 34ff33a..08f612c 100644
--- a/test/dbus/testlib.py
+++ b/test/dbus/testlib.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
# Copyright (C) 2015-2016 Red Hat, Inc. All rights reserved.
#
diff --git a/test/dbus/validatestate.py b/test/dbus/validatestate.py
index faa2083..ae999ad 100755
--- a/test/dbus/validatestate.py
+++ b/test/dbus/validatestate.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
# Copyright (C) 2015-2016 Red Hat, Inc. All rights reserved.
#
5 years, 10 months
master - build: set clean vars earlier
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5b86b0e3dca804fce7c...
Commit: 5b86b0e3dca804fce7c3e6adcd636c0a6d341a9b
Parent: f7435cd8c7bf4c245c9efabbae1274989d2e49ed
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri May 18 16:15:25 2018 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri May 18 16:25:44 2018 +0200
build: set clean vars earlier
For better cleaning of test dirs.
---
daemons/lvmdbusd/Makefile.in | 2 ++
test/Makefile.in | 23 ++++++++++++-----------
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/daemons/lvmdbusd/Makefile.in b/daemons/lvmdbusd/Makefile.in
index 7cd7724..7b62e7e 100644
--- a/daemons/lvmdbusd/Makefile.in
+++ b/daemons/lvmdbusd/Makefile.in
@@ -44,6 +44,8 @@ LVMDBUS_BUILDDIR_FILES = \
LVMDBUSD = lvmdbusd
+CLEAN_DIRS += __pycache__
+
include $(top_builddir)/make.tmpl
.PHONY: install_lvmdbusd
diff --git a/test/Makefile.in b/test/Makefile.in
index 407babd..f6345a5 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -32,6 +32,18 @@ SOURCES = lib/not.c lib/harness.c
CXXSOURCES = lib/runner.cpp
CXXFLAGS += $(EXTRA_EXEC_CFLAGS)
+CLEAN_DIRS += dbus/__pycache__ $(LVM_TEST_RESULTS)
+ifneq (.,$(firstword $(srcdir)))
+CLEAN_TARGETS += $(RUN_BASE) $(addprefix lib/,$(LIB_LVMLOCKD_CONF))
+endif
+
+CLEAN_TARGETS += .lib-dir-stamp .tests-stamp $(LIB) $(addprefix lib/,\
+ $(CMDS) clvmd dmeventd dmsetup dmstats lvmetad lvmpolld \
+ harness lvmdbusd.profile thin-performance.profile fsadm \
+ dm-version-expected version-expected \
+ paths-installed paths-installed-t paths-common paths-common-t)
+
+
include $(top_builddir)/make.tmpl
T ?= .
@@ -352,17 +364,6 @@ LIB = $(addprefix lib/, $(LIB_SHARED) $(LIB_LOCAL) $(LIB_NOT) $(LIB_LINK_NOT) $(
$(LN_S) -f $(abs_top_srcdir)/test/lib/$$i lib/; done
touch $@
-CLEAN_DIRS += $(LVM_TEST_RESULTS)
-ifneq (.,$(firstword $(srcdir)))
-CLEAN_TARGETS += $(RUN_BASE) $(addprefix lib/,$(LIB_LVMLOCKD_CONF))
-endif
-
-CLEAN_TARGETS += .lib-dir-stamp .tests-stamp $(LIB) $(addprefix lib/,\
- $(CMDS) clvmd dmeventd dmsetup dmstats lvmetad lvmpolld \
- harness lvmdbusd.profile thin-performance.profile fsadm \
- dm-version-expected version-expected \
- paths-installed paths-installed-t paths-common paths-common-t)
-
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
5 years, 10 months
master - liblvm2app: add a couple tests
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f7435cd8c7bf4c245c9...
Commit: f7435cd8c7bf4c245c9efabbae1274989d2e49ed
Parent: 286c9c78b49f3b52bb05cef93659bb91e4249dc9
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu May 17 15:55:44 2018 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu May 17 15:55:44 2018 -0500
liblvm2app: add a couple tests
trivial sanity-check programs using liblvm2app
---
liblvm/test/vgadd.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++
liblvm/test/vgshow.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 185 insertions(+), 0 deletions(-)
diff --git a/liblvm/test/vgadd.c b/liblvm/test/vgadd.c
new file mode 100644
index 0000000..c96baa7
--- /dev/null
+++ b/liblvm/test/vgadd.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2009 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include "lvm2app.h"
+
+int main(int argc, char *argv[])
+{
+ char *vgname = NULL;
+ lvm_t handle;
+ vg_t vg;
+ lv_t lv;
+ lvm_str_list_t *sl;
+ pv_list_t *pvl;
+ lv_list_t *lvl;
+ struct dm_list *vgnames;
+ struct dm_list *vgids;
+ struct dm_list *pvlist;
+ struct dm_list *lvlist;
+ int added = 0;
+ int ret;
+ int i;
+
+ vgname = argv[1];
+
+ handle = lvm_init(NULL);
+ if (!handle) {
+ printf("lvm_init failed\n");
+ return -1;
+ }
+
+ vg = lvm_vg_create(handle, vgname);
+
+ for (i = 2; i < argc; i++) {
+ printf("adding %s to vg\n", argv[i]);
+ ret = lvm_vg_extend(vg, argv[i]);
+
+ if (ret) {
+ printf("Failed to add %s to vg\n", argv[i]);
+ goto out;
+ }
+
+ added++;
+ }
+
+ if (!added) {
+ printf("No PVs added, not writing VG.\n");
+ goto out;
+ }
+
+ printf("writing vg\n");
+ ret = lvm_vg_write(vg);
+
+ lvm_vg_close(vg);
+
+ sleep(1);
+
+ vg = lvm_vg_open(handle, vgname, "w", 0);
+ if (!vg) {
+ printf("vg open %s failed\n", vgname);
+ goto out;
+ }
+
+ lv = lvm_vg_create_lv_linear(vg, "lv0", 1024*1024);
+ if (!lv) {
+ printf("lv create failed\n");
+ goto out;
+ }
+
+ lvm_vg_close(vg);
+out:
+ lvm_quit(handle);
+
+ return 0;
+}
diff --git a/liblvm/test/vgshow.c b/liblvm/test/vgshow.c
new file mode 100644
index 0000000..519f3dd
--- /dev/null
+++ b/liblvm/test/vgshow.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2009 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include "lvm2app.h"
+
+int main(int argc, char *argv[])
+{
+ char *vgname = NULL;
+ lvm_t handle;
+ vg_t vg;
+ lvm_str_list_t *sl;
+ pv_list_t *pvl;
+ lv_list_t *lvl;
+ struct dm_list *vgnames;
+ struct dm_list *vgids;
+ struct dm_list *pvlist;
+ struct dm_list *lvlist;
+ uint64_t val;
+
+ vgname = argv[1];
+
+ handle = lvm_init(NULL);
+ if (!handle) {
+ printf("lvm_init failed\n");
+ return -1;
+ }
+
+ vgnames = lvm_list_vg_names(handle);
+
+ dm_list_iterate_items(sl, vgnames)
+ printf("vg name %s\n", sl->str);
+
+ vgids = lvm_list_vg_uuids(handle);
+
+ dm_list_iterate_items(sl, vgids)
+ printf("vg uuid %s\n", sl->str);
+
+ if (!vgname) {
+ printf("No vg name arg\n");
+ goto out;
+ }
+
+ vg = lvm_vg_open(handle, vgname, "r", 0);
+
+ if (!vg) {
+ printf("vg open %s failed\n", vgname);
+ goto out;
+ }
+
+ val = lvm_vg_get_seqno(vg);
+
+ printf("vg seqno %llu\n", (unsigned long long)val);
+
+ pvlist = lvm_vg_list_pvs(vg);
+
+ dm_list_iterate_items(pvl, pvlist) {
+ printf("vg pv name %s\n", lvm_pv_get_name(pvl->pv));
+
+ val = lvm_pv_get_dev_size(pvl->pv);
+
+ printf("vg pv size %llu\n", (unsigned long long)val);
+ }
+
+ lvlist = lvm_vg_list_lvs(vg);
+
+ dm_list_iterate_items(lvl, lvlist) {
+ printf("vg lv name %s\n", lvm_lv_get_name(lvl->lv));
+
+ val = lvm_lv_get_size(lvl->lv);
+
+ printf("vg lv size %llu\n", (unsigned long long)val);
+ }
+
+ lvm_vg_close(vg);
+out:
+ lvm_quit(handle);
+
+ return 0;
+}
5 years, 10 months
master - liblvm2app: fix valgrind memory warning
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=286c9c78b49f3b52bb0...
Commit: 286c9c78b49f3b52bb05cef93659bb91e4249dc9
Parent: a39eaea27dcd2fd895740193e82ca6d0683eb3ad
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu May 17 15:18:11 2018 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu May 17 15:18:11 2018 -0500
liblvm2app: fix valgrind memory warning
---
lib/metadata/metadata.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 2609840..2f84d5f 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -4830,7 +4830,7 @@ static int _get_pvs(struct cmd_context *cmd, uint32_t warn_flags,
struct dm_list *pvslist, struct dm_list *vgslist)
{
struct dm_str_list *strl;
- const char *vgname, *vgid;
+ const char *vgname, *name, *vgid;
struct pv_list *pvl, *pvl_copy;
struct dm_list *vgids;
struct volume_group *vg;
@@ -4856,11 +4856,13 @@ static int _get_pvs(struct cmd_context *cmd, uint32_t warn_flags,
if (!vgid)
continue; /* FIXME Unnecessary? */
consistent = 0;
- if (!(vgname = lvmcache_vgname_from_vgid(NULL, vgid))) {
+ if (!(name = lvmcache_vgname_from_vgid(NULL, vgid))) {
stack;
continue;
}
+ vgname = dm_pool_strdup(cmd->mem, name);
+
/*
* When we are retrieving a list to return toliblvm we need
* that list to contain VGs that are modifiable as we are using
5 years, 10 months
master - tests: fix kernal_at_least argument in aux.sh
by Heinz Mauelshagen
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a39eaea27dcd2fd8957...
Commit: a39eaea27dcd2fd895740193e82ca6d0683eb3ad
Parent: 5052970da3bdf3ef702fa0f54a25cc2a44d0829e
Author: Heinz Mauelshagen <heinzm(a)redhat.com>
AuthorDate: Thu May 17 14:40:17 2018 +0200
Committer: Heinz Mauelshagen <heinzm(a)redhat.com>
CommitterDate: Thu May 17 14:41:47 2018 +0200
tests: fix kernal_at_least argument in aux.sh
---
test/lib/aux.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 5b2aebf..f6206ce 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -843,7 +843,7 @@ prepare_backing_dev() {
return 0
elif test "${LVM_TEST_PREFER_BRD-1}" = "1" && \
test ! -d /sys/block/ram0 && \
- kernel_at_least 4 16 && \
+ kernel_at_least 4 16 0 && \
test "$size" -lt 16384; then
# try to use ramdisk if possible, but for
# big allocs (>16G) do not try to use ramdisk
5 years, 10 months
master - bcache: Don't call sysconf for every io
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5052970da3bdf3ef702...
Commit: 5052970da3bdf3ef702fa0f54a25cc2a44d0829e
Parent: 7ee0a6e44d5e6c1085d04c407453f69ac14935b0
Author: Joe Thornber <ejt(a)redhat.com>
AuthorDate: Thu May 17 10:05:10 2018 +0100
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu May 17 10:05:10 2018 +0100
bcache: Don't call sysconf for every io
---
lib/device/bcache.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index 3f5a45e..9e94fcc 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -133,6 +133,7 @@ struct async_engine {
struct io_engine e;
io_context_t aio_context;
struct cb_set *cbs;
+ unsigned page_mask;
};
static struct async_engine *_to_async(struct io_engine *e)
@@ -162,9 +163,8 @@ static bool _async_issue(struct io_engine *ioe, enum dir d, int fd,
struct iocb *cb_array[1];
struct control_block *cb;
struct async_engine *e = _to_async(ioe);
- long pgsize = sysconf(_SC_PAGESIZE);
- if (((uintptr_t) data) & (pgsize - 1)) {
+ if (((uintptr_t) data) & e->page_mask) {
log_warn("misaligned data buffer");
return false;
}
@@ -276,6 +276,8 @@ struct io_engine *create_async_io_engine(void)
return NULL;
}
+ e->page_mask = sysconf(_SC_PAGESIZE) - 1;
+
return &e->e;
}
@@ -544,11 +546,10 @@ static void _hash_table_exit(struct bcache *cache)
//----------------------------------------------------------------
-static bool _init_free_list(struct bcache *cache, unsigned count)
+static bool _init_free_list(struct bcache *cache, unsigned count, unsigned pgsize)
{
unsigned i;
size_t block_size = cache->block_sectors << SECTOR_SHIFT;
- long pgsize = sysconf(_SC_PAGESIZE);
unsigned char *data =
(unsigned char *) _alloc_aligned(count * block_size, pgsize);
@@ -949,7 +950,7 @@ struct bcache *bcache_create(sector_t block_sectors, unsigned nr_cache_blocks,
cache->write_misses = 0;
cache->prefetches = 0;
- if (!_init_free_list(cache, nr_cache_blocks)) {
+ if (!_init_free_list(cache, nr_cache_blocks, pgsize)) {
cache->engine->destroy(cache->engine);
_hash_table_exit(cache);
dm_free(cache);
5 years, 10 months
master - Merge branch 'master' of git://sourceware.org/git/lvm2
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7ee0a6e44d5e6c1085d...
Commit: 7ee0a6e44d5e6c1085d04c407453f69ac14935b0
Parent: 3417d6229dcdcb2e1c9595026a8f97d10f25804a c6ca81a38d7012ec9d18a9ea00eff321ff2c47d0
Author: Joe Thornber <ejt(a)redhat.com>
AuthorDate: Thu May 17 09:52:57 2018 +0100
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu May 17 09:52:57 2018 +0100
Merge branch 'master' of git://sourceware.org/git/lvm2
lib/device/bcache.c | 9 ++++++---
lib/label/label.c | 8 +++++++-
lib/label/label.h | 1 +
lib/metadata/cache_manip.c | 4 ++--
lib/metadata/metadata-liblvm.c | 13 +------------
lib/metadata/metadata.c | 4 ++--
lib/metadata/thin_manip.c | 2 +-
test/shell/lvconvert-repair-mirror.sh | 2 +-
test/shell/lvextend-thin-metadata-dmeventd.sh | 4 ++--
tools/toollib.c | 2 +-
10 files changed, 24 insertions(+), 25 deletions(-)
5 years, 10 months
master - scripts/code-stats.rb: count files better, handle bad utf8
by Joe Thornber
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3417d6229dcdcb2e1c9...
Commit: 3417d6229dcdcb2e1c9595026a8f97d10f25804a
Parent: 64dd656ef7943f9991c83802dfa5f762c902e1fb
Author: Joe Thornber <ejt(a)redhat.com>
AuthorDate: Thu May 17 09:52:13 2018 +0100
Committer: Joe Thornber <ejt(a)redhat.com>
CommitterDate: Thu May 17 09:52:13 2018 +0100
scripts/code-stats.rb: count files better, handle bad utf8
---
scripts/code-stats.rb | 28 +++++++++++++++++++---------
1 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/scripts/code-stats.rb b/scripts/code-stats.rb
index e87de26..d73343b 100755
--- a/scripts/code-stats.rb
+++ b/scripts/code-stats.rb
@@ -2,21 +2,22 @@
require 'date'
require 'pp'
+require 'set'
REGEX = /(\w+)\s+'(.+)'\s+(.*)/
Commit = Struct.new(:hash, :time, :author, :stats)
-CommitStats = Struct.new(:nr_files, :nr_added, :nr_deleted)
+CommitStats = Struct.new(:files, :nr_added, :nr_deleted)
def calc_stats(diff)
- changed = 0
+ changed = Set.new
added = 0
deleted = 0
diff.lines.each do |l|
- case l
- when /^\+\+\+/
- changed = changed + 1
+ case l.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
+ when /^\+\+\+ (\S+)/
+ changed << $1
when /^\+/
added = added + 1
when /^---/
@@ -61,20 +62,29 @@ def pad(str, col)
str + (' ' * (col - str.size))
end
+def code_delta(s)
+ s.nr_added + s.nr_deleted
+end
+
+def cmp_stats(lhs, rhs)
+ code_delta(rhs) <=> code_delta(lhs)
+end
+
#-----------------------------------
commits = select_commits(&since(DateTime.now - 14))
-authors = Hash.new {|hash, key| hash[key] = CommitStats.new(0, 0, 0)}
+authors = Hash.new {|hash, key| hash[key] = CommitStats.new(Set.new, 0, 0)}
commits.each do |c|
author_stats = authors[c.author]
- author_stats.nr_files = author_stats.nr_files + c.stats.nr_files
+ author_stats.files.merge(c.stats.files)
author_stats.nr_added = author_stats.nr_added + c.stats.nr_added
author_stats.nr_deleted = author_stats.nr_deleted + c.stats.nr_deleted
end
puts "#{pad("Author", 20)}\tChanged files\tInsertions\tDeletions"
-authors.each_pair do |k, v|
- puts "#{pad(k, 20)}\t#{v.nr_files}\t\t#{v.nr_added}\t\t#{v.nr_deleted}"
+authors.keys.sort {|a1, a2| cmp_stats(authors[a1], authors[a2])}.each do |k|
+ v = authors[k]
+ puts "#{pad(k, 20)}\t#{v.files.size}\t\t#{v.nr_added}\t\t#{v.nr_deleted}"
end
5 years, 10 months