Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 260623 | Differences between
and this patch

Collapse All | Expand All

(-)orig_portage/bin/dispatch-conf (-4 / +82 lines)
Lines 32-37 Link Here
32
DIFF_CONTENTS        = "diff -Nu '%s' '%s'"
32
DIFF_CONTENTS        = "diff -Nu '%s' '%s'"
33
DIFF_CVS_INTERP      = "diff -Nu '%s' '%s' | grep '^[+-][^+-]' | grep -v '# .Header:.*'"
33
DIFF_CVS_INTERP      = "diff -Nu '%s' '%s' | grep '^[+-][^+-]' | grep -v '# .Header:.*'"
34
DIFF_WSCOMMENTS      = "diff -Nu '%s' '%s' | grep '^[+-][^+-]' | grep -v '^[-+]#' | grep -v '^[-+][:space:]*$'"
34
DIFF_WSCOMMENTS      = "diff -Nu '%s' '%s' | grep '^[+-][^+-]' | grep -v '^[-+]#' | grep -v '^[-+][:space:]*$'"
35
GIT_INIT_DB          = "git --work-tree=%s --git-dir=%s init"
36
GIT_INIT_CHMOD       = "chmod og-rwx %s"
37
GIT_INIT_ADD         = "git --work-tree=%s --git-dir=%s add ."
38
GIT_INIT_COMMIT      = "git --work-tree=%s --git-dir=%s commit -m 'automatic import after git-init'"
39
GIT_COMMIT           = "git --work-tree=%s --git-dir=%s commit %s"
35
40
36
# We need a secure scratch dir and python does silly verbose errors on the use of tempnam
41
# We need a secure scratch dir and python does silly verbose errors on the use of tempnam
37
oldmask = os.umask(0077)
42
oldmask = os.umask(0077)
Lines 82-87 Link Here
82
        else:
87
        else:
83
            self.options["log-file"] = "/dev/null"
88
            self.options["log-file"] = "/dev/null"
84
89
90
        if not self.options.has_key("use-git"):
91
            self.options['use-git'] = 'no'
92
        if not self.options.has_key("use-rcs"):
93
            self.options['use-rcs'] = 'no'
94
95
        if self.options['use-git'] == 'yes' and self.options['use-rcs'] == 'yes':
96
            print >> sys.stderr, \
97
                'dispatch-conf: cannot use git and rcs at the same time and " + \
98
                "use-rcs=yes and use-git=yes in config; fatal'
99
            return False
100
101
        if self.options['use-git'] == 'yes':
102
            if not find_binary("git"):
103
                print >> sys.stderr, \
104
                    'dispatch-conf: Error finding git and " + \
105
                    "use-git=yes in config; fatal'
106
                return False
107
108
        if self.options['use-rcs'] == 'yes':
109
            for rcs_util in ("rcs", "ci", "co", "rcsmerge"):
110
                if not find_binary(rcs_util):
111
                    print >> sys.stderr, \
112
                        'dispatch-conf: Error finding all RCS utils and " + \
113
                        "use-rcs=yes in config; fatal'
114
                    return False
115
85
        #
116
        #
86
        # Build list of extant configs
117
        # Build list of extant configs
87
        #
118
        #
Lines 98-103 Link Here
98
                path, basename = os.path.split(path)
129
                path, basename = os.path.split(path)
99
                find_opts = "-maxdepth 1"
130
                find_opts = "-maxdepth 1"
100
131
132
            if self.options['use-git'] == 'yes':
133
                dotgit = os.path.join(path, '.git')
134
                if os.path.exists(dotgit):
135
                    if not os.path.isdir(dotgit):
136
                        print >> sys.stderr, \
137
                            'dispatch-conf: ' + dotgit + ' is not a git repository; fatal'
138
                        return False
139
                else:
140
                    os.system(GIT_INIT_DB % (path, dotgit))
141
                    os.system(GIT_INIT_CHMOD % (dotgit,))
142
                    os.system(GIT_INIT_ADD % (path, dotgit))
143
                    os.system(GIT_INIT_COMMIT % (path, dotgit))
144
145
101
            confs += self.massage(os.popen(FIND_EXTANT_CONFIGS % (path, find_opts, basename)).readlines())
146
            confs += self.massage(os.popen(FIND_EXTANT_CONFIGS % (path, find_opts, basename)).readlines())
102
147
103
        if self.options['use-rcs'] == 'yes':
148
        if self.options['use-rcs'] == 'yes':
Lines 126-132 Link Here
126
            archive = os.path.join(self.options['archive-dir'], conf['current'].lstrip('/'))
171
            archive = os.path.join(self.options['archive-dir'], conf['current'].lstrip('/'))
127
            if self.options['use-rcs'] == 'yes':
172
            if self.options['use-rcs'] == 'yes':
128
                mrgfail = portage.dispatch_conf.rcs_archive(archive, conf['current'], conf['new'], mrgconf)
173
                mrgfail = portage.dispatch_conf.rcs_archive(archive, conf['current'], conf['new'], mrgconf)
129
            else:
174
            elif self.options['use-git'] == 'no':
