Pages

Monday, 4 August 2014

Differences between git branches

The problem

Given I have two branches, A and B within a git repository, I would like to come up with two sets of changes: (A-B) and (B-A). So I would like to find all the commits that are in A but not in B, and vice versa.

Introducing the same change to two branches

Let's set up a git repository to play with. As a first step, I create an initial commit, with only one file in it, a simple greeting:
$ git init
$ echo "hello there" > hello.txt
$ git add hello.txt
$ git commit -m "Initial commit"
And now, make the branching, and introduce the same change to each of those branches:
$ git checkout -b A
$ echo "blah" > blah.txt
$ git add blah.txt
$ git commit -m "Added blah"
And see the B branch:
$ git checkout master -b B
$ echo "blah" > blah.txt
$ git add blah.txt
$ git commit -m "Added blah"
See if git is smart enough to find out that the two changes are the same:
$ git log A..B --oneline | wc -l
1
Of course, they are not the same, they are copies of the other. So let's see the other command, called git-cherry:
$ git cherry A B
This shows only one line, with a minus sign. From the documentation of git cherry:
git cherry [-v] [<upstream> [<head> [<limit>]]]

       Every commit that doesn’t exist in the <upstream> branch has its id (sha1) reported,
       prefixed by a symbol. The ones that have equivalent change already in the <upstream>
       branch are prefixed with a minus (-) sign, and those that only exist in the <head>
       branch are prefixed with a plus (+) symbol:

Saturday, 21 June 2014

SSD - Bytes written

I Have an Intel 520 SSD. I can use smartmontools to ask how much bytes have been written to it:
sudo ./smartctl -q noserial -i -l devstat,0 -l devstat /dev/sda
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.2.0-32-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Intel 520 Series SSDs
Device Model:     INTEL SSDSC2CW240A3
Firmware Version: 400i
User Capacity:    240,057,409,536 bytes [240 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    Solid State Device
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2 T13/2015-D revision 3
SATA Version is:  SATA 3.0, 3.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Sat Jun 21 08:42:06 2014 BST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

Device Statistics (GP Log 0x04) supported pages
Page Description
  0  List of supported log pages
  1  General Statistics
  4  General Errors Statistics
  6  Transport Statistics
  7  Solid State Device Statistics

Device Statistics (GP Log 0x04)
Page Offset Size         Value  Description
  1  =====  =                =  == General Statistics (rev 2) ==
  1  0x008  4             1129  Lifetime Power-On Resets
  1  0x010  4             8660  Power-on Hours
  1  0x018  6       5401949881  Logical Sectors Written
  1  0x028  6       5794864033  Logical Sectors Read
  4  =====  =                =  == General Errors Statistics (rev 1) ==
  4  0x008  4                0  Number of Reported Uncorrectable Errors
  4  0x010  4             9232  Resets Between Cmd Acceptance and Completion
  6  =====  =                =  == Transport Statistics (rev 1) ==
  6  0x008  4             9232  Number of Hardware Resets
  6  0x010  4             4085  Number of ASR Events
  6  0x018  4                0  Number of Interface CRC Errors
  7  =====  =                =  == Solid State Device Statistics (rev 1) ==
  7  0x008  1              255  Percentage Used Endurance Indicator

Monday, 16 June 2014

Recording terminal sessions

During the weekend I was experimenting with some tools to record terminal sessions. The result of the hacking:
  • ttyrec
  • ttygif

Tuesday, 27 May 2014

Debootstrap as a single user

fakeroot -s fakechroot.save fakechroot debootstrap --variant=fakechroot --components=main,universe precise precise
fakeroot -i fakechroot.save -s fakechroot.save fakechroot chroot precise apt-get update
fakeroot -i fakechroot.save -s fakechroot.save fakechroot chroot precise apt-get -qy install git

Sunday, 18 May 2014

Ubuntu installer - Unmount partitions that are in use?

I am working on the unattended-iso project, and seeing this message:

for the bots and search engines

The installer has detected that the following disks have mounted
partitions:

/dev/sda

Do you want the installer to try to unmount the partitions on these
disks before continuing? If you leave them mounted, you will not be
able to create, delete, or resize partitions on these disks, but you
may be able to install to existing partitions there.

Unmount partitions that are in use?

It happens whenever you already have a filesystem on say sda1. Workaround:

d-i preseed/early_command string umount /media || true

Friday, 16 May 2014

Sherlocking Mock based builds

Jenkins is frozen, waiting for something. One useful link is to look at ${JENKINS_URL}/threadDump. That reveals which thread is doing what.

Mine is stuck like this:

waiting for hudson.remoting.Channel@f7f725

Okay, I logged onto the other machine, and yes, it still has an open ssh connection to the guest. So log on to the guest, and look at the open files:

sudo lsof -i 4

Okay, I now know some PIDs: 775 and 790

Let's see the file descriptors:

sudo ls -l /proc/790/fd/

lrwx------ 1 root root 64 May 16 19:51 0 -> /dev/null
lrwx------ 1 root root 64 May 16 19:51 1 -> /dev/null
lr-x------ 1 root root 64 May 16 19:51 10 -> pipe:[7800]
lrwx------ 1 root root 64 May 16 19:51 2 -> /dev/null
lrwx------ 1 root root 64 May 16 19:51 3 -> socket:[7744]
lrwx------ 1 root root 64 May 16 19:51 4 -> socket:[7781]
lrwx------ 1 root root 64 May 16 19:51 5 -> socket:[7791]
lr-x------ 1 root root 64 May 16 19:51 6 -> pipe:[7798]
l-wx------ 1 root root 64 May 16 19:51 7 -> pipe:[7798]

Nice, I guess that pipe is the bad guy, but how do I know, what is that?

sudo lsof  | grep 7800

sshd        790         ubuntu   10r     FIFO                0,8      0t0       7800 pipe
udevd     30043           root    4w     FIFO                0,8      0t0       7800 pipe

All right, that means that I know a new PID...

sudo ls -l /proc/30043/fd/

Okay, that's nice, but what was the command line?

sudo cat /proc/30043/cmdline
udevd --daemon

Nice, now I need to look at mock and udevd.

Sunday, 11 May 2014

Handwriting to SVG: potrace and image magick

#!/bin/bash
set -eux

INPUT="$1"
OUTPUT="$2"

WORKDIR="$(mktemp -d)"
convert \
    -format bmp -colorspace gray -normalize \
    -threshold 90% "$INPUT" "$WORKDIR/bitmap.bmp"

potrace -b svg -r 300 -t 5 -o "$OUTPUT" "$WORKDIR/bitmap.bmp"