<commit_before>#
# Copyright (c) 2004 Specifix, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#
"""
Defines the datastreams stored in a changeset
"""

import copy
import struct
import versions

from deps import filedeps, deps

_STREAM_CONTENTS    = 1
_STREAM_DEVICE	    = 2
_STREAM_FLAGS	    = 3
_STREAM_FLAVOR	    = 4
_STREAM_INODE	    = 5
_STREAM_PROVIDES    = 6
_STREAM_REQUIRES    = 7
_STREAM_TAGS	    = 8
_STREAM_TARGET	    = 9

_STREAM_TROVE_CHANGE_SET = 100

class InfoStream(object):

    __slots__ = ()

    def copy(self):
        return self.__class__(self.freeze())
    
    def freeze(self):
	raise NotImplementedError
    
    def diff(self, them):
	raise NotImplementedError

    def twm(self, diff, base):
	"""
	Performs a three way merge. Base is the original information,
	diff is one of the changes, and self is the (already changed)
	object. Returns a boolean saying whether or not the merge failed
	"""
	raise NotImplementedError

    def __eq__(self, them):
	raise NotImplementedError

    def __ne__(self, them):
	return not self.__eq__(them)

class NumericStream(InfoStream):

    __slots__ = "val"

    def value(self):
	return self.val

    def set(self, val):
	self.val = val

    def freeze(self):
	return struct.pack(self.format, self.val)

    def diff(self, them):
	if self.val != them.val:
	    return struct.pack(self.format, self.val)

	return ""

    def thaw(self, frz):
	self.val = struct.unpack(self.format, frz)[0]

    def twm(self, diff, base):
	if not diff: return False

	newVal = struct.unpack(self.format, diff)[0]
	if self.val == base.val:
	    self.val = newVal
	    return False
	elif self.val != newVal:
	    return True

	return False

    def __eq__(self, other):
	return other.__class__ == self.__class__ and \
	       self.val == other.val

    def __init__(self, val = None):
	if type(val) == str:
	    self.thaw(val)
	else:
	    self.val = val

class ShortStream(NumericStream):

    format = "!H"

class IntStream(NumericStream):

    __slots__ = ( "val", )

    format = "!I"

class MtimeStream(NumericStream):

    format = "!I"

    def __eq__(self, other):
	# don't ever compare mtimes
	return True

    def twm(self, diff, base):
	# and don't let merges fail
	NumericStream.twm(self, diff, base)
	return False

class LongLongStream(NumericStream):

    format = "!Q"

class StringStream(InfoStream):
    """
    Stores a simple string; used for the target of symbolic links
    """

    __slots__ = "s"

    def value(self):
	return self.s

    def set(self, val):
        assert(type(val) is str)
	self.s = val

    def freeze(self):
	return self.s

    def asString(self):
	return self.s

    def diff(self, them):
	if self.s != them.s:
	    return self.s

	return ""<commit_msg>None is okay for the value of a changelog message<commit_after>#
# Copyright (c) 2004 Specifix, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#
"""
Defines the datastreams stored in a changeset
"""

import copy
import struct
import versions

from deps import filedeps, deps

_STREAM_CONTENTS    = 1
_STREAM_DEVICE	    = 2
_STREAM_FLAGS	    = 3
_STREAM_FLAVOR	    = 4
_STREAM_INODE	    = 5
_STREAM_PROVIDES    = 6
_STREAM_REQUIRES    = 7
_STREAM_TAGS	    = 8
_STREAM_TARGET	    = 9

_STREAM_TROVE_CHANGE_SET = 100

class InfoStream(object):

    __slots__ = ()

    def copy(self):
        return self.__class__(self.freeze())
    
    def freeze(self):
	raise NotImplementedError
    
    def diff(self, them):
	raise NotImplementedError

    def twm(self, diff, base):
	"""
	Performs a three way merge. Base is the original information,
	diff is one of the changes, and self is the (already changed)
	object. Returns a boolean saying whether or not the merge failed
	"""
	raise NotImplementedError

    def __eq__(self, them):
	raise NotImplementedError

    def __ne__(self, them):
	return not self.__eq__(them)

class NumericStream(InfoStream):

    __slots__ = "val"

    def value(self):
	return self.val

    def set(self, val):
	self.val = val

    def freeze(self):
	return struct.pack(self.format, self.val)

    def diff(self, them):
	if self.val != them.val:
	    return struct.pack(self.format, self.val)

	return ""

    def thaw(self, frz):
	self.val = struct.unpack(self.format, frz)[0]

    def twm(self, diff, base):
	if not diff: return False

	newVal = struct.unpack(self.format, diff)[0]
	if self.val == base.val:
	    self.val = newVal
	    return False
	elif self.val != newVal:
	    return True

	return False

    def __eq__(self, other):
	return other.__class__ == self.__class__ and \
	       self.val == other.val

    def __init__(self, val = None):
	if type(val) == str:
	    self.thaw(val)
	else:
	    self.val = val

class ShortStream(NumericStream):

    format = "!H"

class IntStream(NumericStream):

    __slots__ = ( "val", )

    format = "!I"

class MtimeStream(NumericStream):

    format = "!I"

    def __eq__(self, other):
	# don't ever compare mtimes
	return True

    def twm(self, diff, base):
	# and don't let merges fail
	NumericStream.twm(self, diff, base)
	return False

class LongLongStream(NumericStream):

    format = "!Q"

class StringStream(InfoStream):
    """
    Stores a simple string; used for the target of symbolic links
    """

    __slots__ = "s"

    def value(self):
	return self.s

    def set(self, val):
        assert(not val or type(val) is str)
	self.s = val

    def freeze(self):
	return self.s

    def asString(self):
	return self.s

    def diff(self, them):
	if self.s != them.s:
	    return self.s

	return ""
{'fraction_non_alphanumeric': 0.09602699800582912, 'fraction_numerical': 0.00613591041570793, 'mean_word_length': 3.18216805644644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5278515', 'n_tokens_mistral': 2243, 'n_tokens_neox': 2118, 'n_words': 724}