common/SCMCopyrightUpdater.st
author Jan Vrany <jan.vrany@labware.com>
Fri, 19 Feb 2021 08:29:41 +0000
changeset 924 4d92f234f671
parent 903 3c6c268d7395
child 942 2368b49c865d
permissions -rw-r--r--
Rework and fix HGSourceCodeManager >> #revisionLogOf:...directory:module:` This commit changes the logic in two ways: 1. #newestRevision is now the newest revision in the branch that *contains* given file (not necesarily modidfes it). If there are multiple heads in that branch, pretty much random one is returned. This changes old behavior and therefore this commit updates tests. 2. If a specific single revision is requested, i.e., both from and to revisions are the same, revision log with that single revision is returned no matter whether it modifies the file or even contains that file at all. This is essentially a workaround to fix issue #305. Moreover, this commit simplifies the code a lot by delegating all the changeset searching and filtering to mercurial using revset expressions. See https://swing.fit.cvut.cz/projects/stx-jv/ticket/305#comment:3

"
COPYRIGHT (c) 2020 LabWare

stx:libscm - a new source code management library for Smalltalk/X

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
"{ Package: 'stx:libscm/common' }"

"{ NameSpace: Smalltalk }"

Object subclass:#SCMCopyrightUpdater
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'SCM-Common-StX-Tools'
!

!SCMCopyrightUpdater class methodsFor:'documentation'!

copyright
"
COPYRIGHT (c) 2020 LabWare

stx:libscm - a new source code management library for Smalltalk/X

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
! !

!SCMCopyrightUpdater class methodsFor:'utilities'!

updateClass:aClass
    ^ self new updateClass:aClass
! !

!SCMCopyrightUpdater methodsFor:'private'!

add: missing to: existing inText: lines
    existing do:[:each | 
        (each canBeMergedWith: missing) ifTrue:[ 
            | merged |

            merged := each merge: missing.
            merged prefix: each prefix ? missing prefix.
            lines at: each line put: merged asString.
            ^ self.
        ].
    ].
    "/ Cannot be merged with anything already there,
    "/ add new one.
    existing isEmpty ifTrue:[ 
        "/ No copyright at all, add it to the top...
        lines add: missing asString beforeIndex: 3.
        lines add: ''"empty line" beforeIndex: 4.
    ] ifFalse:[
        missing prefix: existing last prefix ? missing prefix.  
        lines add: missing asString beforeIndex: existing last line + 1
    ].

    "Created: / 27-05-2020 / 12:22:45 / Jan Vrany <jan.vrany@labware.com>"
! !

!SCMCopyrightUpdater methodsFor:'utilities'!

updateClass: aClass
    "Create / update #copyright method in given class"

    | source present current |

    aClass theNonMetaclass programmingLanguage isSmalltalk ifFalse:[ ^self ].

    source := aClass theNonMetaclass copyrightMethodSource asStringCollection.
    present := (SCMCopyrightLine collectCopyrightsFromText: source).
    present notEmpty ifTrue:[ present := present first ].
    current := SCMCopyrightLine new.
    self add: current to: present inText: source.

    aClass theMetaclass compile: source asString classified: 'documentation'.
    (aClass theMetaclass compiledMethodAt:#copyright) setPackage:aClass package.
    "
    SCMCopyrightUpdater new updateClass: Class.  
    SCMCopyrightUpdater new updateClass: UnixOperatingSystem.
    SCMCopyrightUpdater new updateClass: SCMCopyrightLine.  
    SCMCopyrightUpdater new updateClass: Foo.  
    "

    "Created: / 27-05-2020 / 09:19:42 / Jan Vrany <jan.vrany@labware.com>"
    "Modified: / 27-05-2020 / 13:08:06 / Jan Vrany <jan.vrany@labware.com>"
! !

!SCMCopyrightUpdater class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !