github.com/artpar/rclone@v1.67.3/bin/not-in-stable.go (about)

     1  // This shows the commits not yet in the stable branch
     2  package main
     3  
     4  import (
     5  	"bytes"
     6  	"flag"
     7  	"fmt"
     8  	"log"
     9  	"os"
    10  	"os/exec"
    11  	"regexp"
    12  
    13  	"github.com/coreos/go-semver/semver"
    14  )
    15  
    16  // version=$(sed <VERSION -e 's/\.[0-9]+*$//g')
    17  // echo "Checking version ${version}"
    18  // echo
    19  //
    20  // git log --oneline ${version}.0..${version}-stable | cut -c11- | sort > /tmp/in-stable
    21  // git log --oneline ${version}.0..master  | cut -c11- | sort > /tmp/in-master
    22  //
    23  // comm -23 /tmp/in-master /tmp/in-stable
    24  
    25  var logRe = regexp.MustCompile(`^([0-9a-f]{4,}) (.*)$`)
    26  
    27  // run the test passed in with the -run passed in
    28  func readCommits(from, to string) (logMap map[string]string, logs []string) {
    29  	cmd := exec.Command("git", "log", "--oneline", from+".."+to)
    30  	out, err := cmd.Output()
    31  	if err != nil {
    32  		log.Fatalf("failed to run git log %s: %v", from+".."+to, err)
    33  	}
    34  	logMap = map[string]string{}
    35  	logs = []string{}
    36  	for _, line := range bytes.Split(out, []byte{'\n'}) {
    37  		if len(line) == 0 {
    38  			continue
    39  		}
    40  		match := logRe.FindSubmatch(line)
    41  		if match == nil {
    42  			log.Fatalf("failed to parse line: %q", line)
    43  		}
    44  		var hash, logMessage = string(match[1]), string(match[2])
    45  		logMap[logMessage] = hash
    46  		logs = append(logs, logMessage)
    47  	}
    48  	return logMap, logs
    49  }
    50  
    51  func main() {
    52  	flag.Parse()
    53  	args := flag.Args()
    54  	if len(args) != 0 {
    55  		log.Fatalf("Syntax: %s", os.Args[0])
    56  	}
    57  	// v1.54.0
    58  	versionBytes, err := os.ReadFile("VERSION")
    59  	if err != nil {
    60  		log.Fatalf("Failed to read version: %v", err)
    61  	}
    62  	if versionBytes[0] == 'v' {
    63  		versionBytes = versionBytes[1:]
    64  	}
    65  	versionBytes = bytes.TrimSpace(versionBytes)
    66  	semver := semver.New(string(versionBytes))
    67  	stable := fmt.Sprintf("v%d.%d", semver.Major, semver.Minor-1)
    68  	log.Printf("Finding commits in %v not in stable %s", semver, stable)
    69  	masterMap, masterLogs := readCommits(stable+".0", "master")
    70  	stableMap, _ := readCommits(stable+".0", stable+"-stable")
    71  	for _, logMessage := range masterLogs {
    72  		// Commit found in stable already
    73  		if _, found := stableMap[logMessage]; found {
    74  			continue
    75  		}
    76  		hash := masterMap[logMessage]
    77  		fmt.Printf("%s %s\n", hash, logMessage)
    78  	}
    79  }