@@ -84,8 +84,9 @@ class Diffable:
84
84
compatible type.
85
85
86
86
:note:
87
- Subclasses require a repo member as it is the case for Object instances, for
88
- practical reasons we do not derive from Object.
87
+ Subclasses require a repo member as it is the case for
88
+ :class:`~git.objects.base.Object` instances, for practical reasons we do not
89
+ derive from :class:`~git.objects.base.Object`.
89
90
"""
90
91
91
92
__slots__ = ()
@@ -111,37 +112,38 @@ def diff(
111
112
create_patch : bool = False ,
112
113
** kwargs : Any ,
113
114
) -> "DiffIndex" :
114
- """Create diffs between two items being trees, trees and index or an
115
- index and the working tree. Detects renames automatically.
115
+ """Create diffs between two items being trees, trees and index or an index and
116
+ the working tree. Detects renames automatically.
116
117
117
118
:param other:
118
119
This the item to compare us with.
119
120
120
- * If None, we will be compared to the working tree.
121
+ * If `` None`` , we will be compared to the working tree.
121
122
* If :class:`~git.index.base.Treeish`, it will be compared against the
122
123
respective tree.
123
- * If :class:`~ Diffable.Index`, it will be compared against the index.
124
+ * If :class:`Diffable.Index`, it will be compared against the index.
124
125
* If :attr:`git.NULL_TREE`, it will compare against the empty tree.
125
- * It defaults to :class:`~ Diffable.Index` so that the method will not by
126
+ * It defaults to :class:`Diffable.Index` so that the method will not by
126
127
default fail on bare repositories.
127
128
128
129
:param paths:
129
130
This a list of paths or a single path to limit the diff to. It will only
130
131
include at least one of the given path or paths.
131
132
132
133
:param create_patch:
133
- If True, the returned :class:`Diff` contains a detailed patch that if
134
+ If `` True`` , the returned :class:`Diff` contains a detailed patch that if
134
135
applied makes the self to other. Patches are somewhat costly as blobs have
135
136
to be read and diffed.
136
137
137
138
:param kwargs:
138
- Additional arguments passed to git- diff, such as ``R=True`` to swap both
139
+ Additional arguments passed to `` git diff`` , such as ``R=True`` to swap both
139
140
sides of the diff.
140
141
141
- :return: git.DiffIndex
142
+ :return:
143
+ :class:`DiffIndex`
142
144
143
145
:note:
144
- On a bare repository, ' other' needs to be provided as
146
+ On a bare repository, ` other` needs to be provided as
145
147
:class:`~Diffable.Index`, or as :class:`~git.objects.tree.Tree` or
146
148
:class:`~git.objects.commit.Commit`, or a git command error will occur.
147
149
"""
@@ -184,7 +186,7 @@ def diff(
184
186
185
187
args .insert (0 , self )
186
188
187
- # paths is list here, or None.
189
+ # paths is a list here, or None.
188
190
if paths :
189
191
args .append ("--" )
190
192
args .extend (paths )
@@ -204,7 +206,7 @@ def diff(
204
206
205
207
206
208
class DiffIndex (List [T_Diff ]):
207
- """An Index for diffs, allowing a list of Diffs to be queried by the diff
209
+ R """An Index for diffs, allowing a list of :class:`Diff`\s to be queried by the diff
208
210
properties.
209
211
210
212
The class improves the diff handling convenience.
@@ -256,34 +258,34 @@ def iter_change_type(self, change_type: Lit_change_type) -> Iterator[T_Diff]:
256
258
class Diff :
257
259
"""A Diff contains diff information between two Trees.
258
260
259
- It contains two sides a and b of the diff, members are prefixed with
260
- "a" and "b" respectively to indicate that.
261
+ It contains two sides a and b of the diff. Members are prefixed with "a" and "b"
262
+ respectively to indicate that.
261
263
262
264
Diffs keep information about the changed blob objects, the file mode, renames,
263
265
deletions and new files.
264
266
265
- There are a few cases where None has to be expected as member variable value:
267
+ There are a few cases where `` None`` has to be expected as member variable value:
266
268
267
- `` New File`` ::
269
+ New File::
268
270
269
271
a_mode is None
270
272
a_blob is None
271
273
a_path is None
272
274
273
- `` Deleted File`` ::
275
+ Deleted File::
274
276
275
277
b_mode is None
276
278
b_blob is None
277
279
b_path is None
278
280
279
- `` Working Tree Blobs``
281
+ Working Tree Blobs:
280
282
281
283
When comparing to working trees, the working tree blob will have a null hexsha
282
- as a corresponding object does not yet exist. The mode will be null as well.
283
- The path will be available, though.
284
+ as a corresponding object does not yet exist. The mode will be null as well. The
285
+ path will be available, though.
284
286
285
- If it is listed in a diff, the working tree version of the file must
286
- differ from the version in the index or tree, and hence has been modified.
287
+ If it is listed in a diff, the working tree version of the file must differ from
288
+ the version in the index or tree, and hence has been modified.
287
289
"""
288
290
289
291
# Precompiled regex.
@@ -467,17 +469,20 @@ def rename_to(self) -> Optional[str]:
467
469
468
470
@property
469
471
def renamed (self ) -> bool :
470
- """
471
- :return: True if the blob of our diff has been renamed
472
+ """Deprecated, use :attr:`renamed_file` instead.
473
+
474
+ :return:
475
+ ``True`` if the blob of our diff has been renamed
472
476
473
- :note: This property is deprecated.
477
+ :note:
478
+ This property is deprecated.
474
479
Please use the :attr:`renamed_file` property instead.
475
480
"""
476
481
return self .renamed_file
477
482
478
483
@property
479
484
def renamed_file (self ) -> bool :
480
- """:return: True if the blob of our diff has been renamed"""
485
+ """:return: `` True`` if the blob of our diff has been renamed"""
481
486
return self .rename_from != self .rename_to
482
487
483
488
@classmethod
@@ -495,11 +500,18 @@ def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_m
495
500
496
501
@classmethod
497
502
def _index_from_patch_format (cls , repo : "Repo" , proc : Union ["Popen" , "Git.AutoInterrupt" ]) -> DiffIndex :
498
- """Create a new DiffIndex from the given process output which must be in patch format.
503
+ """Create a new :class:`DiffIndex` from the given process output which must be
504
+ in patch format.
505
+
506
+ :param repo:
507
+ The repository we are operating on.
499
508
500
- :param repo: The repository we are operating on
501
- :param proc: ``git diff`` process to read from (supports :class:`Git.AutoInterrupt` wrapper)
502
- :return: git.DiffIndex
509
+ :param proc:
510
+ ``git diff`` process to read from
511
+ (supports :class:`Git.AutoInterrupt <git.cmd.Git.AutoInterrupt>` wrapper).
512
+
513
+ :return:
514
+ :class:`DiffIndex`
503
515
"""
504
516
505
517
# FIXME: Here SLURPING raw, need to re-phrase header-regexes linewise.
@@ -540,14 +552,14 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn
540
552
a_path = cls ._pick_best_path (a_path , rename_from , a_path_fallback )
541
553
b_path = cls ._pick_best_path (b_path , rename_to , b_path_fallback )
542
554
543
- # Our only means to find the actual text is to see what has not been matched by our regex,
544
- # and then retro-actively assign it to our index.
555
+ # Our only means to find the actual text is to see what has not been matched
556
+ # by our regex, and then retro-actively assign it to our index.
545
557
if previous_header is not None :
546
558
index [- 1 ].diff = text [previous_header .end () : _header .start ()]
547
559
# END assign actual diff
548
560
549
- # Make sure the mode is set if the path is set. Otherwise the resulting blob is invalid.
550
- # We just use the one mode we should have parsed.
561
+ # Make sure the mode is set if the path is set. Otherwise the resulting blob
562
+ # is invalid. We just use the one mode we should have parsed.
551
563
a_mode = old_mode or deleted_file_mode or (a_path and (b_mode or new_mode or new_file_mode ))
552
564
b_mode = b_mode or new_mode or new_file_mode or (b_path and a_mode )
553
565
index .append (
@@ -611,7 +623,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> Non
611
623
rename_from = None
612
624
rename_to = None
613
625
614
- # NOTE: We cannot conclude from the existence of a blob to change type
626
+ # NOTE: We cannot conclude from the existence of a blob to change type,
615
627
# as diffs with the working do not have blobs yet.
616
628
if change_type == "D" :
617
629
b_blob_id = None # Optional[str]
@@ -655,11 +667,17 @@ def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> Non
655
667
656
668
@classmethod
657
669
def _index_from_raw_format (cls , repo : "Repo" , proc : "Popen" ) -> "DiffIndex" :
658
- """Create a new DiffIndex from the given process output which must be in raw format.
670
+ """Create a new :class:`DiffIndex` from the given process output which must be
671
+ in raw format.
672
+
673
+ :param repo:
674
+ The repository we are operating on.
659
675
660
- :param repo: The repository we are operating on
661
- :param proc: Process to read output from
662
- :return: git.DiffIndex
676
+ :param proc:
677
+ Process to read output from.
678
+
679
+ :return:
680
+ :class:`DiffIndex`
663
681
"""
664
682
# handles
665
683
# :100644 100644 687099101... 37c5e30c8... M .gitignore
0 commit comments