Exemple #1
0
    def gather_matches(self, case_sensitive):
        (matched_refs, dummy_paths, dummy_dirs) =\
                GitRefCompletionModel.gather_matches(self, case_sensitive)

        file_list = self.cola_model.everything()
        files = set(file_list)
        files_and_dirs = utils.add_parents(set(files))

        if case_sensitive:
            transform = lambda x: x
            compare = self.completion_cmp
        else:
            transform = lambda x: x.lower()
            compare = self.lower_completion_cmp

        dirs = files_and_dirs.difference(files)
        matched_text = self.matched_text
        if matched_text:
            matched_paths = [
                f for f in files_and_dirs
                if transform(matched_text) in transform(f)
            ]
        else:
            matched_paths = list(files_and_dirs)

        matched_paths.sort(cmp=compare)

        return (matched_refs, matched_paths, dirs)
Exemple #2
0
    def gather_matches(self, case_sensitive):
        file_list = self.cmodel.everything()
        files = set(file_list)
        files_and_dirs = utils.add_parents(set(files))

        dirs = files_and_dirs.difference(files)

        model = self.cmodel
        refs = model.local_branches + model.remote_branches + model.tags
        matched_text = self.matched_text

        if matched_text:
            if case_sensitive:
                matched_refs = [r for r in refs if matched_text in r]
            else:
                matched_refs = [r for r in refs
                                    if matched_text.lower() in r.lower()]
        else:
            matched_refs = refs

        matched_refs.sort(cmp=self.lower_cmp)

        if matched_text:
            if case_sensitive:
                matched_paths = [f for f in files_and_dirs
                                        if matched_text in f]
            else:
                matched_paths = [f for f in files_and_dirs
                                    if matched_text.lower() in f.lower()]
        else:
            matched_paths = list(files_and_dirs)

        matched_paths.sort(cmp=self.lower_cmp)

        return (matched_refs, matched_paths, dirs)
Exemple #3
0
    def gather_matches(self, case_sensitive):
        (matched_refs, dummy_paths, dummy_dirs) =\
                GitRefCompletionModel.gather_matches(self, case_sensitive)

        file_list = self.main_model.everything()
        files = set(file_list)
        files_and_dirs = utils.add_parents(set(files))

        if case_sensitive:
            transform = lambda x: x
            compare = self.completion_cmp
        else:
            transform = lambda x: x.lower()
            compare = self.lower_completion_cmp

        dirs = files_and_dirs.difference(files)
        matched_text = self.matched_text
        if matched_text:
            matched_paths = [f for f in files_and_dirs
                             if transform(matched_text) in transform(f)]
        else:
            matched_paths = list(files_and_dirs)

        matched_paths.sort(cmp=compare)

        return (matched_refs, matched_paths, dirs)
Exemple #4
0
    def status(self):
        """Return the status for the entry's path."""

        model = cola.model()
        unmerged = utils.add_parents(set(model.unmerged))
        modified = utils.add_parents(set(model.modified))
        staged = utils.add_parents(set(model.staged))
        untracked = utils.add_parents(set(model.untracked))
        upstream_changed = utils.add_parents(set(model.upstream_changed))

        if self.path in unmerged:
            return (resources.icon('modified.png'), qtutils.tr('Unmerged'))
        if self.path in modified and self.path in staged:
            return (resources.icon('partial.png'),
                    qtutils.tr('Partially Staged'))
        if self.path in modified:
            return (resources.icon('modified.png'), qtutils.tr('Modified'))
        if self.path in staged:
            return (resources.icon('staged.png'), qtutils.tr('Staged'))
        if self.path in upstream_changed:
            return (resources.icon('upstream.png'),
                    qtutils.tr('Changed Upstream'))
        if self.path in untracked:
            return (None, '?')
        return (None, '')
Exemple #5
0
    def sync_selection(self):
        """Push selection into the selection model."""
        staged = []
        unmerged = []
        modified = []
        untracked = []
        state = State(staged, unmerged, modified, untracked)

        paths = self.selected_paths()
        model = main.model()
        model_staged = utils.add_parents(set(model.staged))
        model_modified = utils.add_parents(set(model.modified))
        model_unmerged = utils.add_parents(set(model.unmerged))
        model_untracked = utils.add_parents(set(model.untracked))

        for path in paths:
            if path in model_unmerged:
                unmerged.append(path)
            elif path in model_untracked:
                untracked.append(path)
            elif path in model_staged:
                staged.append(path)
            elif path in model_modified:
                modified.append(path)
            else:
                staged.append(path)
        # Push the new selection into the model.
        selection_model().set_selection(state)
        return paths
Exemple #6
0
    def sync_selection(self):
        """Push selection into the selection model."""
        staged = []
        unmerged = []
        modified = []
        untracked = []
        state = State(staged, unmerged, modified, untracked)

        paths = self.selected_paths()
        model = main.model()
        model_staged = utils.add_parents(set(model.staged))
        model_modified = utils.add_parents(set(model.modified))
        model_unmerged = utils.add_parents(set(model.unmerged))
        model_untracked = utils.add_parents(set(model.untracked))

        for path in paths:
            if path in model_unmerged:
                unmerged.append(path)
            elif path in model_untracked:
                untracked.append(path)
            elif path in model_staged:
                staged.append(path)
            elif path in model_modified:
                modified.append(path)
            else:
                staged.append(path)
        # Push the new selection into the model.
        selection_model().set_selection(state)
        return paths
