def diff_to_workdir(self, flags=0, context_lines=3, interhunk_lines=0): """Diff the index against the working directory. Return a <Diff> object with the differences between the index and the working copy. Arguments: flags: a GIT_DIFF_* constant. context_lines: the number of unchanged lines that define the boundary of a hunk (and to display before and after) interhunk_lines: the maximum number of unchanged lines between hunk boundaries before the hunks will be merged into a one """ repo = self._repo if repo is None: raise ValueError('diff needs an associated repository') copts = ffi.new('git_diff_options *') err = C.git_diff_init_options(copts, 1) check_error(err) copts.flags = flags copts.context_lines = context_lines copts.interhunk_lines = interhunk_lines cdiff = ffi.new('git_diff **') err = C.git_diff_index_to_workdir(cdiff, repo._repo, self._index, copts) check_error(err) return Diff.from_c(bytes(ffi.buffer(cdiff)[:]), repo)
def diff_to_workdir(self, flags=0, context_lines=3, interhunk_lines=0): """Diff the index against the working directory. Return a <Diff> object with the differences between the index and the working copy. Arguments: flags: a GIT_DIFF_* constant. context_lines: the number of unchanged lines that define the boundary of a hunk (and to display before and after) interhunk_lines: the maximum number of unchanged lines between hunk boundaries before the hunks will be merged into a one """ if not hasattr(self, '_repo'): raise ValueError('diff needs an associated repository') copts = ffi.new('git_diff_options *') err = C.git_diff_init_options(copts, 1) check_error(err) copts.flags = flags copts.context_lines = context_lines copts.interhunk_lines = interhunk_lines cdiff = ffi.new('git_diff **') err = C.git_diff_index_to_workdir(cdiff, self._repo._repo, self._index, copts) check_error(err) return Diff.from_c(bytes(ffi.buffer(cdiff)[:]), self._repo)
def diff_to_tree(self, tree, flags=0, context_lines=3, interhunk_lines=0): """ Diff the index against a tree. Return a <Diff> object with the differences between the index and the given tree. Parameters: tree The tree to diff. flags A GIT_DIFF_* constant. context_lines The number of unchanged lines that define the boundary of a hunk (and to display before and after). interhunk_lines The maximum number of unchanged lines between hunk boundaries before the hunks will be merged into a one. """ repo = self._repo if repo is None: raise ValueError('diff needs an associated repository') if not isinstance(tree, Tree): raise TypeError('tree must be a Tree') copts = ffi.new('git_diff_options *') err = C.git_diff_init_options(copts, 1) check_error(err) copts.flags = flags copts.context_lines = context_lines copts.interhunk_lines = interhunk_lines ctree = ffi.new('git_tree **') ffi.buffer(ctree)[:] = tree._pointer[:] cdiff = ffi.new('git_diff **') err = C.git_diff_tree_to_index(cdiff, repo._repo, ctree[0], self._index, copts) check_error(err) return Diff.from_c(bytes(ffi.buffer(cdiff)[:]), repo)