Commits

seydar  committed d648cc0

work to patch.rb

  • Participants
  • Parent commits e46b8a6

Comments (0)

Files changed (9)

 The Amp Commandments:
     1. Thou shalt not useth the "for...in" syntax.
-    2. Thou shalt useth only but 80 columns, for those who useth the lord's
+    2. Thou shalt useth only but 80 columns, for those who useth the elden
        editors, vim and emacs.
     3. Thou shalt preface thine variables with _ only when thou needest,
        lest ye face judgement for this most grave sin.
        it. Thou shalt leave one blank comment line between thine comment info
        and thine yard information.
     10. Thou shalt make great and grand use of the yard extension. It is good.
-    11. Name thine motherfucking variables motherfucking descriptively.
+    11. Name thine motherfucking variables motherfucking descriptively.
+	12. For thine ranges, thou shalt place but 1 space on either side of the
+		ellipses.

File lib/amp/commands/command_support.rb

       if !message && logfile
         begin
           message = logfile == '-' ? $stdin.read : File.read(logfile)
-        rescue => e
+        rescue IOError => e
           raise abort("can't read commit message '#{logfile}': #{e}")
         end
       end

File lib/amp/dependencies/zip/ioextras.rb

 
   CHUNK_SIZE = 32768
 
-  RANGE_ALL = 0..-1
+  RANGE_ALL = 0 .. -1
 
   def self.copy_stream(ostream, istream)
     s = ''

File lib/amp/dependencies/zip/zip.rb

       end
       return value_when_finished if @outputBuffer.length==0 && input_finished?
       endIndex= numberOfBytes==nil ? @outputBuffer.length : numberOfBytes
-      return @outputBuffer.slice!(0...endIndex)
+      return @outputBuffer.slice!(0 ... endIndex)
     end
     
     def produce_input

File lib/amp/encoding/base85.rb

         olen += 1 if olen > 0
         olen += l / 4 * 5
         
-        out[0..olen-1]
+        out[0 .. olen-1]
       end
       
       ##
         out = []
         i = 0
         while i < text.size
-          chunk = text[i..i+4]
+          chunk = text[i .. i+4]
           acc = 0
           chunk.size.times do |j|
             acc = acc * 85 + B85dec[chunk[j].chr]
         
         out = out.pack("N#{out.size}")
         if cl > 0
-          out = out[0..(-1 * (5-cl) - 1)]
+          out = out[0 .. (-1 * (5-cl) - 1)]
         end
         out
       end

File lib/amp/encoding/binary_diff.rb

           # Since the array byte_offsets[] contains the actual byte offsets of each line,
           # our diff is stored as [start_a_text_to_replace, end_a_text_to_replace,
           # size_of_replacement_text, replacement_text]. 
-          s = b[lb..(bm-1)].join unless lb == bm && lb == 0
-          s = ""                 if     lb == bm && lb == 0
+          s = b[lb .. (bm-1)].join unless lb == bm && lb == 0
+          s = ""                   if     lb == bm && lb == 0
           bin << [byte_offsets[la], byte_offsets[am], s.size].pack("NNN") + s if am > la || s.any?
           la = am + size
           lb = bm + size

File lib/amp/encoding/mercurial_diff.rb

               l[0] = "Moved file from #{fn1.cyan} to #{fn2.cyan}"
             end
           else
-            l[0] = "#{l[0][0..-3]}#{date_tag(ad,fn1,true,options)}"
-            l[1] = "#{l[1][0..-3]}#{date_tag(bd,fn1,true,options)}"
+            l[0] = "#{l[0][0 .. -3]}#{date_tag(ad,fn1,true,options)}"
+            l[1] = "#{l[1][0 .. -3]}#{date_tag(bd,fn1,true,options)}"
           end
         end
         
           (astart - 1).downto(0) do |x|
             t = l1[x].rstrip
             if t =~ /\w/
-              func = ' ' + t[0..39]
+              func = ' ' + t[0 .. 39]
               break
             end
           end

File lib/amp/encoding/patch.rb

