Exemple #1
0
 def __init__(self, filename, encoding='iso8859-1'):
     """'encoding' sets the encoding assumed of log messages and
     delta text in RCS files.
     """
     self.filename = filename
     self.encoding = encoding
     self.rcsfile = rcsparse.rcsfile(filename)
Exemple #2
0
import rcsparse
import md5

f = rcsparse.rcsfile("test,v")
print f.head
print f.branch
s = f.symbols
print s["RELENG_4"]
print s.items()
r = f.revs
i = r.items()
print i
print f.getlog(f.sym2rev("RELENG_4"))
Exemple #3
0
    def expand_keyword(self, filename, r):
	rcs = rcsparse.rcsfile(filename)
	rev = rcs.revs[r]

	mode = self.kflag_get(rcs.expand)
	if (mode & (self.RCS_KWEXP_NONE | self.RCS_KWEXP_OLD)) != 0:
	    return rcs.checkout(rev[0])

	s = logbuf = ''
	for line in rcs.checkout(rev[0]).split('\n'):
	    while True:
		m = self.re_kw.match(line)
		if m is None:
		    break
		if len(line) > m.end(1) and line[m.end(1)] == '$':
		    dsign = m.end(1)
		else:
		    try:
			dsign = string.index(line, '$', m.end(1))
			if dsign < 0:
			    break
		    except:
			break
		prefix = line[:m.start(1)-1]
		line = line[dsign + 1:]
		s += prefix
		expbuf = ''
		if (mode & self.RCS_KWEXP_NAME) != 0:
		    expbuf += '$'
		    expbuf += m.group(1)
		    if (mode & self.RCS_KWEXP_VAL) != 0:
			expbuf += ': '
		if (mode & self.RCS_KWEXP_VAL) != 0:
		    expkw = self.rcs_expkw[m.group(1)]
		    if (expkw & self.RCS_KW_RCSFILE) != 0:
			expbuf += filename \
				if (expkw & self.RCS_KW_FULLPATH) != 0 \
				else os.path.basename(filename)
			expbuf += " "
		    if (expkw & self.RCS_KW_REVISION) != 0:
			expbuf += rev[0]
			expbuf += " "
		    if (expkw & self.RCS_KW_DATE) != 0:
			expbuf += time.strftime("%Y/%m/%d %H:%M:%S ", \
				time.gmtime(rev[1]))
		    if (expkw & self.RCS_KW_MDOCDATE) != 0:
			d = time.gmtime(rev[1])
			expbuf += time.strftime("%B%e %Y " \
				if (d.tm_mday < 10) else "%B %e %Y ", d)
		    if (expkw & self.RCS_KW_AUTHOR) != 0:
			expbuf += rev[2]
			expbuf += " "
		    if (expkw & self.RCS_KW_STATE) != 0:
			expbuf += rev[3]
			expbuf += " "
		    if (expkw & self.RCS_KW_LOG) != 0:
			p = prefix
			expbuf += filename \
				if (expkw & self.RCS_KW_FULLPATH) != 0 \
				else os.path.basename(filename)
			expbuf += " "
			logbuf += '%sRevision %s  ' % (p, rev[0])
			logbuf += time.strftime("%Y/%m/%d %H:%M:%S  ",\
				time.gmtime(rev[1]))
			logbuf += rev[2] + '\n'
			for lline in rcs.getlog(rev[0]).rstrip().split('\n'):
			    if lline == '':
				logbuf += p.rstrip() + '\n'
			    else:
				logbuf += p + lline.lstrip() +  '\n'
			if line == '':
			    logbuf += p.rstrip() + '\n'
			else:
			    logbuf += p + line.lstrip() +  '\n'
			line = ''
		    if (expkw & self.RCS_KW_SOURCE) != 0:
			expbuf += filename
			expbuf += " "
		    if (expkw & (self.RCS_KW_NAME | self.RCS_KW_LOCKER)) != 0:
			expbuf += " "
		if (mode & self.RCS_KWEXP_NAME) != 0:
		    expbuf += '$'
		s += expbuf[:255]
	    s += line + '\n'
	    if len(logbuf) > 0:
		s += logbuf
		logbuf = ''
	return s[:-1]
Exemple #4
0
import rcsparse

