Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of git://github.com/robinluckey/ohloh_scm

  • Loading branch information...
commit c39077b6d58539c0f355df02642e7b656a15aad6 2 parents f5da98d + e9598d7
authored February 09, 2009

Showing 20 changed files with 45 additions and 5 deletions. Show diff stats Hide diff stats

  1. 2  lib/scm/adapters/bzr/cat_file.rb
  2. 25  lib/scm/adapters/bzr/commits.rb
  3. 3  test/repositories/bzr_with_subdirectories/.bzr/README
  4. 1  test/repositories/bzr_with_subdirectories/.bzr/branch-format
  5. 0  test/repositories/bzr_with_subdirectories/.bzr/branch/branch.conf
  6. 1  test/repositories/bzr_with_subdirectories/.bzr/branch/format
  7. 1  test/repositories/bzr_with_subdirectories/.bzr/branch/last-revision
  8. 0  test/repositories/bzr_with_subdirectories/.bzr/branch/tags
  9. 1  test/repositories/bzr_with_subdirectories/.bzr/checkout/conflicts
  10. BIN  test/repositories/bzr_with_subdirectories/.bzr/checkout/dirstate
  11. 1  test/repositories/bzr_with_subdirectories/.bzr/checkout/format
  12. 1  test/repositories/bzr_with_subdirectories/.bzr/repository/format
  13. BIN  test/repositories/bzr_with_subdirectories/.bzr/repository/indices/6eb92b11d9f811881dd08e0ca71e136d.iix
  14. BIN  test/repositories/bzr_with_subdirectories/.bzr/repository/indices/6eb92b11d9f811881dd08e0ca71e136d.rix
  15. 5  test/repositories/bzr_with_subdirectories/.bzr/repository/indices/6eb92b11d9f811881dd08e0ca71e136d.six
  16. BIN  test/repositories/bzr_with_subdirectories/.bzr/repository/indices/6eb92b11d9f811881dd08e0ca71e136d.tix
  17. BIN  test/repositories/bzr_with_subdirectories/.bzr/repository/pack-names
  18. BIN  test/repositories/bzr_with_subdirectories/.bzr/repository/packs/6eb92b11d9f811881dd08e0ca71e136d.pack
  19. 0  test/repositories/bzr_with_subdirectories/foo/helloworld.c
  20. 9  test/unit/bzr_commits_test.rb
2  lib/scm/adapters/bzr/cat_file.rb
@@ -10,7 +10,7 @@ def cat_file_parent(commit, diff)
10 10
 		end
11 11
 
12 12
 		def cat(revision, path)
13  
-			out, err = run_with_err("cd '#{url}' && bzr cat -r #{to_rev_param(revision)} #{escape(path)}")
  13
+			out, err = run_with_err("cd '#{url}' && bzr cat --name-from-revision -r #{to_rev_param(revision)} #{escape(path)}")
14 14
 			return nil if err =~ / is not present in revision /
15 15
 			raise RuntimeError.new(err) unless err.to_s == ''
16 16
 			out
25  lib/scm/adapters/bzr/commits.rb
@@ -46,10 +46,10 @@ def verbose_commit(token)
46 46
 		# This is designed to prevent excessive RAM usage when we
47 47
 		# encounter a massive repository.  Only a single commit is ever
48 48
 		# held in memory at once.
49  
-		def each_commit(since=0)
  49
+		def each_commit(since=nil)
50 50
 			open_log_file(since) do |io|
51 51
 				Scm::Parsers::BzrParser.parse(io) do |commit|
52  
-					yield remove_directories(commit) if block_given? && commit.token != since
  52
+					yield remove_dupes(remove_directories(commit)) if block_given? && commit.token != since
53 53
 				end
54 54
 			end
55 55
 		end
@@ -61,6 +61,23 @@ def remove_directories(commit)
61 61
 			commit
62 62
 		end
63 63
 
  64
+		# Bazaar may report that a file was both removed and added in the same commit.
  65
+		# We're going to consider this to be simply a modification of the file.
  66
+		# So we'll remove the 'D' action, and replace the 'A' with an 'M' action.
  67
+		def remove_dupes(commit)
  68
+			if commit.diffs
  69
+				dupes = commit.diffs.collect do |d|
  70
+					d if d.action == 'D' && commit.diffs.select { |x| x.action == 'A' and x.path == d.path }.any?
  71
+				end.compact
  72
+				dupes.each do |dupe|
  73
+					commit.diffs.delete_if { |del| del.action == 'D' and del.path == dupe.path }
  74
+					commit.diffs.each { |add| add.action = 'M' if add.path == dupe.path }
  75
+				end
  76
+			end
  77
+			commit
  78
+		end
  79
+
  80
+
64 81
 		# Not used by Ohloh proper, but handy for debugging and testing