+# I have seen few files so poorly organized such as patch.py
+# What. The. Fuck. This is going to take so long to make.
+module Amp
+  module Patch
+    
+    class PatchError < StandardError; end
+    class NoHunkError < PatchError; end
+    
+    class Patch
+      
+      ##
+      # The filename of the patch
+      attr_accessor :file_name
+      
+      ##
+      # The opener used to open the patch
+      attr_accessor :opener
+      
+      ##
+      # @todo - add comment
+      attr_accessor :lines
+      
+      ##
+      # does the patch exist? @todo - make this accurate
+      attr_accessor :exists
+      
+      ##
+      # Is the file in the filesystem
+      attr_accessor :missing
+      
+      ##
+      # @todo - add comment
+      attr_accessor :hash
+      
+      ##
+      # Is this dirty and does it need to be resynced with something?
+      attr_accessor :dirty
+      alias_method  :dirty?, :dirty
+      
+      ##
+      # @todo - add comment
+      attr_accessor :offset
+      
+      ##
+      # has this been printed? (duh)
+      attr_accessor :printed
+      alias_method  :printed?, :printed
+      
+      ##
+      # @todo - add comment
+      attr_accessor :hunks
+      
+      def initialize(file_name, opener, missing=false)
+        @file_name = file_name
+        @opener    = opener
+        @lines     = []
+        @exists    = false
+        
+        ##
+        # If the patch is in the filesystem
+        # then we should read it and accurately set its existence
+        unless @missing = missing
+          begin
+            readlines!
+            @exists = true
+          rescue IOError
+          end
+        else
+          UI::warn "unable to find '#{@file_name}' for patching"
+        end
+        
+        @hash     = {}
+        @dirty    = false
+        @offset   = 0
+        @rejected = []
+        @printed  = false
+        @hunks    = 0
+      end
+      
+      ##
+      # Loads up the patch info from +@file_name+
+      # into +@lines+
+      def readlines!
+        @opener.open @file_name do |f|
+          @lines = f.readlines
+        end
+      end
+      
+      ##
+      # Write +linez+ to +fname+ as a patch.
+      # 
+      # @param [String] fname the filename to write to
+      # @param [Array<String>] linez an array of the lines to write
+      def writelines!(fname, linez)
+        @opener.open fname, 'w' do |f|
+          f.write linez.join("\n")
+        end
+      end
+      
+      ##
+      # Mysteriously and safely disappear...
+      #
+      # @return [Boolean] success marker
+      def unlink; File.safe_unlink @file_name; end
+      
+      ##
+      # Print out the patch to STDOUT, or STDERR if +warn+ is true.
+      # 
+      # @param [Boolean] warn should we be printing to STDERR?
+      def print(warn=false)
+        return if printed? # no need to print it twice
+        
+        @printed = true if warn
+        message  = "patching file #{@file_name}"
+        warn ? UI::warn message : UI::note message
+      end
+      
+      ##
+      # From the Python: looks through the hash and finds candidate lines. The
+      # result is a list of line numbers sorted based on distance from linenum.
+      # 
+      # I wish I knew how to make sense of that sentence.
+      # 
+      # @todo Look into removing an unnecessary `- number`.
+      # @param  [String] line
+      # @param  [Integer] number the line number
+      # @return [Array] the lines that matchish.
+      def find_lines(line, number)
+        return [] unless @hash.include? line
+        
+        # really, we're just getting the lines and sorting them
+        # is the `- number` even necessary?
+        @hash[line].sort {|a, b| (a - number).abs <=> (b - number).abs }
+      end
+      
+      ##
+      # I have no clue what song I am listening to but it is SOOOOO GOOD!!!!!!!!
+      # "This time baby, I'll be bullet proof"
+      # If I had working internet now, I'd be googling the lyrics.
+      # 
+      # Oh right, the method. I don't know what this does... YET
+      # 
+      # @todo Figure out what this does
+      def hash_lines
+        @hash = Hash.new {|h, k| h[k] = [] }
+        (0 ... @lines.size).each do |x|
+          s = @lines[x]
+          @hash[s] << x
+        end
+      end
+      
+      ##
+      # our rejects are a little different from patch(1).  This always
+      # creates rejects in the same form as the original patch.  A file
+      # header is inserted so that you can run the reject through patch again
+      # without having to type the filename.
+      def write_rejects
+        return if @rejects.empty?
+        fname = @file_name + '.rej'
+        
+        UI::warn("#{@rejects.size} out of #{@hunks} hunks FAILED --" +
+                 "saving rejects to file #{fname}")
+        
+        # i have never written code as horrid as this
+        # please help me
+        lz = []
+        base = File.dirname @file_name
+        lz << "--- #{base}\n+++ #{base}\n"
+        @rejects.each do |r|
+          r.hunk.each do |l|
+            lz << l
+            lz << "\n\ No newline at end of file\n" if l.last != "\n"
+          end
+        end
+        
+        write_lines fname, lz
+      end
+      
+    end
+    
+    class PatchMeta
+    end
+    
+    class Hunk
+    end
+    
+    class GitHunk
+    end
+    
+    class BinaryHunk
+    end
+    
+    class SymLinkHunk
+    end
+    
+    class LineReader
+    end
+    
+  end
+end

File lib/amp/repository/repositories/local_repository.rb

         #
         # unbundle assumes local user cannot lock remote repo (new ssh
         # servers, http servers).
-
         if remote_repo.capable? "unbundle"
           push_unbundle remote_repo, opts
         else