f = rcsparse.rcsfile('test,v')
print(f.head)
print(f.branch)
s = f.symbols
print(s['RELENG_4'])
print(list(s.items()))
r = f.revs
i = list(r.items())
print(i)
print(f.getlog(f.sym2rev('RELENG_4')).decode('ascii'))
print('1.1' in r)
Exemple #5
0
	    for tag in k.tags:
		extags.add(tag)
	    continue
	if k.max_time > max_time_max:
	    break

	marks = {}

	for f in k.revs:
	    if not do_incremental:
		marks[f.markseq] = f
	    else:
		markseq = markseq + 1
		git_dump_file(f.path, f.rev, rcs, markseq)
		marks[markseq] = f
	log = rcsparse.rcsfile(k.revs[0].path).getlog(k.revs[0].rev)
	for i, e in enumerate(log_encodings):
	    try:
		how = 'ignore' if i == len(log_encodings) - 1 else 'strict';
		log = log.decode(e, how)
		break
	    except:
		pass
	log = log.encode('utf-8', 'ignore')

	print 'commit refs/heads/' + git_branch
	markseq = markseq + 1
	print 'mark :%d' % (markseq)
	email = k.author if email_domain is None \
		else k.author + '@' + email_domain
	print 'author %s <%s> %d +0000' % (k.author, email, k.min_time)
Exemple #6
0
    def parse_file(self, path):
	rtags = dict()
	rcsfile=rcsparse.rcsfile(path)
	path_related = path[len(self.cvsroot) + 1:][:-2]
	branches = {'1': 'HEAD', '1.1.1': 'VENDOR' }
	have_111 = False
	for k,v in rcsfile.symbols.items():
	    r = v.split('.')
	    if len(r) == 3:
		branches[v] = 'VENDOR'
	    elif len(r) >= 3 and r[-2] == '0':
		z = reduce(lambda a, b: a + '.' + b, r[:-2] + r[-1:])
		branches[reduce(lambda a, b: a + '.' + b, r[:-2] + r[-1:])] = k
	    if len(r) == 2 and branches[r[0]] == 'HEAD':
		if not rtags.has_key(v):
		    rtags[v] = list()
		rtags[v].append(k)

	# sort by time and revision
	revs = sorted(rcsfile.revs.items(), \
		lambda a,b: cmp(a[1][1], b[1][1]) or cmp(b[1][0], a[1][0]))
	p = '0'
	novendor = False
	have_initial_revision = False
	last_vendor_status = None
	for k,v in revs:
	    r = k.split('.')
	    if len(r) == 4 and r[0] == '1' and r[1] == '1' and r[2] == '1' \
		    and r[3] == '1':
		if have_initial_revision:
		    continue
		if v[3] == 'dead':
		    continue
		last_vendor_status = v[3]
		have_initial_revision = True
	    elif len(r) == 4 and r[0] == '1' and r[1] == '1' and r[2] == '1':
		if novendor:
		    continue
		last_vendor_status = v[3]
	    elif len(r) == 2:
		if r[0] == '1' and r[1] == '1':
		    if have_initial_revision:
			continue
		    if v[3] == 'dead':
			continue
		    have_initial_revision = True
		elif r[0] == '1' and r[1] != '1':
		    novendor = True
		if last_vendor_status == 'dead' and v[3] == 'dead':
		    last_vendor_status = None
		    continue
		last_vendor_status = None
	    else:
		# trunk only
		continue

	    if self.dumpfile:
		self.markseq = self.markseq + 1
		git_dump_file(path, k, self.rcs, self.markseq)

	    b = reduce(lambda a, b: a + '.' + b, r[:-1])
	    try:
		a = ChangeSetKey(branches[b], v[2], v[1], rcsfile.getlog(v[0]),
			v[6], self.fuzzsec)
	    except Exception as e:
		print >>sys.stderr, 'Aborted at %s %s' % (path, v[0])
		raise e

	    a.put_file(path, k, v[3], self.markseq)
	    while self.changesets.has_key(a):
		c = self.changesets[a]
		del self.changesets[a]
		c.merge(a)
		a = c
	    self.changesets[a] = a
	    p = k
	    if rtags.has_key(k):
		for t in rtags[k]:
		    if not self.tags.has_key(t) or \
			    self.tags[t].max_time < a.max_time:
			self.tags[t] = a