Exemple #7
0
    def status(self):
        """Return the status for the entry's path."""

        model = cola.model()
        unmerged = utils.add_parents(set(model.unmerged))
        modified = utils.add_parents(set(model.modified))
        staged = utils.add_parents(set(model.staged))
        untracked = utils.add_parents(set(model.untracked))
        upstream_changed = utils.add_parents(set(model.upstream_changed))

        if self.path in unmerged:
            return (resources.icon('sigil-unmerged.png'),
                    qtutils.tr('Unmerged'))
        if self.path in modified and self.path in staged:
            return (resources.icon('sigil-partial.png'),
                    qtutils.tr('Partially Staged'))
        if self.path in modified:
            return (resources.icon('sigil-modified.png'),
                    qtutils.tr('Modified'))
        if self.path in staged:
            return (resources.icon('sigil-staged.png'),
                    qtutils.tr('Staged'))
        if self.path in upstream_changed:
            return (resources.icon('sigil-upstream.png'),
                    qtutils.tr('Changed Upstream'))
        if self.path in untracked:
            return (None, '?')
        return (None, '')
Exemple #8
0
    def gather_matches(self, case_sensitive):
        (matched_refs, dummy_paths, dummy_dirs) =\
                GitRefCompletionModel.gather_matches(self, case_sensitive)

        file_list = self.cola_model.everything()
        files = set(file_list)
        files_and_dirs = utils.add_parents(set(files))

        dirs = files_and_dirs.difference(files)
        matched_text = self.matched_text
        if matched_text:
            if case_sensitive:
                matched_paths = [f for f in files_and_dirs
                                        if matched_text in f]
            else:
                matched_paths = [f for f in files_and_dirs
                                    if matched_text.lower() in f.lower()]
        else:
            matched_paths = list(files_and_dirs)

        if self.case_sensitive:
            matched_paths.sort(cmp=self.completion_cmp)
        else:
            matched_paths.sort(cmp=self.lower_completion_cmp)
        return (matched_refs, matched_paths, dirs)
Exemple #9
0
 def selected_unstaged_paths(self, selection=None):
     """Return selected unstaged paths."""
     if not selection:
         selection = self.selected_paths()
     model = main.model()
     modified = utils.add_parents(set(model.modified))
     untracked = utils.add_parents(set(model.untracked))
     unstaged = modified.union(untracked)
     return [p for p in selection if p in unstaged]
Exemple #10
0
 def selected_unstaged_paths(self, selection=None):
     """Return selected unstaged paths."""
     if not selection:
         selection = self.selected_paths()
     model = main.model()
     modified = utils.add_parents(set(model.modified))
     untracked = utils.add_parents(set(model.untracked))
     unstaged = modified.union(untracked)
     return [p for p in selection if p in unstaged]
Exemple #11
0
    def restore_selection(self):
        if not self.old_selection or not self.old_contents:
            return

        (staged, modified, unmerged, untracked) = self.old_contents

        (staged_sel, modified_sel,
         unmerged_sel, untracked_sel) = self.old_selection

        (updated_staged, updated_modified,
         updated_unmerged, updated_untracked) = self.contents()

        def select_modified(item):
            idx = updated_modified.index(item)
            select_item(self, self.modified_item(idx))

        def select_unmerged(item):
            idx = updated_unmerged.index(item)
            select_item(self, self.unmerged_item(idx))

        def select_untracked(item):
            idx = updated_untracked.index(item)
            select_item(self, self.untracked_item(idx))

        def select_staged(item):
            idx = updated_staged.index(item)
            select_item(self, self.staged_item(idx))

        restore_selection_actions = (
            (updated_modified, modified, modified_sel, select_modified),
            (updated_unmerged, unmerged, unmerged_sel, select_unmerged),
            (updated_untracked, untracked, untracked_sel, select_untracked),
            (updated_staged, staged, staged_sel, select_staged),
        )

        for (new, old, selection, action) in restore_selection_actions:
            # When modified is staged, select the next modified item
            # When unmerged is staged, select the next unmerged item
            # When untracked is staged, select the next untracked item
            # When something is unstaged we should select the next staged item
            new_set = set(new)
            if len(new) < len(old) and old:
                for idx, i in enumerate(old):
                    if i not in new_set:
                        for j in itertools.chain(old[idx+1:],
                                                 reversed(old[:idx])):
                            if j in new_set:
                                action(j)
                                return

        for (new, old, selection, action) in restore_selection_actions:
            # Reselect items when doing partial-staging
            new_set = set(new)
            for item in selection:
                if item in new_set:
                    action(item)
