about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--.document3
-rw-r--r--.gitignore4
-rwxr-xr-xGIT-VERSION-GEN40
-rw-r--r--GNUmakefile143
-rw-r--r--Rakefile112
-rw-r--r--clogger.gemspec16
6 files changed, 246 insertions, 72 deletions
diff --git a/.document b/.document
index b9cb90b..243e30e 100644
--- a/.document
+++ b/.document
@@ -1,4 +1,5 @@
 README
-History
+NEWS
+ChangeLog
 lib
 ext/clogger_ext/clogger.c
diff --git a/.gitignore b/.gitignore
index 31a1a8b..973362b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,4 +12,6 @@ Makefile
 /local.mk
 /pkg
 /.manifest
-/History
+/ChangeLog
+/NEWS
+/GIT-VERSION-FILE
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
new file mode 100755
index 0000000..47770a8
--- /dev/null
+++ b/GIT-VERSION-GEN
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+GVF=GIT-VERSION-FILE
+DEF_VER=v0.0.7.GIT
+
+LF='
+'
+
+# First see if there is a version file (included in release tarballs),
+# then try git-describe, then default.
+if test -f version
+then
+        VN=$(cat version) || VN="$DEF_VER"
+elif test -d .git -o -f .git &&
+        VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
+        case "$VN" in
+        *$LF*) (exit 1) ;;
+        v[0-9]*)
+                git update-index -q --refresh
+                test -z "$(git diff-index --name-only HEAD --)" ||
+                VN="$VN-dirty" ;;
+        esac
+then
+        VN=$(echo "$VN" | sed -e 's/-/./g');
+else
+        VN="$DEF_VER"
+fi
+
+VN=$(expr "$VN" : v*'\(.*\)')
+
+if test -r $GVF
+then
+        VC=$(sed -e 's/^GIT_VERSION = //' <$GVF)
+else
+        VC=unset
+fi
+test "$VN" = "$VC" || {
+        echo >&2 "GIT_VERSION = $VN"
+        echo "GIT_VERSION = $VN" >$GVF
+}
diff --git a/GNUmakefile b/GNUmakefile
index 17b8b2e..51f1c8f 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,7 +1,11 @@
 all:: test
 ruby = ruby
 rake = rake
+GIT_URL = git://git.bogomips.org/clogger.git
 
+GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
+        @./GIT-VERSION-GEN
+-include GIT-VERSION-FILE
 -include local.mk
 
 ifeq ($(DLEXT),) # "so" for Linux
@@ -26,84 +30,117 @@ test-pure:
 
 test: test-ext test-pure
 
-History:
-        $(rake) -s history > $@+
+pkg_extra := GIT-VERSION-FILE NEWS ChangeLog
+manifest: $(pkg_extra)
+        $(RM) .manifest
+        $(MAKE) .manifest
+
+.manifest:
+        (git ls-files && \
+         for i in $@ $(pkg_extra); \
+         do echo $$i; done) | LC_ALL=C sort > $@+
+        cmp $@+ $@ || mv $@+ $@
+        $(RM) $@+
+
+NEWS: GIT-VERSION-FILE
+        $(rake) -s news_rdoc > $@+
         mv $@+ $@
 
-.manifest: History
-        (git ls-files; for i in $^ $@; do echo $$i; done) | LC_ALL=C sort > $@+
+SINCE = 0.0.7
+ChangeLog: log_range = $(shell test -n "$(SINCE)" && echo v$(SINCE)..)
+ChangeLog: GIT-VERSION-FILE
+        @echo "ChangeLog from $(GIT_URL) ($(SINCE)..$(GIT_VERSION))" > $@+
+        @echo >> $@+
+        git log $(log_range) | sed -e 's/^/    /' >> $@+
         mv $@+ $@
 