Exemple #7
0
    def expand_keyword(self, filename, r):
        rcs = rcsparse.rcsfile(filename)
        rev = rcs.revs[r]

        mode = self.kflag_get(rcs.expand)
        if (mode & (self.RCS_KWEXP_NONE | self.RCS_KWEXP_OLD)) != 0:
            return rcs.checkout(rev[0])

        s = logbuf = ''
        for line in rcs.checkout(rev[0]).split('\n'):
            while True:
                m = self.re_kw.match(line)
                if m is None:
                    break
                if len(line) > m.end(1) and line[m.end(1)] == '$':
                    dsign = m.end(1)
                else:
                    try:
                        dsign = string.index(line, '$', m.end(1))
                        if dsign < 0:
                            break
                    except:
                        break
                prefix = line[:m.start(1) - 1]
                line = line[dsign + 1:]
                s += prefix
                expbuf = ''
                if (mode & self.RCS_KWEXP_NAME) != 0:
                    expbuf += '$'
                    expbuf += m.group(1)
                    if (mode & self.RCS_KWEXP_VAL) != 0:
                        expbuf += ': '
                if (mode & self.RCS_KWEXP_VAL) != 0:
                    expkw = self.rcs_expkw[m.group(1)]
                    if (expkw & self.RCS_KW_RCSFILE) != 0:
                        expbuf += filename \
                                if (expkw & self.RCS_KW_FULLPATH) != 0 \
                                else os.path.basename(filename)
                        expbuf += " "
                    if (expkw & self.RCS_KW_REVISION) != 0:
                        expbuf += rev[0]
                        expbuf += " "
                    if (expkw & self.RCS_KW_DATE) != 0:
                        expbuf += time.strftime("%Y/%m/%d %H:%M:%S ", \
                                time.gmtime(rev[1]))
                    if (expkw & self.RCS_KW_MDOCDATE) != 0:
                        d = time.gmtime(rev[1])
                        expbuf += time.strftime("%B%e %Y " \
                                if (d.tm_mday < 10) else "%B %e %Y ", d)
                    if (expkw & self.RCS_KW_AUTHOR) != 0:
                        expbuf += rev[2]
                        expbuf += " "
                    if (expkw & self.RCS_KW_STATE) != 0:
                        expbuf += rev[3]
                        expbuf += " "
                    if (expkw & self.RCS_KW_LOG) != 0:
                        p = prefix
                        expbuf += filename \
                                if (expkw & self.RCS_KW_FULLPATH) != 0 \
                                else os.path.basename(filename)
                        expbuf += " "
                        logbuf += '%sRevision %s  ' % (p, rev[0])
                        logbuf += time.strftime("%Y/%m/%d %H:%M:%S  ",\
                                time.gmtime(rev[1]))
                        logbuf += rev[2] + '\n'
                        for lline in rcs.getlog(rev[0]).rstrip().split('\n'):
                            if lline == '':
                                logbuf += p.rstrip() + '\n'
                            else:
                                logbuf += p + lline.lstrip() + '\n'
                        if line == '':
                            logbuf += p.rstrip() + '\n'
                        else:
                            logbuf += p + line.lstrip() + '\n'
                        line = ''
                    if (expkw & self.RCS_KW_SOURCE) != 0:
                        expbuf += filename
                        expbuf += " "
                    if (expkw & (self.RCS_KW_NAME | self.RCS_KW_LOCKER)) != 0:
                        expbuf += " "
                if (mode & self.RCS_KWEXP_NAME) != 0:
                    expbuf += '$'
                s += expbuf[:255]
            s += line + '\n'
            if len(logbuf) > 0:
                s += logbuf
                logbuf = ''
        return s[:-1]
