thunderbird-patch-review

Easy-to-use patch review interface for Thunderbird

Contribute: ~marcc/thunderbird-review-plugin@lists.sr.ht

git clone git://mccd.space/thunderbird-patch-review

gen-fixtures.sh (2160B)

      1 #!/bin/sh
      2 # Regenerate tests/fixtures from a real git-format-patch run. POSIX sh only.
      3 set -eu
      4 
      5 dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
      6 out="$dir/fixtures"
      7 work="${TMPDIR:-/tmp}/patch-review-fixtures.$$"
      8 trap 'rm -rf "$work"' EXIT INT TERM
      9 mkdir -p "$work" "$out"
     10 
     11 repo="$work/repo"
     12 git init -q "$repo"
     13 git -C "$repo" config user.email dev@example.org
     14 git -C "$repo" config user.name "Dev Example"
     15 git -C "$repo" config commit.gpgsign false
     16 
     17 # Base commit (not part of the series).
     18 mkdir -p "$repo/src"
     19 cat > "$repo/src/socket.c" <<'EOF'
     20 #include <stdio.h>
     21 
     22 int open_socket(int fd)
     23 {
     24 	if (fd < 0)
     25 		return -1;
     26 	printf("opening %d\n", fd);
     27 	return fd;
     28 }
     29 
     30 int close_socket(int fd)
     31 {
     32 	printf("closing %d\n", fd);
     33 	return 0;
     34 }
     35 EOF
     36 git -C "$repo" add .
     37 git -C "$repo" commit -q -m "initial import"
     38 
     39 # Patch 1/3: modify two spots in one file (two hunks).
     40 cat > "$repo/src/socket.c" <<'EOF'
     41 #include <stdio.h>
     42 #include <errno.h>
     43 
     44 int open_socket(int fd)
     45 {
     46 	if (fd < 0) {
     47 		errno = EBADF;
     48 		return -1;
     49 	}
     50 	printf("opening %d\n", fd);
     51 	return fd;
     52 }
     53 
     54 int close_socket(int fd)
     55 {
     56 	if (fd < 0)
     57 		return -1;
     58 	printf("closing %d\n", fd);
     59 	return 0;
     60 }
     61 EOF
     62 git -C "$repo" add .
     63 git -C "$repo" commit -q -m "socket: validate file descriptors
     64 
     65 Reject negative descriptors in both open and close paths and
     66 report EBADF like the rest of the subsystem does."
     67 
     68 # Patch 2/3: add a new file.
     69 cat > "$repo/src/log.c" <<'EOF'
     70 #include <stdio.h>
     71 
     72 void log_err(const char *msg)
     73 {
     74 	fprintf(stderr, "error: %s\n", msg);
     75 }
     76 EOF
     77 git -C "$repo" add .
     78 git -C "$repo" commit -q -m "log: add error logging helper"
     79 
     80 # Patch 3/3: binary file.
     81 printf '\211PNG\r\n\032\n\000\001\002\003' > "$repo/icon.bin"
     82 git -C "$repo" add .
     83 git -C "$repo" commit -q -m "assets: add icon"
     84 
     85 git -C "$repo" format-patch -q --cover-letter -v2 -3 -o "$work/patches"
     86 
     87 # Fixtures hold the email *body* (what messages.getFull yields): strip the
     88 # RFC822 headers, i.e. everything through the first blank line.
     89 n=0
     90 for patch in "$work/patches"/*; do
     91     case $patch in
     92         *0000*) name=cover ;;
     93         *) n=$((n + 1)); name="patch$n" ;;
     94     esac
     95     sed '1,/^$/d' "$patch" > "$out/$name.body"
     96 done
     97 
     98 ls "$out"