MCPcopy Create free account
hub / github.com/libgit2/pygit2 / diff_to_tree

Method diff_to_tree

pygit2/index.py:310–359  ·  view source on GitHub ↗

Diff the index against a tree. Return a object with the differences between the index and the given tree. Parameters: tree The tree to diff. flags A combination of enums.DiffOption constants. context_lines

(
        self,
        tree: Tree,
        flags: DiffOption = DiffOption.NORMAL,
        context_lines: int = 3,
        interhunk_lines: int = 0,
    )

Source from the content-addressed store, hash-verified

308 return Diff.from_c(bytes(ffi.buffer(cdiff)[:]), repo)
309
310 def diff_to_tree(
311 self,
312 tree: Tree,
313 flags: DiffOption = DiffOption.NORMAL,
314 context_lines: int = 3,
315 interhunk_lines: int = 0,
316 ) -> Diff:
317 """
318 Diff the index against a tree. Return a <Diff> object with the
319 differences between the index and the given tree.
320
321 Parameters:
322
323 tree
324 The tree to diff.
325
326 flags
327 A combination of enums.DiffOption constants.
328
329 context_lines
330 The number of unchanged lines that define the boundary of a hunk
331 (and to display before and after).
332
333 interhunk_lines
334 The maximum number of unchanged lines between hunk boundaries
335 before the hunks will be merged into a one.
336 """
337 repo = self._repo
338 if repo is None:
339 raise ValueError('diff needs an associated repository')
340
341 if not isinstance(tree, Tree):
342 raise TypeError('tree must be a Tree')
343
344 copts = ffi.new('git_diff_options *')
345 err = C.git_diff_options_init(copts, 1)
346 check_error(err)
347
348 copts.flags = int(flags)
349 copts.context_lines = context_lines
350 copts.interhunk_lines = interhunk_lines
351
352 ctree = ffi.new('git_tree **')
353 ffi.buffer(ctree)[:] = tree._pointer[:]
354
355 cdiff = ffi.new('git_diff **')
356 err = C.git_diff_tree_to_index(cdiff, repo._repo, ctree[0], self._index, copts)
357 check_error(err)
358
359 return Diff.from_c(bytes(ffi.buffer(cdiff)[:]), repo)
360
361 #
362 # Conflicts

Callers 15

test_diff_invalidFunction · 0.80
test_diff_treeFunction · 0.80
test_diff_empty_treeFunction · 0.80
test_diff_tree_optsFunction · 0.80
test_diff_mergeFunction · 0.80
test_diff_patchFunction · 0.80
test_diff_idsFunction · 0.80
test_diff_patchidFunction · 0.80
test_hunk_contentFunction · 0.80
test_find_similarFunction · 0.80
test_diff_statsFunction · 0.80

Calls 2

check_errorFunction · 0.85
from_cMethod · 0.45

Tested by 14

test_diff_invalidFunction · 0.64
test_diff_treeFunction · 0.64
test_diff_empty_treeFunction · 0.64
test_diff_tree_optsFunction · 0.64
test_diff_mergeFunction · 0.64
test_diff_patchFunction · 0.64
test_diff_idsFunction · 0.64
test_diff_patchidFunction · 0.64
test_hunk_contentFunction · 0.64
test_find_similarFunction · 0.64
test_diff_statsFunction · 0.64