Exemple #12
0
 def selected_tracked_paths(self, selection=None):
     """Return selected tracked paths."""
     if not selection:
         selection = self.selected_paths()
     model = main.model()
     staged = set(self.selected_staged_paths())
     modified = set(self.selected_modified_paths())
     untracked = utils.add_parents(set(model.untracked))
     tracked = staged.union(modified)
     return [p for p in selection
             if p not in untracked or p in tracked]
Exemple #13
0
 def selected_tracked_paths(self, selection=None):
     """Return selected tracked paths."""
     if not selection:
         selection = self.selected_paths()
     model = main.model()
     staged = set(self.selected_staged_paths())
     modified = set(self.selected_modified_paths())
     untracked = utils.add_parents(set(model.untracked))
     tracked = staged.union(modified)
     return [p for p in selection
             if p not in untracked or p in tracked]
Exemple #14
0
    def restore_selection(self):
        if not self.old_selection or not self.old_contents:
            return

        old_c = self.old_contents
        old_s = self.old_selection
        new_c = self.contents()

        def select_modified(item):
            idx = new_c.modified.index(item)
            select_item(self, self.modified_item(idx))

        def select_unmerged(item):
            idx = new_c.unmerged.index(item)
            select_item(self, self.unmerged_item(idx))

        def select_untracked(item):
            idx = new_c.untracked.index(item)
            select_item(self, self.untracked_item(idx))

        def select_staged(item):
            idx = new_c.staged.index(item)
            select_item(self, self.staged_item(idx))

        restore_selection_actions = (
            (new_c.modified, old_c.modified, old_s.modified, select_modified),
            (new_c.unmerged, old_c.unmerged, old_s.unmerged, select_unmerged),
            (new_c.untracked, old_c.untracked, old_s.untracked,
             select_untracked),
            (new_c.staged, old_c.staged, old_s.staged, select_staged),
        )

        for (new, old, selection, action) in restore_selection_actions:
            # When modified is staged, select the next modified item
            # When unmerged is staged, select the next unmerged item
            # When untracked is staged, select the next untracked item
            # When something is unstaged we should select the next staged item
            new_set = set(new)
            if len(new) < len(old) and old:
                for idx, i in enumerate(old):
                    if i not in new_set:
                        for j in itertools.chain(old[idx + 1:],
                                                 reversed(old[:idx])):
                            if j in new_set:
                                action(j)
                                return

        for (new, old, selection, action) in restore_selection_actions:
            # Reselect items when doing partial-staging
            new_set = set(new)
            for item in selection:
                if item in new_set:
                    action(item)
Exemple #15
0
def worktree_state_dict(head='HEAD',
                        update_index=False,
                        display_untracked=True):
    """Return a dict of files in various states of being

    :rtype: dict, keys are staged, unstaged, untracked, unmerged,
            changed_upstream, and submodule.

    """
    if update_index:
        git.update_index(refresh=True)

    staged, unmerged, staged_submods = diff_index(head)
    modified, modified_submods = diff_worktree()
    untracked = display_untracked and untracked_files() or []

    # Remove unmerged paths from the modified list
    unmerged_set = set(unmerged)
    modified_set = set(modified)
    modified_unmerged = modified_set.intersection(unmerged_set)
    for path in modified_unmerged:
        modified.remove(path)

    # All submodules
    submodules = staged_submods.union(modified_submods)

    # Only include the submodule in the staged list once it has
    # been staged.  Otherwise, we'll see the submodule as being
    # both modified and staged.
    modified_submods = modified_submods.difference(staged_submods)

    # Add submodules to the staged and unstaged lists
    staged.extend(list(staged_submods))
    modified.extend(list(modified_submods))

    # Look for upstream modified files if this is a tracking branch
    upstream_changed = diff_upstream(head)

    # Keep stuff sorted
    staged.sort()
    modified.sort()
    unmerged.sort()
    untracked.sort()
    upstream_changed.sort()

    return {
        'staged': staged,
        'modified': modified,
        'unmerged': unmerged,
        'untracked': untracked,
        'upstream_changed': upstream_changed,
        'submodules': submodules
    }
Exemple #16
0
def unstage_paths(args, head='HEAD'):
    status, output = git.reset(head, '--', with_stderr=True, with_status=True,
                               *set(args))
    if status != 128:
        return (status, output)
    # handle git init: we have to use 'git rm --cached'
    # detect this condition by checking if the file is still staged
    status, output = git.update_index('--',
                                      force_remove=True,
                                      with_status=True,
                                      with_stderr=True,
                                      *set(args))
    return (status, output)
Exemple #17
0
    def __init__(self, model, view, *args, **kwargs):
        """Binds a model and Qt view"""
        observer.Observer.__init__(self, model)
        QtCore.QObject.__init__(self)

        self.view = view

        self._actions = {}
        self._callbacks = {}
        self._widget_names = {}
        self._model_to_view = {}
        self._mapped_params = set()
        self._connected = set()
Exemple #18
0
def worktree_state_dict(head="HEAD", update_index=False, display_untracked=True):
    """Return a dict of files in various states of being

    :rtype: dict, keys are staged, unstaged, untracked, unmerged,
            changed_upstream, and submodule.

    """
    if update_index:
        git.update_index(refresh=True)

    staged, unmerged, staged_submods = diff_index(head)
    modified, modified_submods = diff_worktree()
    untracked = display_untracked and untracked_files() or []

    # Remove unmerged paths from the modified list
    unmerged_set = set(unmerged)
    modified_set = set(modified)
    modified_unmerged = modified_set.intersection(unmerged_set)
    for path in modified_unmerged:
        modified.remove(path)

    # All submodules
    submodules = staged_submods.union(modified_submods)

    # Only include the submodule in the staged list once it has
    # been staged.  Otherwise, we'll see the submodule as being
    # both modified and staged.
    modified_submods = modified_submods.difference(staged_submods)

    # Add submodules to the staged and unstaged lists
    staged.extend(list(staged_submods))
    modified.extend(list(modified_submods))

    # Look for upstream modified files if this is a tracking branch
    upstream_changed = diff_upstream(head)

    # Keep stuff sorted
    staged.sort()
    modified.sort()
    unmerged.sort()
    untracked.sort()
    upstream_changed.sort()

    return {
        "staged": staged,
        "modified": modified,
        "unmerged": unmerged,
        "untracked": untracked,
        "upstream_changed": upstream_changed,
        "submodules": submodules,
    }
Exemple #19
0
def _filter(a, b):
    b_set = set(b)
    a_copy = list(a)
    last = len(a_copy) - 1
    for idx, i in enumerate(reversed(a)):
        if i not in b_set:
            a.pop(last - idx)
Exemple #20
0
 def selected_modified_paths(self, selection=None):
     """Return selected modified paths."""
     if not selection:
         selection = self.selected_paths()
     model = main.model()
     modified = utils.add_parents(set(model.modified))
     return [p for p in selection if p in modified]
Exemple #21
0
    def __init__(self, parent):
        QtGui.QTreeWidget.__init__(self, parent)

        self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.headerItem().setHidden(True)
        self.setAllColumnsShowFocus(True)
        self.setSortingEnabled(False)
        self.setUniformRowHeights(True)
        self.setAnimated(True)

        self.add_item("Staged", "plus.png", hide=True)
        self.add_item("Modified", "modified.png", hide=True)
        self.add_item("Unmerged", "unmerged.png", hide=True)
        self.add_item("Untracked", "untracked.png", hide=True)

        # Used to restore the selection
        self.old_scroll = None

        self.expanded_items = set()

        self.connect(self, SIGNAL("about_to_update"), self._about_to_update)
        self.connect(self, SIGNAL("updated"), self._updated)

        self.model = cola.model()
        self.model.add_message_observer(self.model.message_about_to_update, self.about_to_update)
        self.model.add_message_observer(self.model.message_updated, self.updated)

        self.connect(self, SIGNAL("itemSelectionChanged()"), self.show_selection)
        self.connect(self, SIGNAL("itemDoubleClicked(QTreeWidgetItem*,int)"), self.double_clicked)
        self.connect(self, SIGNAL("itemClicked(QTreeWidgetItem*,int)"), self.clicked)
Exemple #22
0
 def selected_modified_paths(self, selection=None):
     """Return selected modified paths."""
     if not selection:
         selection = self.selected_paths()
     model = main.model()
     modified = utils.add_parents(set(model.modified))
     return [p for p in selection if p in modified]
Exemple #23
0
def unstage_paths(args, head="HEAD"):
    status, output = git.reset(head, "--", with_stderr=True, with_status=True, *set(args))
    if status != 128:
        return (status, output)
    # handle git init: we have to use 'git rm --cached'
    # detect this condition by checking if the file is still staged
    return untrack_paths(args, head=head)
Exemple #24
0
    def __init__(self, cwd=None):
        """Reads git repository settings and sets several methods
        so that they refer to the git module.  This object
        encapsulates cola's interaction with git."""
        Observable.__init__(self)

        # Initialize the git command object
        self.git = git.instance()

        self.head = 'HEAD'
        self.diff_text = ''
        self.mode = self.mode_none
        self.filename = None
        self.currentbranch = ''
        self.directory = ''
        self.project = ''
        self.remotes = []

        self.commitmsg = ''
        self.modified = []
        self.staged = []
        self.untracked = []
        self.unmerged = []
        self.upstream_changed = []
        self.submodules = set()

        self.local_branches = []
        self.remote_branches = []
        self.tags = []
        if cwd:
            self.set_worktree(cwd)
Exemple #25
0
    def stage_paths(self, paths):
        """Stages add/removals to git."""
        if not paths:
            self.stage_all()
            return

        add = []
        remove = []

        for path in set(paths):
            if os.path.exists(core.encode(path)):
                add.append(path)
            else:
                remove.append(path)

        self.notify_observers(self.message_about_to_update)

        # `git add -u` doesn't work on untracked files
        if add:
            self._sliced_add(add)

        # If a path doesn't exist then that means it should be removed
        # from the index.   We use `git add -u` for that.
        if remove:
            while remove:
                self.git.add('--', u=True, with_stderr=True, *remove[:42])
                remove = remove[42:]

        self._update_files()
        self.notify_observers(self.message_updated)
