From ff77fbf5d96f9250f7478036148deff87ac6ca3f Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Fri, 13 Jun 2014 11:42:20 +0100 Subject: [PATCH 1/6] Sort PackagesList by name and version --- deb/list.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/deb/list.go b/deb/list.go index b615b5d2..cf46bb40 100644 --- a/deb/list.go +++ b/deb/list.go @@ -300,9 +300,16 @@ func (l *PackageList) Swap(i, j int) { l.packagesIndex[i], l.packagesIndex[j] = l.packagesIndex[j], l.packagesIndex[i] } -// Compare compares two names in lexographical order +// Compare compares two packages by name in lexographical order and version func (l *PackageList) Less(i, j int) bool { - return l.packagesIndex[i].Name < l.packagesIndex[j].Name + iPkg := l.packagesIndex[i] + jPkg := l.packagesIndex[j] + + if iPkg.Name == jPkg.Name { + return CompareVersions(iPkg.Version, jPkg.Version) == -1 + } + + return iPkg.Name < jPkg.Name } // PrepareIndex prepares list for indexing From e19a615641c9c4160066ef4df95fb47af1a0bdfa Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Fri, 13 Jun 2014 12:06:33 +0100 Subject: [PATCH 2/6] In PackageList, sort the package version from latest to oldest This enables us to return the latest version of a package when no version is specified rather than the oldest. Therefore, we don't need to modify the search algorithm to return the latest version of a package. --- deb/list.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deb/list.go b/deb/list.go index cf46bb40..cbe25d5f 100644 --- a/deb/list.go +++ b/deb/list.go @@ -300,13 +300,13 @@ func (l *PackageList) Swap(i, j int) { l.packagesIndex[i], l.packagesIndex[j] = l.packagesIndex[j], l.packagesIndex[i] } -// Compare compares two packages by name in lexographical order and version +// Compare compares two packages by name (lexographical) and version (latest to oldest) func (l *PackageList) Less(i, j int) bool { iPkg := l.packagesIndex[i] jPkg := l.packagesIndex[j] if iPkg.Name == jPkg.Name { - return CompareVersions(iPkg.Version, jPkg.Version) == -1 + return CompareVersions(iPkg.Version, jPkg.Version) == 1 } return iPkg.Name < jPkg.Name From e311d41dd7f7ce0841ef9d65bdde0e02f8c6a5d4 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 27 Jun 2014 23:49:05 +0400 Subject: [PATCH 3/6] Add Simon Aquino to authors. #67 --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 84d6fd11..d8e8ad09 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,3 +3,4 @@ List of contributors, in chronological order: * Andrey Smirnov (https://github.com/smira) * Sebastien Binet (https://github.com/sbinet) * Ryan Uber (https://github.com/ryanuber) +* Simon Aquino (https://github.com/simonaquino) \ No newline at end of file From 86b0860463791df47a8d0f5f661b173c6e05d1ee Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 27 Jun 2014 23:53:37 +0400 Subject: [PATCH 4/6] Enable system tests fixture under go1.3 as well. #72 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index df3f35a9..686c09b3 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ install: $(GOM) build -o $(BINPATH)/aptly system-test: install -ifeq ($(GOVERSION),$(filter $(GOVERSION),go1.2 go1.2.1 devel)) +ifeq ($(GOVERSION),$(filter $(GOVERSION),go1.2 go1.2.1 go1.3 devel)) if [ ! -e ~/aptly-fixture-db ]; then git clone https://github.com/aptly-dev/aptly-fixture-db.git ~/aptly-fixture-db/; fi endif if [ ! -e ~/aptly-fixture-pool ]; then git clone https://github.com/aptly-dev/aptly-fixture-pool.git ~/aptly-fixture-pool/; fi From 980102462b565ef34abf412db5d1723dd6bbb0e1 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Sat, 28 Jun 2014 00:10:35 +0400 Subject: [PATCH 5/6] Simplify Makefile. --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 686c09b3..4be0b733 100644 --- a/Makefile +++ b/Makefile @@ -77,9 +77,7 @@ src-package: mkdir -p aptly-$(VERSION)/src/github.com/smira/aptly/ cd aptly-$(VERSION)/src/github.com/smira/ && git clone https://github.com/smira/aptly && cd aptly && git checkout v$(VERSION) cd aptly-$(VERSION)/src/github.com/smira/aptly && gom -production install - cd aptly-$(VERSION)/src/github.com/smira/aptly && find . -name .git -print | xargs rm -rf - cd aptly-$(VERSION)/src/github.com/smira/aptly && find . -name .bzr -print | xargs rm -rf - cd aptly-$(VERSION)/src/github.com/smira/aptly && find . -name .hg -print | xargs rm -rf + cd aptly-$(VERSION)/src/github.com/smira/aptly && find . \( -name .git -o -name .bzr -o -name .hg \) -print | xargs rm -rf rm -rf aptly-$(VERSION)/src/github.com/smira/aptly/_vendor/{pkg,bin} tar cyf aptly-$(VERSION)-src.tar.bz2 aptly-$(VERSION) rm -rf aptly-$(VERSION) From 44ce4c8a77da78161186b5211827e957917b4283 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Sat, 28 Jun 2014 00:26:56 +0400 Subject: [PATCH 6/6] Insert into right position when adding as well. #67 --- deb/list.go | 13 +++++++------ deb/list_test.go | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/deb/list.go b/deb/list.go index cbe25d5f..4d379cad 100644 --- a/deb/list.go +++ b/deb/list.go @@ -101,7 +101,7 @@ func (l *PackageList) Add(p *Package) error { l.providesIndex[provides] = append(l.providesIndex[provides], p) } - i := sort.Search(len(l.packagesIndex), func(j int) bool { return l.packagesIndex[j].Name >= p.Name }) + i := sort.Search(len(l.packagesIndex), func(j int) bool { return l.lessPackages(p, l.packagesIndex[j]) }) // insert p into l.packagesIndex in position i l.packagesIndex = append(l.packagesIndex, nil) @@ -300,11 +300,7 @@ func (l *PackageList) Swap(i, j int) { l.packagesIndex[i], l.packagesIndex[j] = l.packagesIndex[j], l.packagesIndex[i] } -// Compare compares two packages by name (lexographical) and version (latest to oldest) -func (l *PackageList) Less(i, j int) bool { - iPkg := l.packagesIndex[i] - jPkg := l.packagesIndex[j] - +func (l *PackageList) lessPackages(iPkg, jPkg *Package) bool { if iPkg.Name == jPkg.Name { return CompareVersions(iPkg.Version, jPkg.Version) == 1 } @@ -312,6 +308,11 @@ func (l *PackageList) Less(i, j int) bool { return iPkg.Name < jPkg.Name } +// Less compares two packages by name (lexographical) and version (latest to oldest) +func (l *PackageList) Less(i, j int) bool { + return l.lessPackages(l.packagesIndex[i], l.packagesIndex[j]) +} + // PrepareIndex prepares list for indexing func (l *PackageList) PrepareIndex() { l.packagesIndex = make([]*Package, l.Len()) diff --git a/deb/list_test.go b/deb/list_test.go index 953f5e85..5a7db3be 100644 --- a/deb/list_test.go +++ b/deb/list_test.go @@ -218,6 +218,9 @@ func (s *PackageListSuite) TestSearch(c *C) { c.Check(s.il.Search(Dependency{Architecture: "i386", Pkg: "app", Relation: VersionGreaterOrEqual, Version: "1.0"}), Equals, s.packages[3]) c.Check(s.il.Search(Dependency{Architecture: "i386", Pkg: "app", Relation: VersionGreaterOrEqual, Version: "1.1~bp1"}), Equals, s.packages[3]) c.Check(s.il.Search(Dependency{Architecture: "i386", Pkg: "app", Relation: VersionGreaterOrEqual, Version: "1.2"}), IsNil) + + // search w/o version should return package with latest version + c.Check(s.il.Search(Dependency{Architecture: "source", Pkg: "dpkg"}), Equals, s.packages[13]) } func (s *PackageListSuite) TestFilter(c *C) {