<commit_before>/*-------------------------------------------------------------------------
 *
 * trigfuncs.c
 *    Builtin functions for useful trigger support.
 *
 *
 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * $PostgreSQL: pgsql/src/backend/utils/adt/trigfuncs.c,v 1.1 2008/11/03 20:17:20 adunstan Exp $
 *
 *-------------------------------------------------------------------------
 */



#include "postgres.h"
#include "commands/trigger.h"
#include "access/htup.h"

/*
 * suppress_redundant_updates_trigger
 *
 * This trigger function will inhibit an update from being done
 * if the OLD and NEW records are identical.
 *
 */

Datum
suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
{
    TriggerData *trigdata = (TriggerData *) fcinfo->context;
    HeapTuple   newtuple, oldtuple, rettuple;
	HeapTupleHeader newheader, oldheader;

    /* make sure it's called as a trigger */
    if (!CALLED_AS_TRIGGER(fcinfo))
        elog(ERROR, (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
					 errmsg("suppress_redundant_updates_trigger: must be called as trigger")));
	
    /* and that it's called on update */
    if (! TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
        ereport(ERROR, (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
						errmsg( "suppress_redundant_updates_trigger: may only be called on update")));

    /* and that it's called before update */
    if (! TRIGGER_FIRED_BEFORE(trigdata->tg_event))
        ereport(ERROR, (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
						errmsg( "suppress_redundant_updates_trigger: may only be called before update")));

    /* and that it's called for each row */
    if (! TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
        ereport(ERROR, (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
						errmsg( "suppress_redundant_updates_trigger: may only be called for each row")));

	/* get tuple data, set default return */
	rettuple  = newtuple = trigdata->tg_newtuple;
	oldtuple = trigdata->tg_trigtuple;

	newheader = newtuple->t_data;
	oldheader = oldtuple->t_data;

    if (newtuple->t_len == oldtuple->t_len &&
		newheader->t_hoff == oldheader->t_hoff &&
		(HeapTupleHeaderGetNatts(newheader) == 
		 HeapTupleHeaderGetNatts(oldheader) ) &&
		((newheader->t_infomask & ~HEAP_XACT_MASK) == 
		 (oldheader->t_infomask & ~HEAP_XACT_MASK) )&&
		memcmp(((char *)newheader) + offsetof(HeapTupleHeaderData, t_bits),
			   ((char *)oldheader) + offsetof(HeapTupleHeaderData, t_bits),
			   newtuple->t_len - offsetof(HeapTupleHeaderData, t_bits)) == 0)
	{
		rettuple = NULL;
	}
	
    return PointerGetDatum(rettuple);
}
<commit_msg>Fix compiler warnings (including a seriously bogus elog call); minor code beautification.<commit_after>/*-------------------------------------------------------------------------
 *
 * trigfuncs.c
 *    Builtin functions for useful trigger support.
 *
 *
 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * $PostgreSQL: pgsql/src/backend/utils/adt/trigfuncs.c,v 1.2 2008/11/04 00:29:39 tgl Exp $
 *
 *-------------------------------------------------------------------------
 */
#include "postgres.h"

#include "access/htup.h"
#include "commands/trigger.h"
#include "utils/builtins.h"


/*
 * suppress_redundant_updates_trigger
 *
 * This trigger function will inhibit an update from being done
 * if the OLD and NEW records are identical.
 */
Datum
suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
{
    TriggerData *trigdata = (TriggerData *) fcinfo->context;
    HeapTuple   newtuple, oldtuple, rettuple;
	HeapTupleHeader newheader, oldheader;

    /* make sure it's called as a trigger */
    if (!CALLED_AS_TRIGGER(fcinfo))
        ereport(ERROR,
				(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
				 errmsg("suppress_redundant_updates_trigger: must be called as trigger")));
	
    /* and that it's called on update */
    if (! TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
        ereport(ERROR,
				(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
				 errmsg("suppress_redundant_updates_trigger: must be called on update")));

    /* and that it's called before update */
    if (! TRIGGER_FIRED_BEFORE(trigdata->tg_event))
        ereport(ERROR,
				(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
				 errmsg("suppress_redundant_updates_trigger: must be called before update")));

    /* and that it's called for each row */
    if (! TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
        ereport(ERROR,
				(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
				 errmsg("suppress_redundant_updates_trigger: must be called for each row")));

	/* get tuple data, set default result */
	rettuple  = newtuple = trigdata->tg_newtuple;
	oldtuple = trigdata->tg_trigtuple;

	newheader = newtuple->t_data;
	oldheader = oldtuple->t_data;

	/* if the tuple payload is the same ... */
    if (newtuple->t_len == oldtuple->t_len &&
		newheader->t_hoff == oldheader->t_hoff &&
		(HeapTupleHeaderGetNatts(newheader) == 
		 HeapTupleHeaderGetNatts(oldheader)) &&
		((newheader->t_infomask & ~HEAP_XACT_MASK) == 
		 (oldheader->t_infomask & ~HEAP_XACT_MASK)) &&
		memcmp(((char *)newheader) + offsetof(HeapTupleHeaderData, t_bits),
			   ((char *)oldheader) + offsetof(HeapTupleHeaderData, t_bits),
			   newtuple->t_len - offsetof(HeapTupleHeaderData, t_bits)) == 0)
	{
		/* ... then suppress the update */
		rettuple = NULL;
	}
	
    return PointerGetDatum(rettuple);
}

{'fraction_non_alphanumeric': 0.15969989281886388, 'fraction_numerical': 0.010360843158270811, 'mean_word_length': 3.34031007751938, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4102830', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1855, 'n_words': 390}