Exemple #26
0
def _filter(a, b):
    b_set = set(b)
    a_copy = list(a)
    last = len(a_copy) - 1
    for idx, i in enumerate(reversed(a)):
        if i not in b_set:
            a.pop(last - idx)
Exemple #27
0
def edits1(word):
   splits     = [(word[:i], word[i:]) for i in range(len(word) + 1)]
   deletes    = [a + b[1:] for a, b in splits if b]
   transposes = [a + b[1] + b[0] + b[2:] for a, b in splits if len(b)>1]
   replaces   = [a + c + b[1:] for a, b in splits for c in alphabet if b]
   inserts    = [a + c + b     for a, b in splits for c in alphabet]
   return set(deletes + transposes + replaces + inserts)
Exemple #28
0
    def __init__(self, cwd=None):
        """Reads git repository settings and sets several methods
        so that they refer to the git module.  This object
        encapsulates cola's interaction with git."""
        Observable.__init__(self)

        # Initialize the git command object
        self.git = git.instance()

        self.head = 'HEAD'
        self.diff_text = ''
        self.mode = self.mode_none
        self.filename = None
        self.currentbranch = ''
        self.directory = ''
        self.project = ''
        self.remotes = []

        self.commitmsg = ''
        self.modified = []
        self.staged = []
        self.untracked = []
        self.unmerged = []
        self.upstream_changed = []
        self.submodules = set()

        self.local_branches = []
        self.remote_branches = []
        self.tags = []
        if cwd:
            self.set_worktree(cwd)
def edits1(word):
   splits     = [(word[:i], word[i:]) for i in range(len(word) + 1)]
   deletes    = [a + b[1:] for a, b in splits if b]
   transposes = [a + b[1] + b[0] + b[2:] for a, b in splits if len(b)>1]
   replaces   = [a + c + b[1:] for a, b in splits for c in alphabet if b]
   inserts    = [a + c + b     for a, b in splits for c in alphabet]
   return set(deletes + transposes + replaces + inserts)
Exemple #30
0
def untrack_paths(args, head='HEAD'):
    if not args:
        return (-1, N_('Nothing to do'))
    return git.update_index('--',
                            force_remove=True,
                            with_status=True,
                            *set(args))
Exemple #31
0
def diff_index(head, cached=True):
    decode = core.decode
    submodules = set()
    staged = []
    unmerged = []

    status, output = git.diff_index(head,
                                    '--',
                                    cached=cached,
                                    z=True,
                                    with_status=True)
    if status != 0:
        # handle git init
        return all_files(), unmerged, submodules

    while output:
        rest, output = output.split('\0', 1)
        name, output = output.split('\0', 1)
        status = rest[-1]
        name = decode(name)
        if '160000' in rest[1:14]:
            submodules.add(name)
        elif status in 'DAMT':
            staged.append(name)
        elif status == 'U':
            unmerged.append(name)

    return staged, unmerged, submodules
Exemple #32
0
def diff_index(head, cached=True):
    decode = core.decode
    submodules = set()
    staged = []
    unmerged = []

    status, output = git.diff_index(head, cached=cached,
                                    z=True, with_status=True)
    if status != 0:
        # handle git init
        return all_files(), unmerged, submodules

    while output:
        rest, output = output.split('\0', 1)
        name, output = output.split('\0', 1)
        status = rest[-1]
        name = decode(name)
        if '160000' in rest[1:14]:
            submodules.add(name)
        elif status  in 'DAMT':
            staged.append(name)
        elif status == 'U':
            unmerged.append(name)

    return staged, unmerged, submodules
Exemple #33
0
    def stage_paths(self, paths):
        """Stages add/removals to git."""
        if not paths:
            self.stage_all()
            return

        add = []
        remove = []

        for path in set(paths):
            if os.path.exists(core.encode(path)):
                add.append(path)
            else:
                remove.append(path)

        self.notify_observers(self.message_about_to_update)

        # `git add -u` doesn't work on untracked files
        if add:
            self._sliced_add(add)

        # If a path doesn't exist then that means it should be removed
        # from the index.   We use `git add -u` for that.
        if remove:
            while remove:
                self.git.add('--', u=True, with_stderr=True, *remove[:42])
                remove = remove[42:]

        self._update_files()
        self.notify_observers(self.message_updated)
Exemple #34
0
def unstage_paths(args, head="HEAD"):
    status, out, err = git.reset(head, "--", *set(args))
    if status == 128:
        # handle git init: we have to use 'git rm --cached'
        # detect this condition by checking if the file is still staged
        return untrack_paths(args, head=head)
    else:
        return (status, out, err)
Exemple #35
0
 def __init__(self):
     """Create an event handler"""
     ## Timer used to prevent notification floods
     self._timer = None
     ## The files that have changed since the last broadcast
     self._files = set()
     ## Lock to protect files and timer from threading issues
     self._lock = Lock()