-VERSION := $(shell git describe 2>/dev/null | sed 's/^v//')
+news_atom := http://clogger.rubyforge.org/NEWS.atom.xml
+cgit_atom := http://git.bogomips.org/cgit/clogger.git/atom/?h=master
+atom = <link rel="alternate" title="Atom feed" href="$(1)" \
+             type="application/atom+xml"/>
+
+doc: .document NEWS ChangeLog
+        rdoc -Na -t "$(shell sed -ne '1s/^= //p' README)"
+        install -m644 COPYING doc/COPYING
+        install -m644 $(shell grep '^[A-Z]' .document)  doc/
+        $(ruby) -i -p -e \
+          '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
+          doc/ChangeLog.html
+        $(ruby) -i -p -e \
+          '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
+          doc/NEWS.html doc/README.html
+        $(rake) -s news_atom > doc/NEWS.atom.xml
+        cd doc && ln README.html tmp && mv tmp index.html
+
+# publishes docs to http://clogger.rubyforge.org/
+# this preserves timestamps as best as possible to help HTTP caches out
+# git set-file-times is here: http://git-scm.org/gitwiki/ExampleScripts
+publish_doc:
+        git set-file-times
+        $(RM) -r doc
+        $(MAKE) doc
+        rsync -av --delete doc/ rubyforge.org:/var/www/gforge-projects/clogger/
+        git ls-files | xargs touch
 
 ifneq ($(VERSION),)
-v := /^v$(VERSION)$$/
-vPREV := $(shell git tag -l 2>/dev/null | sed -n -e '$(v)!h' -e '$(v){x;p;q}')
+rfproject := clogger
+rfpackage := clogger
+pkggem := pkg/$(rfpackage)-$(VERSION).gem
+pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
 release_notes := release_notes-$(VERSION)
 release_changes := release_changes-$(VERSION)
+
 release-notes: $(release_notes)
 release-changes: $(release_changes)
-$(release_changes): verify
-        git diff --stat $(vPREV) v$(VERSION) > $@+
-        echo >> $@+
-        git log $(vPREV)..v$(VERSION) >> $@+
+$(release_changes):
+        $(rake) -s release_changes > $@+
         $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
-$(release_notes): pkggem = pkg/clogger-$(VERSION).gem
-$(release_notes): verify package
-        gem spec $(pkggem) description | sed -ne '/\w/p' > $@+
-        echo >> $@+
-        gem spec $(pkggem) homepage | sed -ne 's/^--- /* /p' >> $@+
-        gem spec $(pkggem) email | sed -ne 's/^--- /* /p' >> $@+
-        echo '* git://git.bogomips.org/clogger.git' >> $@+
-        echo >> $@+
-        echo Changes: >> $@+
-        echo >> $@+
-        git cat-file tag v$(VERSION) | awk 'p>1{print $$0}/^$$/{++p}' >> $@+
+$(release_notes):
+        GIT_URL=$(GIT_URL) $(rake) -s release_notes > $@+
         $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
+
+# ensures we're actually on the tagged $(VERSION), only used for release
 verify:
-        @test -n "$(VERSION)" || { echo >&2 VERSION= not defined; exit 1; }
+        test x"$(shell umask)" = x0022
         git rev-parse --verify refs/tags/v$(VERSION)^{}
-        @test -n "$(VISUAL)" || { echo >&2 VISUAL= not defined; exit 1; }
         git diff-index --quiet HEAD^0
         test `git rev-parse --verify HEAD^0` = \
              `git rev-parse --verify refs/tags/v$(VERSION)^{}`
 
-pkg/clogger-$(VERSION).gem: .manifest History clogger.gemspec
-        gem build clogger.gemspec
+fix-perms:
+        -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
+        -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
+
+gem: $(pkggem)
+
+install-gem: $(pkggem)
+        gem install $(CURDIR)/$<
+
+$(pkggem): manifest fix-perms
+        gem build $(rfpackage).gemspec
         mkdir -p pkg
         mv $(@F) $@
 