65 82
 		def log(since=nil)
66 83
 			run "#{rev_list_command(since)} -v"
@@ -71,14 +88,14 @@ def log(since=nil)
71 88
 		# +since+. However, bzr doesn't work that way; it returns
72 89
 		# everything after and INCLUDING +since+. Therefore, consumers
73 90
 		# of this file should check for and reject the duplicate commit.
74  
-		def open_log_file(since=0)
  91
+		def open_log_file(since=nil)
75 92
 			begin
76 93
 				if since == head_token # There are no new commits
77 94
 					# As a time optimization, just create an empty
78 95
 					# file rather than fetch a log we know will be empty.
79 96
 					File.open(log_filename, 'w') { }
80 97
 				else
81  
-					run "#{rev_list_command} -v > #{log_filename}"
  98
+					run "#{rev_list_command(since)} -v > #{log_filename}"
82 99
 				end
83 100
 				File.open(log_filename, 'r') { |io| yield io }
84 101
 			ensure
3  test/repositories/bzr_with_subdirectories/.bzr/README
... ...
@@ -0,0 +1,3 @@
  1
+This is a Bazaar control directory.
  2
+Do not change any files in this directory.
  3
+See http://bazaar-vcs.org/ for more information about Bazaar.
1  test/repositories/bzr_with_subdirectories/.bzr/branch-format
... ...
@@ -0,0 +1 @@
  1
+Bazaar-NG meta directory, format 1
0  test/repositories/bzr_with_subdirectories/.bzr/branch/branch.conf
No changes.
1  test/repositories/bzr_with_subdirectories/.bzr/branch/format
... ...
@@ -0,0 +1 @@
  1
+Bazaar Branch Format 6 (bzr 0.15)
1  test/repositories/bzr_with_subdirectories/.bzr/branch/last-revision
... ...
@@ -0,0 +1 @@
  1
+1 test@example.com-20090206231214-d211b455ad50q6eh
0  test/repositories/bzr_with_subdirectories/.bzr/branch/tags
No changes.
1  test/repositories/bzr_with_subdirectories/.bzr/checkout/conflicts
... ...
@@ -0,0 +1 @@
  1
+BZR conflict list format 1
BIN  test/repositories/bzr_with_subdirectories/.bzr/checkout/dirstate
Binary file not shown
1  test/repositories/bzr_with_subdirectories/.bzr/checkout/format
... ...
@@ -0,0 +1 @@
  1
+Bazaar Working Tree Format 4 (bzr 0.15)
1  test/repositories/bzr_with_subdirectories/.bzr/repository/format
... ...
@@ -0,0 +1 @@
  1
+Bazaar pack repository format 1 (needs bzr 0.92)
BIN  test/repositories/bzr_with_subdirectories/.bzr/repository/indices/6eb92b11d9f811881dd08e0ca71e136d.iix
Binary file not shown
BIN  test/repositories/bzr_with_subdirectories/.bzr/repository/indices/6eb92b11d9f811881dd08e0ca71e136d.rix
Binary file not shown
5  test/repositories/bzr_with_subdirectories/.bzr/repository/indices/6eb92b11d9f811881dd08e0ca71e136d.six
... ...
@@ -0,0 +1,5 @@
  1
+Bazaar Graph Index 1
  2
+node_ref_lists=0
  3
+key_elements=1
  4
+len=0
  5
+
BIN  test/repositories/bzr_with_subdirectories/.bzr/repository/indices/6eb92b11d9f811881dd08e0ca71e136d.tix
Binary file not shown
BIN  test/repositories/bzr_with_subdirectories/.bzr/repository/pack-names
Binary file not shown
BIN  test/repositories/bzr_with_subdirectories/.bzr/repository/packs/6eb92b11d9f811881dd08e0ca71e136d.pack
Binary file not shown
0  test/repositories/bzr_with_subdirectories/foo/helloworld.c
No changes.
9  test/unit/bzr_commits_test.rb
@@ -63,6 +63,15 @@ def test_each_commit
63 63
 			end
64 64
 		end
65 65
 
  66
+		def test_remove_dupes_add_remove
  67
+			bzr = BzrAdapter.new
  68
+			c = Scm::Commit.new(:diffs => [ Scm::Diff.new(:action => "A", :path => "foo"),
  69
+																			Scm::Diff.new(:action => "D", :path => "foo") ])
  70
+			bzr.remove_dupes(c)
  71
+			assert_equal 1, c.diffs.size
  72
+			assert_equal 'M', c.diffs.first.action
  73
+		end
  74
+
66 75
 		# This bzr repository contains the following tree structure
67 76
 		#    /foo/
68 77
 		#    /foo/helloworld.c

0 notes on commit c39077b

Please sign in to comment.
Something went wrong with that request. Please try again.