summaryrefslogtreecommitdiffstats
path: root/scripts/find-commit
blob: 551fd993e3a722b2417188d6e9571dc1312c0f9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/python
#
# find a linux kernel commit message (including its associated diff)
# given a search text provided by the user
#
# Copyright (C) 2009 Michael S Gilbert 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import sys
import tempfile

if ( len( sys.argv ) < 2 ):
    sys.stderr.write( 'usage: %s <search text> {only-rc|oldest-version=2.6.#}\n' % sys.argv[0] )
    sys.exit( 1 )

if ( len( sys.argv ) > 2 ):
    onlyrc = sys.argv[2] == 'only-rc'
    if sys.argv[2].startswith( 'oldest-version=' ):
	oldest_version = int( sys.argv[2].split( '=' )[1].split( '.' )[2] )
    else:
	oldest_version = 12
else:
    onlyrc = False
    oldest_version = 12

if not os.path.exists( '/usr/bin/git' ):
    sys.stderr.write( 'error: this script uses git; please install the package\n' )
    sys.exit( 1 )

# if not already downloadeded, clone stable kernel.org git repo
giturl = 'git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-2.6-stable.git/'
gitdir = './linux-2.6-stable'
if not os.path.exists( os.path.join( gitdir , '.git/HEAD' ) ):
    sys.stdout.write( 'Existing git repository not found; will now clone from kernel.org.\n\n' )
    sys.stdout.write( 'This may take a while, so if you already have a working stable repository,\n' )
    sys.stdout.write( 'please copy it to the current directory with the name \'%s\'.\n' % gitdir.lstrip( './' ) )
    sys.stdout.write( 'Note that this *is not* Linus Torvald\'s repository, it is the stable repo:\n' )
    sys.stdout.write( '%s\n\n' % giturl)
    if ( os.system( 'git clone %s %s' % ( giturl , gitdir ) ) != 0 ):
	sys.exit( 1 )

# if kernel.org repository has updates, pull them
os.chdir( gitdir )
fread = open( './.git/refs/heads/master' , 'r' )
local_hash = fread.readline().strip( '\n' )
fread.close()
pipe = os.popen( 'git ls-remote .' )
remote_hash = pipe.readline().split()[0]
pipe.close()
if ( local_hash != remote_hash ):
    if ( os.system( 'git pull' ) != 0 ):
	sys.exit( 1 )

# retrieve set of release tags
pipe = os.popen( 'git tag -l' )
tags = pipe.readlines()
tags.reverse()
pipe.close()

# generate changelog+diff files
fnames = []
lastversion = ''
ismainline = True
rootname = 'changelog+diff'
for tag in tags:
    version = tag.strip( '\n' )
    isnotrc = tag.find( '-rc' ) < 0
    if isnotrc:
	ismainline = False
    if isnotrc or ismainline:
	if ( lastversion != '' ):
	    fname = '%s-%s' % ( rootname , lastversion.lstrip( 'v' ) )
	    if onlyrc and ( lastversion.find( '-rc' ) < 0 ):
                break
	    elif ( int( version.split( '.' )[2].split( '-' )[0] ) >= oldest_version ):
	        fnames.append( fname )
	        if not os.path.exists( fname ):
	            tmpname = tempfile.mkstemp()[1]
	            sys.stdout.write( 'generating: %s\n' % fname )
	            if ( os.system( 'git log -p %s..%s > %s' % ( version , lastversion , tmpname ) ) != 0 ):
		        os.system( 'rm %s' % tmpname )
		        sys.exit( 1 )
	            if ( os.system( 'cp %s %s' % ( tmpname , fname ) ) != 0 ):
		        os.system( 'rm %s' % tmpname )
	                sys.exit( 1 )
	            os.system( 'rm %s' % tmpname )
	lastversion = version

# search thru the generated files for text of interest
foundtext = False
for fname in fnames:
    fread = open( fname , 'r' )
    line = fread.readline()
    while line:
	if line.startswith( 'commit' ):
	    if foundtext:
		sys.stdout.write( 'found search text \'%s\' in release %s:\n' % ( sys.argv[1] , fname[len( rootname )+1::] ) )
                sys.stdout.write( commit )
		foundtext = False
	    commit = '| %s' % line
	else:
	    commit += '| %s' % line
        if ( line.find( sys.argv[1] ) >= 0 ):
            foundtext = True
	line = fread.readline()
    fread.close()

© 2014-2024 Faster IT GmbH | imprint | privacy policy