This file is indexed.

/usr/share/pyshared/qctlib/changeselect.py is in qct 1.7-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Change Selection Dialog
#
# Copyright 2007 Steve Borho
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qctlib.ui_select import Ui_ChangeDialog
from qctlib.utils import formatPatchRichText
from qctlib.patches import iter_patched, hunk_from_header
import difflib

patchColors = {
    'std': 'black',
    'new': '#009600',
    'remove': '#C80000',
    'head': '#C800C8'}

class ChangeDialog(QDialog):
    '''QCT commit tool GUI logic'''
    def __init__(self, changefile, origfile):
        '''Initialize the dialog window, calculate diff hunks'''
        QDialog.__init__(self)

        self.changefile = changefile
        self.origfile = origfile
        self.accepted = False
        self.ui = Ui_ChangeDialog()
        self.ui.setupUi(self)
        self.ui.buttonBox.setStandardButtons(QDialogButtonBox.Cancel)
        settings = QSettings('vcs', 'qct')
        settings.beginGroup('changetool')
        if settings.contains('size'):
            self.resize(settings.value('size').toSize())
            self.move(settings.value('pos').toPoint())
        settings.endGroup()

        # Calculate unified diffs, split into hunks
        self.hunklist = []
        hunk = None
        self.origtext = open(origfile, 'rb').readlines()
        changetext = open(changefile, 'rb').readlines()
        for line in difflib.unified_diff(self.origtext, changetext):
            if line.startswith('@@'):
                if hunk: self.hunklist.append(hunk)
                hunk = [line]
            elif hunk:
                hunk.append(line)
        if hunk: self.hunklist.append(hunk)

        self.curhunk = 0
        self.showhunk()

    def showhunk(self):
        text = ''.join(self.hunklist[self.curhunk])
        h = formatPatchRichText(text, patchColors)
        self.ui.textEdit.setHtml(h)

    def on_keepButton_pressed(self):
        '''User has pushed the keep button'''
        self.curhunk += 1
        if self.curhunk < len(self.hunklist):
            self.showhunk()
        else:
            self.ui.keepButton.setEnabled(False)
            self.ui.shelveButton.setEnabled(False)
            self.ui.buttonBox.setStandardButtons( \
                    QDialogButtonBox.Cancel | QDialogButtonBox.Ok)

    def on_shelveButton_pressed(self):
        del self.hunklist[self.curhunk]
        if self.curhunk < len(self.hunklist):
            self.showhunk()
        else:
            self.ui.keepButton.setEnabled(False)
            self.ui.shelveButton.setEnabled(False)
            self.ui.buttonBox.setStandardButtons( \
                    QDialogButtonBox.Cancel | QDialogButtonBox.Ok)

    def reject(self):
        '''User has pushed the cancel button'''
        self.close()

    def closeEvent(self, e = None):
        '''Dialog is closing, save persistent state'''
        settings = QSettings('vcs', 'qct')
        settings.beginGroup('changetool')
        settings.setValue("size", QVariant(self.size()))
        settings.setValue("pos", QVariant(self.pos()))
        settings.endGroup()
        settings.sync()
        if e is not None:
            e.accept()

    def accept(self):
        '''User has pushed the accept button'''
        # Make sure at least one hunk was selected
        if not self.hunklist:
            self.close()
            return

        # Determine lines we expect from iter_patched to replace
        lasthunk = self.hunklist[-1]
        lasth = hunk_from_header(lasthunk[0])
                
        # Apply selected hunks to origfile
        try:
            try:
                patchlines = ['--- orig\n', '+++ changed\n']
                for p in self.hunklist:
                    patchlines += p
                replace = []
                for line in iter_patched(self.origtext, patchlines):
                    replace.append(line)
                if replace:
                    self.origtext[0:lasth.orig_pos + lasth.orig_range - 1] = \
                            replace
                f = open(self.origfile, 'wb')
                f.writelines(self.origtext)
                f.close()
                self.accepted = True
            except Exception, e:
                print str(e)
        finally:
            self.close()

# Test operation by running directly
if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    try:
        (changefile, origfile) = sys.argv[1:3]
    except ValueError:
        print sys.argv[0], 'changed-file orig-file'
        sys.exit(1)
    dialog = ChangeDialog(changefile, origfile)
    dialog.show()
    app.exec_()
    if dialog.accepted:
        sys.exit(0)
    else:
        print 'changes not selected'
        sys.exit(1)