Exemple #36
0
 def __init__(self, view=None):
     QtCore.QObject.__init__(self, view)
     self.model = cola.model()
     self.view = view
     self.updated = set()
     self.connect(view, SIGNAL("history(QStringList)"), self.view_history)
     self.connect(view, SIGNAL("expanded(QModelIndex)"), self.query_model)
     self.connect(view, SIGNAL("difftool_predecessor"), self.difftool_predecessor)
Exemple #37
0
def unstage_paths(args, head='HEAD'):
    status, out, err = git.reset(head, '--', *set(args))
    if status == 128:
        # handle git init: we have to use 'git rm --cached'
        # detect this condition by checking if the file is still staged
        return untrack_paths(args, head=head)
    else:
        return (status, out, err)
Exemple #38
0
def _add_action(widget, text, fn, connect, *shortcuts):
    action = QtGui.QAction(text, widget)
    connect(action, fn)
    if shortcuts:
        shortcuts = list(set(shortcuts))
        action.setShortcuts(shortcuts)
        action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        widget.addAction(action)
    return action
Exemple #39
0
def _add_action(widget, text, fn, connect, *shortcuts):
    action = QtGui.QAction(text, widget)
    connect(action, fn)
    if shortcuts:
        shortcuts = list(set(shortcuts))
        action.setShortcuts(shortcuts)
        action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        widget.addAction(action)
    return action
Exemple #40
0
 def __init__(self, view=None):
     QtCore.QObject.__init__(self, view)
     self.model = cola.model()
     self.view = view
     self.updated = set()
     self.connect(view, SIGNAL('history(QStringList)'), self.view_history)
     self.connect(view, SIGNAL('expanded(QModelIndex)'), self.query_model)
     self.connect(view, SIGNAL('difftool_predecessor'),
                  self.difftool_predecessor)
Exemple #41
0
    def __init__(self, parent=None):
        super(CompletionLineEdit, self).__init__(parent)
        # used to hide the completion popup after a drag-select
        self._drag = 0

        self._completer = None
        self._delegate = HighlightDelegate(self)
        self.connect(self, SIGNAL("textChanged(QString)"), self._text_changed)
        self._keys_to_ignore = set([Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape])
Exemple #42
0
 def _update_files(self, update_index=False):
     state = gitcmds.worktree_state_dict(head=self.head,
                                         update_index=update_index)
     self.staged = state.get('staged', [])
     self.modified = state.get('modified', [])
     self.unmerged = state.get('unmerged', [])
     self.untracked = state.get('untracked', [])
     self.submodules = state.get('submodules', set())
     self.upstream_changed = state.get('upstream_changed', [])
Exemple #43
0
 def _update_files(self, update_index=False):
     state = gitcmds.worktree_state_dict(head=self.head,
                                         update_index=update_index)
     self.staged = state.get('staged', [])
     self.modified = state.get('modified', [])
     self.unmerged = state.get('unmerged', [])
     self.untracked = state.get('untracked', [])
     self.submodules = state.get('submodules', set())
     self.upstream_changed = state.get('upstream_changed', [])
Exemple #44
0
def unstage_paths(args, head='HEAD'):
    status, output = git.reset(head, '--', with_status=True,
                               *set(args))
    if status == 128:
        # handle git init: we have to use 'git rm --cached'
        # detect this condition by checking if the file is still staged
        return untrack_paths(args, head=head)
    else:
        return (status, output)
Exemple #45
0
def add_action(widget, text, fn, *shortcuts):
    action = QtGui.QAction(text, widget)
    action.connect(action, SIGNAL('triggered()'), fn)
    if shortcuts:
        shortcuts = list(set(shortcuts))
        action.setShortcuts(shortcuts)
        action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        widget.addAction(action)
    return action
Exemple #46
0
def worktree_state_dict(head="HEAD", staged_only=False, update_index=False):
    """Return a dict of files in various states of being

    :rtype: dict, keys are staged, unstaged, untracked, unmerged,
            changed_upstream, and submodule.

    """
    if update_index:
        git.update_index(refresh=True)

    if staged_only:
        return _branch_status(head)

    staged, unmerged, submodules = diff_index(head)
    modified, more_submods = diff_worktree()

    # Remove unmerged paths from the modified list
    unmerged_set = set(unmerged)
    modified_set = set(modified)
    modified_unmerged = modified_set.intersection(unmerged_set)
    for path in modified_unmerged:
        modified.remove(path)

    submodules = submodules.union(more_submods)
    untracked = untracked_files()

    # Look for upstream modified files if this is a tracking branch
    upstream_changed = diff_upstream(head)

    # Keep stuff sorted
    staged.sort()
    modified.sort()
    unmerged.sort()
    untracked.sort()
    upstream_changed.sort()

    return {
        "staged": staged,
        "modified": modified,
        "unmerged": unmerged,
        "untracked": untracked,
        "upstream_changed": upstream_changed,
        "submodules": submodules,
    }