130
                mrgfail = portage.dispatch_conf.file_archive(archive, conf['current'], conf['new'], mrgconf)
175
                mrgfail = portage.dispatch_conf.file_archive(archive, conf['current'], conf['new'], mrgconf)
131
            if os.path.exists(archive + '.dist'):
176
            if os.path.exists(archive + '.dist'):
132
                unmodified = len(commands.getoutput(DIFF_CONTENTS % (conf['current'], archive + '.dist'))) == 0
177
                unmodified = len(commands.getoutput(DIFF_CONTENTS % (conf['current'], archive + '.dist'))) == 0
Lines 313-322 Link Here
313
        archive = os.path.join(self.options['archive-dir'], curconf.lstrip('/'))
358
        archive = os.path.join(self.options['archive-dir'], curconf.lstrip('/'))
314
        if self.options['use-rcs'] == 'yes':
359
        if self.options['use-rcs'] == 'yes':
315
            portage.dispatch_conf.rcs_archive_post_process(archive)
360
            portage.dispatch_conf.rcs_archive_post_process(archive)
361
        elif self.options['use-git'] == 'yes':
362
            portage.dispatch_conf.git_archive_post_process(curconf)
316
        else:
363
        else:
317
            portage.dispatch_conf.file_archive_post_process(archive)
364
            portage.dispatch_conf.file_archive_post_process(archive)
318
365
319
366
367
    def commit(self, config_paths):
368
        """Commit all changed files in CONFIG_PROTECT to the git index"""
369
        if self.options['use-git'] == 'no':
370
            return
371
372
        gitopts = ""
373
        if self.options.has_key("git-autocommit") and self.options['git-autocommit'] == 'yes':
374
            gitopts = '-m "automatic commit after dispatch-conf"'
375
        else:
376
            gitopts = '--interactive'
377
378
        for path in config_paths.split ():
379
            path = portage.normalize_path(path)
380
            try:
381
                mymode = os.stat(path).st_mode
382
            except OSError:
383
                continue
384
            basename = ""
385
            if not stat.S_ISDIR(mymode):
386
                path, basename = os.path.split(path)
387
388
            dotgit = os.path.join(path, '.git')
389
390
            print '\n>> Committing changes to %s:' % (path,)
391
            if os.system(GIT_COMMIT % (path, dotgit, gitopts)) == 0:
392
                clear_screen()
393
394
320
    def massage (self, newconfigs):
395
    def massage (self, newconfigs):
321
        """Sort, rstrip, remove old versions, break into triad hash.
396
        """Sort, rstrip, remove old versions, break into triad hash.
322
397
Lines 411-418 Link Here
411
# run
486
# run
412
d = dispatch ()
487
d = dispatch ()
413
488
489
config_paths = portage.settings ['CONFIG_PROTECT']
490
414
if len(sys.argv) > 1:
491
if len(sys.argv) > 1:
415
    # for testing
492
    # for testing
416
    d.grind (" ".join(sys.argv[1:]))
493
    config_paths = " ".join(sys.argv[1:])
417
else:
494
418
    d.grind (portage.settings ['CONFIG_PROTECT'])
495
d.grind(config_paths)
496
d.commit(config_paths)
(-)orig_portage/cnf/dispatch-conf.conf (+8 lines)
Lines 9-14 Link Here
9
# (yes or no)
9
# (yes or no)
10
use-rcs=no
10
use-rcs=no
11
11
12
# Use git for tracking file history in a git database?
13
# (yes or no)
14
use-git=no
15
16
# Do an automatic commit or interactive commit?
17
# (yes or no)
18
git-autocommit=yes
19
12
# Diff for display
20
# Diff for display
13
# %s old file
21
# %s old file
14
# %s new file
22
# %s new file
(-)orig_portage/pym/portage/dispatch_conf.py (+9 lines)
Lines 18-23 Link Here
18
RCS_GET = 'co'
18
RCS_GET = 'co'
19
RCS_MERGE = "rcsmerge -p -r" + RCS_BRANCH + " '%s' > '%s'"
19
RCS_MERGE = "rcsmerge -p -r" + RCS_BRANCH + " '%s' > '%s'"
20
20
21
GIT_ADD = 'git add %s'
22
21
DIFF3_MERGE = "diff3 -mE '%s' '%s' '%s' > '%s'"
23
DIFF3_MERGE = "diff3 -mE '%s' '%s' '%s' > '%s'"
22
24
23
def read_config(mandatory_opts):
25
def read_config(mandatory_opts):
Lines 159-161 Link Here
159
def file_archive_post_process(archive):
161
def file_archive_post_process(archive):
160
    """Rename the archive file with the .dist.new suffix to a .dist suffix"""
162
    """Rename the archive file with the .dist.new suffix to a .dist suffix"""
161
    os.rename(archive + '.dist.new', archive + '.dist')
163
    os.rename(archive + '.dist.new', archive + '.dist')
164
165
def git_archive_post_process(curconf):
166
    """Add current config file to git for commit"""
167
    curdir = os.getcwd()
168
    os.chdir(os.path.dirname(curconf))
169
    os.system(GIT_ADD % curconf)
170
    os.chdir(curdir)

Return to bug 260623