-pkg/clogger-$(VERSION).tgz: HEAD = v$(VERSION)
-pkg/clogger-$(VERSION).tgz: .manifest History
-        $(RM) -r $(basename $@)
-        git archive --format=tar --prefix=$(basename $@)/ $(HEAD) | tar xv
-        install -m644 $^ $(basename $@)
-        cd pkg && tar cv $(basename $(@F)) | gzip -9 > $(@F)+
+$(pkgtgz): distdir = $(basename $@)
+$(pkgtgz): HEAD = v$(VERSION)
+$(pkgtgz): manifest fix-perms
+        @test -n "$(distdir)"
+        $(RM) -r $(distdir)
+        mkdir -p $(distdir)
+        tar c `cat .manifest` | (cd $(distdir) && tar x)
+        cd pkg && tar c $(basename $(@F)) | gzip -9 > $(@F)+
         mv $@+ $@
 
-package: pkg/clogger-$(VERSION).gem pkg/clogger-$(VERSION).tgz
+package: $(pkgtgz) $(pkggem)
 
-# not using Hoe's release system since we release 2 gems but only one tgz
-release: package $(release_notes) $(release_changes)
+release: verify package $(release_notes) $(release_changes)
         rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
-          clogger clogger $(VERSION) pkg/clogger-$(VERSION).gem
+          $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
         rubyforge add_file \
-          clogger clogger $(VERSION) pkg/clogger-$(VERSION).tgz
+          $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
+else
+gem install-gem: GIT-VERSION-FILE
+        $(MAKE) $@ VERSION=$(GIT_VERSION)
 endif
 
-doc: .document History
-        rdoc -Na -t "$(shell sed -ne '1s/^= //p' README)"
-        install -m644 COPYING doc/COPYING
-        cd doc && ln README.html tmp.html && mv tmp.html index.html
-
-# publishes docs to http://clogger.rubyforge.org/
-# this preserves timestamps as best as possible to help HTTP caches out
-# git set-file-times is here: http://git-scm.org/gitwiki/ExampleScripts
-publish_doc:
-        git set-file-times
-        $(RM) -r doc
-        $(MAKE) doc
-        rsync -av --delete doc/ rubyforge.org:/var/www/gforge-projects/clogger/
-        git ls-files | xargs touch
-
-.PHONY: test doc .manifest release History
+.PHONY: .FORCE-GIT-VERSION-FILE test doc manifest
diff --git a/Rakefile b/Rakefile
index dc7220c..ff739a8 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,21 +5,6 @@ rescue LoadError
   warn "rake-compiler not available, cross compiling disabled"
 end
 
-desc 'prints RDoc-formatted history'
-task :history do
-  tags = `git tag -l`.split(/\n/).grep(/^v/).reverse
-  timefmt = '%Y-%m-%d %H:%M UTC'
-  tags.each do |tag|
-    header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
-    tagger = header.split(/\n/).grep(/^tagger /).first.split(/\s/)
-    time = Time.at(tagger[-2].to_i).utc
-    puts "=== #{tag.sub(/^v/, '')} / #{time.strftime(timefmt)}"
-    puts ""
-    puts body.gsub(/^/sm, "  ")
-    puts ""
-  end
-end
-
 desc "read news article from STDIN and post to rubyforge"
 task :publish_news do
   require 'rubyforge'
@@ -35,3 +20,100 @@ task :publish_news do
   rf.login
   rf.post_news('clogger', subject, body)
 end
+
+def tags
+  timefmt = '%Y-%m-%dT%H:%M:%SZ'
+  @tags ||= `git tag -l`.split(/\n/).map do |tag|
+    next if tag == "v0.0.0"
+    if %r{\Av[\d\.]+\z} =~ tag
+      header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
+      header = header.split(/\n/)
+      tagger = header.grep(/\Atagger /).first
+      body ||= "initial"
+      {
+        :time => Time.at(tagger.split(/ /)[-2].to_i).utc.strftime(timefmt),
+        :tagger_name => %r{^tagger ([^<]+)}.match(tagger)[1],
+        :tagger_email => %r{<([^>]+)>}.match(tagger)[1],
+        :id => `git rev-parse refs/tags/#{tag}`.chomp!,
+        :tag => tag,
+        :subject => subject,
+        :body => body,
+      }
+    end
+  end.compact.sort { |a,b| b[:time] <=> a[:time] }
+end
+
+cgit_url = "http://git.bogomips.org/cgit/clogger.git"
+
+desc 'prints news as an Atom feed'
+task :news_atom do
+  require 'nokogiri'
+  new_tags = tags[0,10]
+  puts(Nokogiri::XML::Builder.new do
+    feed :xmlns => "http://www.w3.org/2005/Atom" do
+      id! "http://clogger.rubyforge.org/NEWS.atom.xml"
+      title "Clogger news"
+      subtitle "configurable request logging for Rack"
+      link! :rel => 'alternate', :type => 'text/html',
+            :href => 'http://clogger.rubyforge.org/NEWS.html'
+      updated new_tags.first[:time]
+      new_tags.each do |tag|
+        entry do
+          title tag[:subject]
+          updated tag[:time]
+          published tag[:time]
+          author {
+            name tag[:tagger_name]
+            email tag[:tagger_email]
+          }
+          url = "#{cgit_url}/tag/?id=#{tag[:tag]}"
+          link! :rel => "alternate", :type => "text/html", :href =>url
+          id! url
+          content(:type => 'text') { tag[:body] }
+        end
+      end
+    end
+  end.to_xml)
+end
+
+desc 'prints RDoc-formatted news'
+task :news_rdoc do
+  tags.each do |tag|
+    time = tag[:time].tr!('T', ' ').gsub!(/:\d\dZ/, ' UTC')
+    puts "=== #{tag[:tag].sub(/^v/, '')} / #{time}"
+    puts ""
+
+    body = tag[:body]
+    puts tag[:body].gsub(/^/sm, "  ").gsub(/[ \t]+$/sm, "")
+    puts ""
+  end
+end
+
+desc "print release changelog for Rubyforge"
+task :release_changes do
+  version = ENV['VERSION'] or abort "VERSION= needed"
+  version = "v#{version}"
+  vtags = tags.map { |tag| tag[:tag] =~ /\Av/ and tag[:tag] }.sort
+  prev = vtags[vtags.index(version) - 1]
+  system('git', 'diff', '--stat', prev, version) or abort $?
+  puts ""
+  system('git', 'log', "#{prev}..#{version}") or abort $?
+end
+
+desc "print release notes for Rubyforge"
+task :release_notes do
+  require 'rubygems'
+
+  git_url = ENV['GIT_URL'] || 'git://git.bogomips.org/clogger.git'
+
+  spec = Gem::Specification.load('clogger.gemspec')
+  puts spec.description.strip
+  puts ""
+  puts "* #{spec.homepage}"
+  puts "* #{spec.email}"
+  puts "* #{git_url}"
+
+  _, _, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
+  print "\nChanges:\n\n"
+  puts body
+end
diff --git a/clogger.gemspec b/clogger.gemspec
index d2c57a6..665eb1c 100644
--- a/clogger.gemspec
+++ b/clogger.gemspec
@@ -1,4 +1,5 @@
 ENV["VERSION"] or abort "VERSION= must be specified"
+manifest = File.readlines('.manifest').map! { |x| x.chomp! }
 
 Gem::Specification.new do |s|
   s.name = %q{clogger}
@@ -15,8 +16,19 @@ Clogger is Rack middleware for logging HTTP requests.  The log format
 is customizable so you can specify exactly which fields to log.
 }.strip
   s.email = %q{clogger@librelist.com}
-  s.extra_rdoc_files = %w(README History)
-  s.files = File.readlines('.manifest').map! { |x| x.chomp! }
+
+  s.extra_rdoc_files = File.readlines('.document').map! do |x|
+    x.chomp!
+    if File.directory?(x)
+      manifest.grep(%r{\A#{x}/})
+    elsif File.file?(x)
+      x
+    else
+      nil
+    end
+  end.flatten.compact
+
+  s.files = manifest
   s.rdoc_options = [ "-Na",
                      "-t", "Clogger - configurable request logging for Rack"
                    ]