[Rubygems-developers] Why does an install command an update

Hugh Sasse hgs at dmu.ac.uk
Fri Jun 3 14:22:30 EDT 2005


On Fri, 3 Jun 2005, Jim Freeze wrote:

> * Hugh Sasse <hgs at dmu.ac.uk> [2005-06-03 17:21:09 +0100]:
>
>> On Fri, 3 Jun 2005, Jim Weirich wrote:
>>
>>> Another option to reduce bandwidth is to toss the file lists in each of
>>> the downloaded gem specs. [s/\n//; # hgs]
>>
>> You mean the bits like
>>
>>     files:
>>       - lib/cgikit
>>       - lib/cgikit.rb
>>       - lib/cgikit/components
>>       - lib/cgikit/components/CKErrorPage
>>       - lib/cgikit/components/CKErrorPage/CKErrorPage.ckd
>>       - lib/cgikit/components/CKErrorPage/CKErrorPage.html
>>       - lib/cgikit/components/CKErrorPage/CKErrorPage.rb
>>
>> There must be a way to express this more concisely.  Dir doesn't
>> YAML::dump in such a way as to pass the name and the entries, but
>> that can be changed by yaml_properties or something, can't it?.
>> Not sure about backwards compatibility.....
>
> FWIW, I coded up this little snippet:
>
>  -----------
>  files = {"files" =>
>    %w(
>    lib/cgikit
>    lib/cgikit.rb
>    lib/cgikit/components
>    lib/cgikit/components/CKErrorPage
>    lib/cgikit/components/CKErrorPage/CKErrorPage.ckd
>    lib/cgikit/components/CKErrorPage/CKErrorPage.html
>    lib/cgikit/components/CKErrorPage/CKErrorPage.rb
>    )
>  }
>
>  require 'yaml'
>
>  puts files.to_yaml
>  puts files.to_yaml.size
>
>  def optimize_file_list(files)
>    hash = Hash.new { |h,k| h[k] = [] }
>    files.each { |file|
>      dir      = File.dirname(file)
>      filename = File.basename(file)
>      hash[dir] << filename
>    }
>    hash
>  end
>
>  files["files"] = optimize_file_list(files["files"])
>  puts files.to_yaml
>  puts files.to_yaml.size
>  ----------
>
> Running this gives:
>
>  % ruby ftest.rb
>  ---
>  files:
>    - lib/cgikit
>    - lib/cgikit.rb
>    - lib/cgikit/components
>    - lib/cgikit/components/CKErrorPage
>    - lib/cgikit/components/CKErrorPage/CKErrorPage.ckd
>    - lib/cgikit/components/CKErrorPage/CKErrorPage.html
>    - lib/cgikit/components/CKErrorPage/CKErrorPage.rb
>  271
>  ---
>  files:
>    lib/cgikit/components/CKErrorPage:
>      - CKErrorPage.ckd
>      - CKErrorPage.html
>      - CKErrorPage.rb
>    lib/cgikit/components:
>      - CKErrorPage
>    lib/cgikit:
>      - components
>    lib:
>      - cgikit
>      - cgikit.rb
>  229
>
> A slight savings of 15%.
> Not as much as I would have expected.

What about:

diff -u files_in_rubygems.rb.orig files_in_rubygems.rb
--- files_in_rubygems.rb.orig   Fri Jun  3 18:37:50 2005
+++ files_in_rubygems.rb        Fri Jun  3 19:17:02 2005
@@ -12,6 +12,7 @@
    }

    require 'yaml'
+  require 'pathname'

    puts files.to_yaml
    puts files.to_yaml.size
@@ -18,10 +19,26 @@

    def optimize_file_list(files)
      hash = Hash.new { |h,k| h[k] = [] }
+    newhash = nil
      files.each { |file|
-      dir      = File.dirname(file)
-      filename = File.basename(file)
-      hash[dir] << filename
+      path = Pathname.new(file)
+      key = nil
+      # move down the pathname....
+      path.each_filename do |name|
+        if key.nil?
+          key = name
+          hash[key] = nil unless hash.has_key?(key)
+          newhash = hash
+        else
+          if newhash[key]
+            newhash[key][name] ||= nil
+          else
+            newhash[key] = {name => nil}
+          end
+          newhash = newhash[key]
+          key = name
+        end
+      end
      }
      hash
    end
@@ -29,3 +46,5 @@
    files["files"] = optimize_file_list(files["files"])
    puts files.to_yaml
    puts files.to_yaml.size
+
+# vim:set sw=2 et:
brains hgs 144 %>

Which gives:

brains hgs 19 %> ./files_in_rubygems.rb
---
files:
   - lib/cgikit
   - lib/cgikit.rb
   - lib/cgikit/components
   - lib/cgikit/components/CKErrorPage
   - lib/cgikit/components/CKErrorPage/CKErrorPage.ckd
   - lib/cgikit/components/CKErrorPage/CKErrorPage.html
   - lib/cgikit/components/CKErrorPage/CKErrorPage.rb
271
---
files:
   lib:
     cgikit.rb:
     cgikit:
       components:
         CKErrorPage:
           CKErrorPage.ckd:
           CKErrorPage.html:
           CKErrorPage.rb:
174
brains hgs 20 %>

         Hugh


More information about the Rubygems-developers mailing list