Exemple #8
0
    def parse_file(self, path):
        rtags = dict()
        rcsfile = rcsparse.rcsfile(path)
        path_related = path[len(self.cvsroot) + 1:][:-2]
        branches = {'1': 'HEAD', '1.1.1': 'VENDOR'}
        have_111 = False
        for k, v in rcsfile.symbols.items():
            r = v.split('.')
            if len(r) == 3:
                branches[v] = 'VENDOR'
            elif len(r) >= 3 and r[-2] == '0':
                z = reduce(lambda a, b: a + '.' + b, r[:-2] + r[-1:])
                branches[reduce(lambda a, b: a + '.' + b, r[:-2] + r[-1:])] = k
            if len(r) == 2 and branches[r[0]] == 'HEAD':
                if not rtags.has_key(v):
                    rtags[v] = list()
                rtags[v].append(k)

        # sort by time and revision
        revs = sorted(rcsfile.revs.items(), \
                lambda a,b: cmp(a[1][1], b[1][1]) or cmp(b[1][0], a[1][0]))
        p = '0'
        novendor = False
        have_initial_revision = False
        last_vendor_status = None
        for k, v in revs:
            r = k.split('.')
            if len(r) == 4 and r[0] == '1' and r[1] == '1' and r[2] == '1' \
                    and r[3] == '1':
                if have_initial_revision:
                    continue
                if v[3] == 'dead':
                    continue
                last_vendor_status = v[3]
                have_initial_revision = True
            elif len(r) == 4 and r[0] == '1' and r[1] == '1' and r[2] == '1':
                if novendor:
                    continue
                last_vendor_status = v[3]
            elif len(r) == 2:
                if r[0] == '1' and r[1] == '1':
                    if have_initial_revision:
                        continue
                    if v[3] == 'dead':
                        continue
                    have_initial_revision = True
                elif r[0] == '1' and r[1] != '1':
                    novendor = True
                if last_vendor_status == 'dead' and v[3] == 'dead':
                    last_vendor_status = None
                    continue
                last_vendor_status = None
            else:
                # trunk only
                continue

            if self.dumpfile:
                self.markseq = self.markseq + 1
                git_dump_file(path, k, self.rcs, self.markseq)

            b = reduce(lambda a, b: a + '.' + b, r[:-1])
            try:
                a = ChangeSetKey(branches[b], v[2], v[1], rcsfile.getlog(v[0]),
                                 v[6], self.fuzzsec)
            except Exception as e:
                print >> sys.stderr, 'Aborted at %s %s' % (path, v[0])
                raise e

            a.put_file(path, k, v[3], self.markseq)
            while self.changesets.has_key(a):
                c = self.changesets[a]
                del self.changesets[a]
                c.merge(a)
                a = c
            self.changesets[a] = a
            p = k
            if rtags.has_key(k):
                for t in rtags[k]:
                    if not self.tags.has_key(t) or \
                            self.tags[t].max_time < a.max_time:
                        self.tags[t] = a
Exemple #9
0
            for tag in k.tags:
                extags.add(tag)
            continue
        if k.max_time > max_time_max:
            break

        marks = {}

        for f in k.revs:
            if not do_incremental:
                marks[f.markseq] = f
            else:
                markseq = markseq + 1
                git_dump_file(f.path, f.rev, rcs, markseq)
                marks[markseq] = f
        log = rcsparse.rcsfile(k.revs[0].path).getlog(k.revs[0].rev)
        for i, e in enumerate(log_encodings):
            try:
                how = 'ignore' if i == len(log_encodings) - 1 else 'strict'
                log = log.decode(e, how)
                break
            except:
                pass
        log = log.encode('utf-8', 'ignore')

        print 'commit refs/heads/' + git_branch
        markseq = markseq + 1
        print 'mark :%d' % (markseq)
        email = k.author if email_domain is None \
                else k.author + '@' + email_domain
        print 'author %s <%s> %d +0000' % (k.author, email, k.min_time)
Exemple #10
0
    found_last_revision = False
    for i, k in enumerate(changesets):
        if do_incremental and not found_last_revision:
            if k.min_time == svn.last_date and k.author == last_author:
                found_last_revision = True
            continue
        if k.max_time > max_time_max:
            break
        if not printOnce:
            print 'SVN-fs-dump-format-version: 2'
            print ''
            printOnce = True

        # parse the first file to get log
        finfo = k.revs[0]
        rcsfile = rcsparse.rcsfile(finfo.path)
        log = rcsparse.rcsfile(k.revs[0].path).getlog(k.revs[0].rev)
        for i, e in enumerate(log_encodings):
            try:
                how = 'ignore' if i == len(log_encodings) - 1 else 'strict'
                log = log.decode(e, how)
                break
            except:
                pass
        log = log.encode('utf-8', 'ignore')

        if email_domain is None:
            email = k.author
        else:
            email = k.author + '@' + email_domain
Exemple #11
0
    found_last_revision = False
    for i, k in enumerate(changesets):
	if do_incremental and not found_last_revision:
	    if k.min_time == svn.last_date and k.author == last_author:
		found_last_revision = True
	    continue
	if k.max_time > max_time_max:
	    break
	if not printOnce:
	    print 'SVN-fs-dump-format-version: 2'
	    print ''
	    printOnce = True

	# parse the first file to get log
	finfo = k.revs[0]
	rcsfile = rcsparse.rcsfile(finfo.path)
	log = rcsparse.rcsfile(k.revs[0].path).getlog(k.revs[0].rev)
	for i, e in enumerate(log_encodings):
	    try:
		how = 'ignore' if i == len(log_encodings) - 1 else 'strict';
		log = log.decode(e, how)
		break
	    except:
		pass
	log = log.encode('utf-8', 'ignore')

	if email_domain is None:
	    email = k.author
        else:
	    email = k.author + '@' + email_domain