bugspot で android の bug prediction

# Overview

Ubuntu 12.04環境下や14.04環境下で、bugspotsを動かそうとした時にハマったので、メモ。
一部、patchして動かしました。。。。
(下書きにしておいたままだったので、せっかくなのでpostしておきます...)

# depended modules

```
$ sudo apt-get install ruby-dev
$ sudo apt-get install cmake
```

# bugspots

```
$ sudo gem install bugspots
```

# patch for bugspots

```/var/lib/gems/1.9.1/gems/bugspots-0.2.1/lib/bugspots/scanner.rb
  def self.scan(repo, branch = "master", depth = 500, regex = nil)
..snip..
    repo = Rugged::Repository.new(repo)
-    unless repo.branches.each_name(:local).sort.find { |b| b == branch }
-      raise ArgumentError, "no such branch in the repo: #{branch}"
-    end
+    head = nil
+    repo.branches.each_name do |a|
+      if a == branch then
+        head = repo.branches[a].name
+      end
+    end
+    if head == nil then
+      puts "ERROR: no such branch in the repo: #{branch}"
+      puts ""
+      puts "Available branches :"
+      repo.branches.each_name do |a|
+	puts a
+      end
+      exit(-1)
+    end

    walker = Rugged::Walker.new(repo)
    walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
-   walker.push(repo.branches[branch].target)
+   walker.push(repo.branches[head].target)
    walker.each do |commit|
+     row = commit.message.split("\n")
-     if commit.message =~ regex
+     if row[0].strip =~ regex
```

# 実行結果

```
~/work/android-6.0.0_r26/system/vold$ bugspots . -r '^(?!am |[Mm]erge ).*[fF]ix' -b aosp/master
Scanning . repo
	Found 62 bugfix commits, with 32 hotspots:

	Fixes:
		- vold2: Fix a mb -> sector conversion refactor bug
		- vold2: Fix issue with destroying / unmounting asec
		- vold: Fix share status argument off by one
		- vold: Fix a few bugs
		- vold: Fix format argument bug
		- vold: Fix devmapper/ptmx fd leak, and give asec unmount more time
		- vold: fix infinite loop when failing to unmount a busy container in unmountVolume()
		- vold: Fix uninitialized mountpoint bug
		- vold: Bugfixes & cleanups
		- vold: Fix argument validation for volume commands
		- Fix loop_info/loop_info64 impedance mismatch
		- Fixes for devices with internal FAT file system:
		- More fixes for internal FAT partitions:
		- vold: fix an offset one bug that makes partition 4 unusable
		- fix double closing file descriptors
		- Fix to display the proper percentage complete during encryption.
		- Fix cryptfs to work with a raw block device for key storage
		- Fix to not return a bogus decryption error when a device is not encrypted.
		- Fix vdc to add sequence number for NativeConectorDaemon
		- Fix truncation of ASEC ids
		- Fix truncation of ASEC ids
		- Fix a typo in cryptfs.c
		- Fix encryption on certain devices
		- Fix encryption on certain devices
		- Another fix for encryption
		- Fix vold's use of readdir_r(3).
		- Fix issue #7503920: Log spew from vold
		- Fix calls to logwrap
		- Fix compiling warnings
		- Fix a typo in a comment
		- Fix spelling.
		- vold: fix potential socket leak
		- Fix crash in vold
		- DO NOT MERGE. Fix crash in vold
		- vold: fix warnings for 64-bit
		- vold: fix errors inside ALOGV
		- Fix setfield/getfield
		- vdc: fix segfault
		- Fix encryption on Nakasi
		- Fixed bugs with ASEC filesystem.
		- Fix encryption on Nakasi
		- Fix vold %lld to PRId64.
		- Fix an accidental PRId64 to PRIx64.
		- Fix failure erasing SD in Factory reset
		- fstrim: fix typo in log message for FIDTRIM case
		- Fix Vold to properly handle full-disk file systems
		- Fix Shamus bricked by encryption upgrade
		- Fix encrypt-and-wipe
		- Fix error in clocks leading to devices staying unlocked
		- Fix alignment of buffer used for dm_ioctl.
		- Remove unused local variable to fix the build
		- Fix missing #includes in system/vold.
		- Fix memory leak in upgrade_crypt_ftr
		- crytpfs: fix clobbering of crypto info on keymaster failure
		- Fixed type mismatch for ioctl(BLKGETSIZE)
		- Fix 64 bit builds.
		- Fix destroy ordering bug; add debug flag.
		- Fix signed issue with hex conversion.
		- Fix problem that reading/writing crypto footers wasn't identity
		- DO NOT MERGE Fix problem that reading/writing crypto footers wasn't identity
		- Fix erroneous comment in secdiscard.cpp, plus style fixes.
		- Fix ioctl parameter

	Hotspots:
		1.3139 - cryptfs.c
		0.6781 - Utils.cpp
		0.4932 - Ext4Crypt.cpp
		0.4142 - Disk.cpp
		0.3171 - VolumeManager.cpp
		0.3099 - secdiscard.cpp
		0.2164 - fstrim.c
		0.2139 - main.cpp
		0.2059 - Fat.cpp
		0.2026 - VoldUtil.h
		0.2000 - Loop.cpp
		0.2000 - Loop.h
		0.2000 - VoldUtil.c
		0.1250 - DirectVolume.cpp
		0.1240 - Android.mk
		0.0660 - DirectVolume.h
		0.0495 - Volume.cpp
		0.0494 - Ext4.cpp
		0.0435 - Ext4.h
		0.0383 - vdc.c
		0.0142 - NetlinkManager.cpp
		0.0053 - CommandListener.cpp
		0.0033 - Devmapper.cpp
		0.0001 - logwrapper.c
		0.0001 - Volume.h
		0.0000 - CommandListener.h
		0.0000 - Devmapper.h
		0.0000 - VolumeManager.h
		0.0000 - hash.h
		0.0000 - md5.c
		0.0000 - md5.h
		0.0000 - ProcessKiller.c
```