#!/bin/bash
#
# Known issues:
# - only deals with single-line output from 'p4 where' (so no complex mappings)
#

set -e

DIFF_CMD="diff -Nau"

CHANGELIST_ARG=""
if [ -n "$1" ]; then
    CHANGELIST_ARG="-c $1"
fi

{
    while read -r entry
    do
        # caveat, fails for files with # in them
        regexp='^(.*)#[0-9]+ - '
        depot_path=`echo "${entry}" | gawk 'match($0, /^(.*)#[0-9]+ - /, matches) { print matches[1] }'`
        local_path=`p4 where "${depot_path}" | cut -d\  -f 3`
        rev=`echo "${entry}" | gawk 'match($0, /^.*#([0-9]+) - /, matches) { print matches[1] }'`
        change=`echo "${entry}" | gawk 'match($0, /^.*#[0-9]+ - ([^ ]+)/, matches) { print matches[1] }'`

        if [ -n "${DEBUG}" ]; then
            echo "==== $entry"
            echo "[${depot_path}]"
            echo "[${local_path}]"
            echo "[${rev}]"
            echo "[${change}]"
        fi

        case ${change} in
            add)
                echo "==== ${depot_path}#${rev} - ${local_path}" ====
                ${DIFF_CMD} "/tmp/tmp.$$.new.file" "${local_path}" && true
                ;;
            delete)
                echo "==== ${depot_path}#${rev} - ${local_path}" ====
                p4 print "${depot_path}#${rev}" > /tmp/tmp.$$.old
                ${DIFF_CMD} "/tmp/tmp.$$.old" "${local_path}" && true
                ;;
            edit)
                P4DIFF="${DIFF_CMD}" p4 diff "${local_path}"
                ;;
            *)
                echo "Unsupported change type: ${change}"
                ;;
        esac
    done < <(p4 opened ${CHANGELIST_ARG})
}| colordiff | more
-- KoenMartens - 29 Feb 2020
Topic revision: r1 - 29 Feb 2020, KoenMartens
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback