~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to fai.py

  • Committer: Robert Collins
  • Date: 2005-10-23 00:10:38 UTC
  • mto: (147.1.39) (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: robertc@robertcollins.net-20051023001038-626888fa8be1d49d
when we encounter an obviously corrupt patchlog, work around it by using the archive.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
__docformat__ = "restructuredtext"
23
23
__doc__ = "Utility functions to be used by commands"
24
24
 
25
 
def direct_merges(merges, excludes=[]):
 
25
def direct_merges(merges):
26
26
    """Get a list of direct merges, from a list of direct and indirect
27
 
 
 
27
    
28
28
    :param merges: Iterator of merge patchlogs
29
29
    :type merges: iter of `pybaz.Patchlog`
30
30
    :return: The direct merges
31
31
    :rtype: list of `pybaz.Patchlog`
32
32
    """
33
 
    indirect = set()
 
33
    indirect = []
 
34
    direct = []
34
35
    logs = list(merges)
35
36
    if not logs:
36
37
        return []
37
38
    for log in logs:
38
39
        try:
39
 
            this_indirect = set([str(f) for f in log.new_patches
40
 
                                 if f != log.revision and
41
 
                                     str(f) not in indirect])
 
40
            this_indirect = [f for f in log.new_patches if f != log.revision]
42
41
        except pybaz.errors.NamespaceError:
43
42
            print
44
43
            print "log ", log, " unusable, attempting to use archive copy."
45
44
            log = pybaz.Revision(str(log.revision)).patchlog
46
 
            this_indirect = set([str(f) for f in log.new_patches
47
 
                                 if f != log.revision and
48
 
                                     str(f) not in indirect])
49
 
        indirect.update(this_indirect)
 
45
            this_indirect = [f for f in log.new_patches if f != log.revision]
 
46
        indirect.extend(this_indirect)
50
47
        if log.continuation_of is not None:
51
48
            # continuations list everything in new_patches
52
49
            continue
56
53
        except pybaz.errors.ExecProblem:
57
54
            # baz does not know
58
55
            # guess
59
 
            if log.revision.patchlevel != 'version-0':
 
56
            if log.revision.patchlevel != 'version-0': 
60
57
                ancestor = namespace_previous(log.revision)
61
58
            else:
62
59
                found = False
71
68
                        found = True
72
69
                print "ancestor of %s is %s" % (log.revision, ancestor)
73
70
        if ancestor is not None:
74
 
            indirect.add(str(ancestor))
75
 
    return [log.revision for log in logs if not str(log.revision) in indirect
76
 
            and log.revision not in excludes]
77
 
 
 
71
            indirect.append(ancestor)
 
72
    return [log for log in logs if not log.revision in indirect]
78
73
 
79
74
def namespace_previous(revision):
80
75
    if revision.patchlevel == 'base-0':
123
118
    :rtype: Iterator of str
124
119
    """
125
120
    args = [ 'new-merges', '--dir', directory ]
126
 
    if reverse:
 
121
    if reverse: 
127
122
        args.append('--reverse')
128
123
    args.append(version)
129
124
    return sequence_cmd(args)