~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/missing.py

  • Committer: Aaron Bentley
  • Date: 2005-11-29 19:54:19 UTC
  • mto: (1185.72.2 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 1525.
  • Revision ID: abentley@panoramicfeedback.com-20051129195419-9f87fe116aff380d
Added revision-history shortcuts

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
    try:
83
83
        remote_branch.lock_read()
84
84
        try:
85
 
            local_rev_history, local_rev_history_map, local_ancestry = \
86
 
                _get_data(local_branch, progress, "local", 0)
87
 
            remote_rev_history, remote_rev_history_map, remote_ancestry = \
88
 
                _get_data(remote_branch, progress, "remote", 2)
 
85
            local_rev_history, local_rev_history_map = \
 
86
                _get_history(local_branch, progress, "local", 0)
 
87
            remote_rev_history, remote_rev_history_map = \
 
88
                _get_history(remote_branch, progress, "remote", 1)
 
89
            result = _shortcut(local_rev_history, remote_rev_history)
 
90
            if result is not None:
 
91
                local_extra, remote_extra = result
 
92
                local_extra = sorted_revisions(local_extra, 
 
93
                                               local_rev_history_map)
 
94
                remote_extra = sorted_revisions(remote_extra, 
 
95
                                                remote_rev_history_map)
 
96
                return local_extra, remote_extra
 
97
 
 
98
            local_ancestry = _get_ancestry(local_branch, progress, "local",
 
99
                                           2, local_rev_history)
 
100
            remote_ancestry = _get_ancestry(remote_branch, progress, "remote",
 
101
                                            3, remote_rev_history)
89
102
            progress.update('pondering', 4, 5)
90
103
            extras = local_ancestry.symmetric_difference(remote_ancestry) 
91
104
            local_extra = extras.intersection(set(local_rev_history))
101
114
        progress.clear()
102
115
    return (local_extra, remote_extra)
103
116
 
104
 
 
105
 
def _get_data(branch, progress, label, offset):
106
 
    progress.update('%s history' % label, 0+offset, 5)
 
117
def _shortcut(local_rev_history, remote_rev_history):
 
118
    local_history = set(local_rev_history)
 
119
    remote_history = set(remote_rev_history)
 
120
    if len(local_rev_history) == 0:
 
121
        return set(), remote_history
 
122
    elif len(remote_rev_history) == 0:
 
123
        return local_history, set()
 
124
    elif local_rev_history[-1] in remote_history:
 
125
        return set(), set(remote_rev_history[remote_rev_history.index(local_rev_history[-1])+1:])
 
126
    elif remote_rev_history[-1] in local_history:
 
127
        return set(local_rev_history[local_rev_history.index(remote_rev_history[-1])+1:]), set()
 
128
    else:
 
129
        return None
 
130
 
 
131
 
 
132
def _get_history(branch, progress, label, step):
 
133
    progress.update('%s history' % label, step, 5)
107
134
    rev_history = branch.revision_history()
108
135
    rev_history_map = dict(
109
 
        [(rev, rev_history.index(rev))
 
136
        [(rev, rev_history.index(rev) + 1)
110
137
         for rev in rev_history])
111
 
    progress.update('%s ancestry' % label, 1+offset, 5)
 
138
    return rev_history, rev_history_map
 
139
 
 
140
def _get_ancestry(branch, progress, label, step, rev_history):
 
141
    progress.update('%s ancestry' % label, step, 5)
112
142
    if len(rev_history) > 0:
113
143
        ancestry = set(branch.get_ancestry(rev_history[-1]))
114
144
    else:
115
145
        ancestry = set()
116
 
    return rev_history, rev_history_map, ancestry
 
146
    return ancestry
117
147
    
118
148
 
119
149
def sorted_revisions(revisions, history_map):