Exemple #47
0
def worktree_state_dict(head='HEAD', update_index=False):
    """Return a dict of files in various states of being

    :rtype: dict, keys are staged, unstaged, untracked, unmerged,
            changed_upstream, and submodule.

    """
    if update_index:
        git.update_index(refresh=True)

    staged, unmerged, submodules = diff_index(head)
    modified, more_submods = diff_worktree()

    # Remove unmerged paths from the modified list
    unmerged_set = set(unmerged)
    modified_set = set(modified)
    modified_unmerged = modified_set.intersection(unmerged_set)
    for path in modified_unmerged:
        modified.remove(path)

    submodules = submodules.union(more_submods)
    untracked = untracked_files()

    # Look for upstream modified files if this is a tracking branch
    upstream_changed = diff_upstream(head)

    # Keep stuff sorted
    staged.sort()
    modified.sort()
    unmerged.sort()
    untracked.sort()
    upstream_changed.sort()

    return {
        'staged': staged,
        'modified': modified,
        'unmerged': unmerged,
        'untracked': untracked,
        'upstream_changed': upstream_changed,
        'submodules': submodules
    }
Exemple #48
0
    def __init__(self, cwd=None):
        """Reads git repository settings and sets several methods
        so that they refer to the git module.  This object
        encapsulates cola's interaction with git."""
        ObservableModel.__init__(self)

        # Initialize the git command object
        self.git = git.instance()

        #####################################################
        self.head = 'HEAD'
        self.mode = self.mode_none
        self.diff_text = ''
        self.filename = None
        self.currentbranch = ''
        self.trackedbranch = ''
        self.directory = ''
        self.git_version = self.git.version()
        self.remotes = []
        self.remotename = ''
        self.local_branch = ''
        self.remote_branch = ''

        #####################################################
        # Status info
        self.commitmsg = ''
        self.modified = []
        self.staged = []
        self.untracked = []
        self.unmerged = []
        self.upstream_changed = []
        self.submodules = set()

        #####################################################
        # Refs
        self.revision = ''
        self.local_branches = []
        self.remote_branches = []
        self.tags = []
        self.revisions = []
        self.summaries = []

        self.fetch_helper = None
        self.push_helper = None
        self.pull_helper = None
        self.generate_remote_helpers()
        if cwd:
            self.use_worktree(cwd)

        #####################################################
        # Dag
        self._commits = []
Exemple #49
0
    def __init__(self, parent):
        QtGui.QTreeWidget.__init__(self, parent)

        self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.headerItem().setHidden(True)
        self.setAllColumnsShowFocus(True)
        self.setSortingEnabled(False)
        self.setUniformRowHeights(True)
        self.setAnimated(True)
        self.setRootIsDecorated(False)

        self.add_item('Staged', 'plus.png', hide=True)
        self.add_item('Unmerged', 'unmerged.png', hide=True)
        self.add_item('Modified', 'modified.png', hide=True)
        self.add_item('Untracked', 'untracked.png', hide=True)

        # Used to restore the selection
        self.old_scroll = None
        self.old_selection = None
        self.old_contents = None

        self.expanded_items = set()

        self.process_selection = qtutils.add_action(self,
                'Process Selection', self._process_selection, 'Ctrl+S')

        self.launch_difftool = qtutils.add_action(self,
                'Process Selection', self._launch_difftool, 'Ctrl+D')

        self.launch_difftool = qtutils.add_action(self,
                'Launch Editor', self._launch_editor, 'Ctrl+E')

        self.up = qtutils.add_action(self, 'Move Up', self.move_up, 'K')
        self.down = qtutils.add_action(self, 'Move Down', self.move_down, 'J')

        self.connect(self, SIGNAL('about_to_update'), self._about_to_update)
        self.connect(self, SIGNAL('updated'), self._updated)

        self.m = cola.model()
        self.m.add_observer(self.m.message_about_to_update,
                            self.about_to_update)
        self.m.add_observer(self.m.message_updated, self.updated)

        self.connect(self, SIGNAL('itemSelectionChanged()'),
                     self.show_selection)
        self.connect(self,
                     SIGNAL('itemDoubleClicked(QTreeWidgetItem*,int)'),
                     self.double_clicked)
        self.connect(self,
                     SIGNAL('itemClicked(QTreeWidgetItem*,int)'),
                     self.clicked)
Exemple #50
0
    def __init__(self, parent=None):
        from cola.prefs import diff_font

        QtGui.QLineEdit.__init__(self, parent)

        self.setFont(diff_font())
        # used to hide the completion popup after a drag-select
        self._drag = 0

        self._completer = None
        self._delegate = HighlightDelegate(self)
        self.connect(self, SIGNAL('textChanged(QString)'), self._text_changed)
        self._keys_to_ignore = set([Qt.Key_Enter, Qt.Key_Return,
                                    Qt.Key_Escape])
Exemple #51
0
    def __init__(self, parent):
        QtGui.QStandardItemModel.__init__(self, parent)
        self._interesting_paths = self._get_paths()
        self._known_paths = set()

        self.connect(self, SIGNAL('updated'), self._updated_callback)
        model = main.model()
        model.add_observer(model.message_updated, self._model_updated)
        self._dir_rows = {}
        self.setColumnCount(len(Columns.ALL))
        for idx, header in enumerate(Columns.ALL):
            text = Columns.text(header)
            self.setHeaderData(idx, Qt.Horizontal, QtCore.QVariant(text))

        self._direntries = {'': self.invisibleRootItem()}
        self._initialize()
Exemple #52
0
    def gather_matches(self, case_sensitive):
        refs = self.matches()
        matched_text = self.matched_text
        if matched_text:
            if not case_sensitive:
                matched_refs = [r for r in refs if matched_text in r]
            else:
                matched_refs = [r for r in refs
                                    if matched_text.lower() in r.lower()]
        else:
            matched_refs = refs

        if self.case_sensitive:
            matched_refs.sort(cmp=self.completion_cmp)
        else:
            matched_refs.sort(cmp=self.lower_completion_cmp)
        return (matched_refs, (), set())
Exemple #53
0
    def _update_files(self, update_index=False):
        display_untracked = prefs.display_untracked()
        state = gitcmds.worktree_state_dict(
            head=self.head,
            update_index=update_index,
            display_untracked=display_untracked)
        self.staged = state.get('staged', [])
        self.modified = state.get('modified', [])
        self.unmerged = state.get('unmerged', [])
        self.untracked = state.get('untracked', [])
        self.submodules = state.get('submodules', set())
        self.upstream_changed = state.get('upstream_changed', [])

        sel = selection_model()
        if self.is_empty():
            sel.reset()
        else:
            sel.update(self)
        if selection_model().is_empty():
            self.set_diff_text('')
Exemple #54
0
    def gather_matches(self, case_sensitive):
        if case_sensitive:
            transform = lambda x: x
            compare = self.completion_cmp
        else:
            transform = lambda x: x.lower()
            compare = self.lower_completion_cmp

        matched_text = self.matched_text
        if matched_text:
            matched_refs = [r for r in self.matches()
                            if transform(matched_text) in transform(r)]
            # if we match nothing, still offer to complete something
            if not matched_refs:
                matched_refs = self.matches()
        else:
            matched_refs = self.matches()

        matched_refs.sort(cmp=compare)
        return (matched_refs, (), set())
Exemple #55
0
    def __init__(self, model, parent=None):
        QtGui.QLineEdit.__init__(self, parent)

        from cola.prefs import diff_font
        self.setFont(diff_font())
        # used to hide the completion popup after a drag-select
        self._drag = 0

        self._keys_to_ignore = set(
            [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape])

        completion_model = model(self)
        completer = Completer(completion_model, self)
        completer.setWidget(self)
        self._completer = completer

        self._delegate = HighlightDelegate(self)
        self.connect(self, SIGNAL('textChanged(QString)'), self._text_changed)

        completer.popup().setItemDelegate(self._delegate)
        self.connect(self._completer, SIGNAL('activated(QString)'),
                     self._complete)
Exemple #56
0
 def __init__(self, timeout=333):
     """Set up the pyinotify thread"""
     QtCore.QThread.__init__(self)
     ## Git command object
     self._git = cola.model().git
     ## pyinotify timeout
     self._timeout = timeout
     ## Path to monitor
     self._path = self._git.worktree()
     ## Signals thread termination
     self._running = True
     ## Directories to watching
     self._dirs_seen = set()
     ## The inotify watch manager instantiated in run()
     self._wmgr = None
     ## Events to capture
     if utils.is_linux():
         self._mask = (EventsCodes.ALL_FLAGS['IN_ATTRIB'] |
                       EventsCodes.ALL_FLAGS['IN_CLOSE_WRITE'] |
                       EventsCodes.ALL_FLAGS['IN_DELETE'] |
                       EventsCodes.ALL_FLAGS['IN_MODIFY'] |
                       EventsCodes.ALL_FLAGS['IN_MOVED_TO'])
Exemple #57
0
def diff_worktree():
    modified = []
    submodules = set()

    status, out, err = git.diff_files(z=True)
    if status != 0:
        # handle git init
        out = git.ls_files(modified=True, z=True)[STDOUT]
        if out:
            modified = out[:-1].split('\0')
        return modified, submodules

    while out:
        rest, out = out.split('\0', 1)
        name, out = out.split('\0', 1)
        status = rest[-1]
        if '160000' in rest[1:14]:
            submodules.add(name)
        elif status in 'DAMT':
            modified.append(name)

    return modified, submodules
Exemple #58
0
def diff_worktree():
    modified = []
    submodules = set()

    status, output = git.diff_files(z=True, with_status=True)
    if status != 0:
        # handle git init
        ls_files = core.decode(git.ls_files(modified=True, z=True))
        if ls_files:
            modified = ls_files[:-1].split('\0')
        return modified, submodules

    while output:
        rest, output = output.split('\0', 1)
        name, output = output.split('\0', 1)
        status = rest[-1]
        name = core.decode(name)
        if '160000' in rest[1:14]:
            submodules.add(name)
        elif status in 'DAMT':
            modified.append(name)

    return modified, submodules
Exemple #59
0
 def __init__(self):
     self.tasks = set()
     self.threadpool = QtCore.QThreadPool.globalInstance()
     self.notifier = QtCore.QObject()
     self.notifier.connect(self.notifier, SIGNAL('task_done'),
                           self.task_done)