Skip to content

Commit 75f893b

Browse files
authored
refactor: update comments for documentation (#51)
* comments for docs * update
1 parent 59965f6 commit 75f893b

File tree

13 files changed

+320
-299
lines changed

13 files changed

+320
-299
lines changed

index.d.ts

Lines changed: 168 additions & 152 deletions
Large diffs are not rendered by default.

src/blob.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ impl Deref for BlobInner {
1717
}
1818
}
1919

20-
/// A structure to represent a git [blob][1]
20+
/// A class to represent a git [blob][1].
2121
///
22-
/// [1]: http://git-scm.com/book/en/Git-Internals-Git-Objects
22+
/// [1]: https://git-scm.com/book/en/Git-Internals-Git-Objects
2323
#[napi]
2424
pub struct Blob {
2525
pub(crate) inner: BlobInner,
@@ -28,7 +28,7 @@ pub struct Blob {
2828
#[napi]
2929
impl Blob {
3030
#[napi]
31-
/// Get the id (SHA1) of a repository blob
31+
/// Get the id (SHA1) of a repository blob.
3232
pub fn id(&self) -> String {
3333
self.inner.id().to_string()
3434
}

src/commit.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ pub struct CommitOptions {
1212
pub update_ref: Option<String>,
1313
/// Signature for author.
1414
///
15-
/// If not provided, default signature of repository will be used.
15+
/// If not provided, the default signature of the repository will be used.
1616
/// If there is no default signature set for the repository, an error will occur.
1717
pub author: Option<SignaturePayload>,
1818
/// Signature for commiter.
1919
///
20-
/// If not provided, default signature of repository will be used.
20+
/// If not provided, the default signature of the repository will be used.
2121
/// If there is no default signature set for the repository, an error will occur.
2222
pub committer: Option<SignaturePayload>,
2323
pub parents: Option<Vec<String>>,
@@ -40,7 +40,7 @@ impl Deref for CommitInner {
4040
}
4141

4242
#[napi]
43-
/// A structure to represent a git commit
43+
/// A class to represent a git commit.
4444
/// @hideconstructor
4545
pub struct Commit {
4646
pub(crate) inner: CommitInner,
@@ -74,7 +74,7 @@ impl Commit {
7474
/// The returned message will be slightly prettified by removing any
7575
/// potential leading newlines.
7676
///
77-
/// Throws error if the message is not valid utf-8
77+
/// Throws error if the message is not valid utf-8.
7878
pub fn message(&self) -> crate::Result<String> {
7979
let message = std::str::from_utf8(self.inner.message_raw_bytes())?.to_string();
8080
Ok(message)
@@ -113,10 +113,6 @@ impl Commit {
113113

114114
#[napi]
115115
/// Get the commit time (i.e. committer time) of a commit.
116-
///
117-
/// The first element of the tuple is the time, in seconds, since the epoch.
118-
/// The second element is the offset, in minutes, of the time zone of the
119-
/// committer's preferred time zone.
120116
pub fn time(&self) -> crate::Result<DateTime<Utc>> {
121117
let time = DateTime::from_timestamp(self.inner.time().seconds(), 0).ok_or(crate::Error::InvalidTime)?;
122118
Ok(time)
@@ -134,7 +130,7 @@ impl Commit {
134130
}
135131

136132
#[napi]
137-
/// Casts this Commit to be usable as an `GitObject`
133+
/// Casts this Commit to be usable as an `GitObject`.
138134
pub fn as_object(&self) -> GitObject {
139135
let obj = self.inner.as_object().clone();
140136
GitObject {
@@ -169,9 +165,9 @@ impl Repository {
169165
}
170166

171167
#[napi]
172-
/// Create new commit in the repository
168+
/// Create new commit in the repository.
173169
///
174-
/// If the `update_ref` is not `null`, name of the reference that will be
170+
/// If the `updateRef` is not `null`, name of the reference that will be
175171
/// updated to point to this commit. If the reference is not direct, it will
176172
/// be resolved to a direct reference. Use "HEAD" to update the HEAD of the
177173
/// current branch and make it point to this commit. If the reference

src/diff.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use std::ops::Deref;
1010
#[napi]
1111
#[repr(u32)]
1212
pub enum DiffFlags {
13-
/// File(s) treated as binary data. (1 << 0)
13+
/// File(s) treated as binary data.
1414
Binary = 1,
15-
/// File(s) treated as text data. (1 << 1)
15+
/// File(s) treated as text data.
1616
NotBinary = 2,
17-
/// `id` value is known correct. (1 << 2)
17+
/// `id` value is known correct.
1818
ValidId = 4,
19-
/// File exists at this side of the delta. (1 << 3)
19+
/// File exists at this side of the delta.
2020
Exists = 8,
2121
}
2222

@@ -34,9 +34,9 @@ pub fn diff_flags_contains(source: u32, target: u32) -> bool {
3434
pub enum DeltaType {
3535
/// No changes
3636
Unmodified,
37-
/// Entry does not exist in old version
37+
/// Entry does not exist in an old version
3838
Added,
39-
/// Entry does not exist in new version
39+
/// Entry does not exist in a new version
4040
Deleted,
4141
/// Entry content changed between old and new
4242
Modified,
@@ -93,19 +93,19 @@ impl From<DeltaType> for git2::Delta {
9393
}
9494

9595
#[napi(string_enum)]
96-
/// Possible output formats for diff data
96+
/// Possible output formats for diff data.
9797
pub enum DiffFormat {
98-
/// full git diff (default)
98+
/// full `git diff` (default)
9999
Patch,
100100
/// just the headers of the patch
101101
PatchHeader,
102-
/// like git diff --raw
102+
/// like `git diff --raw`
103103
Raw,
104-
/// like git diff --name-only
104+
/// like `git diff --name-only`
105105
NameOnly,
106-
/// like git diff --name-status
106+
/// like `git diff --name-status`
107107
NameStatus,
108-
/// git diff as used by git patch-id
108+
/// `git diff` as used by `git patch-id`
109109
PatchId,
110110
}
111111

@@ -137,8 +137,8 @@ pub struct DiffPrintOptions {
137137
/// The diff object that contains all individual file deltas.
138138
///
139139
/// This is an opaque structure which will be allocated by one of the diff
140-
/// generator functions on the `Repository` structure (e.g. `diff_tree_to_tree`
141-
/// or other `diff_*` functions).
140+
/// generator functions on the `Repository` class (e.g. `diffTreeToTree`
141+
/// or other `diff*` functions).
142142
///
143143
/// @hideconstructor
144144
pub struct Diff {
@@ -199,7 +199,7 @@ impl Diff {
199199
}
200200

201201
#[napi]
202-
/// Structure describing a hunk of a diff.
202+
/// A class describing a hunk of a diff.
203203
///
204204
/// @hideconstructor
205205
pub struct DiffStats {
@@ -228,7 +228,7 @@ impl DiffStats {
228228
}
229229

230230
#[napi(iterator)]
231-
/// An iterator over the diffs in a delta
231+
/// An iterator over the diffs in a delta.
232232
///
233233
/// @hideconstructor
234234
pub struct Deltas {
@@ -271,7 +271,7 @@ impl DiffDelta {
271271
}
272272

273273
#[napi]
274-
/// Returns the status of this entry
274+
/// Returns the status of this entry.
275275
pub fn status(&self) -> DeltaType {
276276
self.inner.status().into()
277277
}
@@ -357,7 +357,7 @@ impl DiffFile {
357357
#[napi]
358358
/// Returns the Oid of this item.
359359
///
360-
/// If this entry represents an absent side of a diff (e.g. the `old_file`
360+
/// If this entry represents an absent side of a diff (e.g. the `oldFile`
361361
/// of a `Added` delta), then the oid returned will be zeroes.
362362
pub fn id(&self) -> String {
363363
self.inner.id().to_string()
@@ -371,7 +371,7 @@ impl DiffFile {
371371
}
372372

373373
#[napi]
374-
/// Returns the size of this entry, in bytes
374+
/// Returns the size of this entry, in bytes.
375375
pub fn size(&self) -> u64 {
376376
self.inner.size()
377377
}
@@ -402,7 +402,7 @@ impl DiffFile {
402402
}
403403

404404
#[napi(object)]
405-
/// Structure describing options about how the diff should be executed.
405+
/// Describing options about how the diff should be executed.
406406
pub struct DiffOptions {
407407
/// Flag indicating whether the sides of the diff will be reversed.
408408
pub reverse: Option<bool>,
@@ -643,10 +643,10 @@ impl Repository {
643643
#[napi]
644644
/// Create a diff with the difference between two tree objects.
645645
///
646-
/// This is equivalent to `git diff <old-tree> <new-tree>`
646+
/// This is equivalent to `git diff <old-tree> <new-tree>`.
647647
///
648-
/// The first tree will be used for the "old_file" side of the delta and the
649-
/// second tree will be used for the "new_file" side of the delta. You can
648+
/// The first tree will be used for the "oldFile" side of the delta and the
649+
/// second tree will be used for the "newFile" side of the delta. You can
650650
/// pass `null` to indicate an empty tree, although it is an error to pass
651651
/// `null` for both the `oldTree` and `newTree`.
652652
pub fn diff_tree_to_tree(
@@ -675,8 +675,8 @@ impl Repository {
675675
#[napi]
676676
/// Create a diff between two index objects.
677677
///
678-
/// The first index will be used for the "old_file" side of the delta, and
679-
/// the second index will be used for the "new_file" side of the delta.
678+
/// The first index will be used for the "oldFile" side of the delta, and
679+
/// the second index will be used for the "newFile" side of the delta.
680680
pub fn diff_index_to_index(
681681
&self,
682682
env: Env,
@@ -700,12 +700,12 @@ impl Repository {
700700
/// Create a diff between the repository index and the workdir directory.
701701
///
702702
/// This matches the `git diff` command. See the note below on
703-
/// `tree_to_workdir` for a discussion of the difference between
703+
/// `diffTreeToWorkdir` for a discussion of the difference between
704704
/// `git diff` and `git diff HEAD` and how to emulate a `git diff <treeish>`
705705
/// using libgit2.
706706
///
707-
/// The index will be used for the "old_file" side of the delta, and the
708-
/// working directory will be used for the "new_file" side of the delta.
707+
/// The index will be used for the "oldFile" side of the delta, and the
708+
/// working directory will be used for the "newFile" side of the delta.
709709
///
710710
/// If you pass `null` for the index, then the existing index of the `repo`
711711
/// will be used. In this case, the index will be refreshed from disk
@@ -731,18 +731,18 @@ impl Repository {
731731
#[napi]
732732
/// Create a diff between a tree and the working directory.
733733
///
734-
/// The tree you provide will be used for the "old_file" side of the delta,
735-
/// and the working directory will be used for the "new_file" side.
734+
/// The tree you provide will be used for the "oldFile" side of the delta,
735+
/// and the working directory will be used for the "newFile" side.
736736
///
737737
/// This is not the same as `git diff <treeish>` or `git diff-index <treeish>`.
738738
/// Those commands use information from the index, whereas this
739739
/// function strictly returns the differences between the tree and the files
740-
/// in the working directory, regardless of the state of the index. Use
741-
/// `tree_to_workdir_with_index` to emulate those commands.
740+
/// in the working directory, regardless of the state of the index. Use
741+
/// `diffTreeToWorkdirWithIndex` to emulate those commands.
742742
///
743-
/// To see difference between this and `tree_to_workdir_with_index`,
743+
/// To see difference between this and `diffTreeToWorkdirWithIndex`,
744744
/// consider the example of a staged file deletion where the file has then
745-
/// been put back into the working dir and further modified. The
745+
/// been put back into the working dir and further modified. The
746746
/// tree-to-workdir diff for that file is 'modified', but `git diff` would
747747
/// show status 'deleted' since there is a staged delete.
748748
///

src/index.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ pub struct IndexUpdateAllOptions {
186186
}
187187

188188
#[napi]
189-
/// A structure to represent a git [index][1]
189+
/// A class to represent a git [index][1].
190190
/// @hideconstructor
191191
///
192-
/// [1]: http://git-scm.com/book/en/Git-Internals-Git-Objects
192+
/// [1]: https://git-scm.com/book/en/Git-Internals-Git-Objects
193193
pub struct Index {
194194
pub(crate) inner: git2::Index,
195195
}
@@ -199,7 +199,7 @@ impl Index {
199199
#[napi]
200200
/// Get index on-disk version.
201201
///
202-
/// Valid return values are 2, 3, or 4. If 3 is returned, an index
202+
/// Valid return values are 2, 3, or 4. If 3 is returned, an index
203203
/// with version 2 may be written instead, if the extension data in
204204
/// version 3 is not necessary.
205205
pub fn version(&self) -> u32 {
@@ -209,7 +209,7 @@ impl Index {
209209
#[napi]
210210
/// Set index on-disk version.
211211
///
212-
/// Valid values are 2, 3, or 4. If 2 is given, git_index_write may
212+
/// Valid values are 2, 3, or 4. If 2 is given, git_index_write may
213213
/// write an index with version 3 instead, if necessary to accurately
214214
/// represent the index.
215215
pub fn set_version(&mut self, version: u32) -> crate::Result<()> {
@@ -227,7 +227,7 @@ impl Index {
227227
}
228228

229229
#[napi]
230-
/// Add or update an index entry from a file on disk
230+
/// Add or update an index entry from a file on disk.
231231
///
232232
/// The file path must be relative to the repository's working folder and
233233
/// must be readable.
@@ -394,7 +394,7 @@ impl Index {
394394
}
395395

396396
#[napi]
397-
/// Update all index entries to match the working directory
397+
/// Update all index entries to match the working directory.
398398
///
399399
/// This method will fail in bare index instances.
400400
///
@@ -433,13 +433,13 @@ impl Index {
433433
}
434434

435435
#[napi]
436-
/// Get the count of entries currently in the index
436+
/// Get the count of entries currently in the index.
437437
pub fn count(&self) -> u32 {
438438
self.inner.len() as u32
439439
}
440440

441441
#[napi]
442-
/// Return `true` is there is no entry in the index
442+
/// Return `true` is there is no entry in the index.
443443
pub fn is_empty(&self) -> bool {
444444
self.inner.is_empty()
445445
}
@@ -469,7 +469,7 @@ impl Index {
469469
}
470470

471471
#[napi(iterator)]
472-
/// An iterator over the entries in an index
472+
/// An iterator over the entries in an index.
473473
///
474474
/// @hideconstructor
475475
pub struct IndexEntries {
@@ -493,12 +493,7 @@ impl Repository {
493493
/// Get the Index file for this repository.
494494
///
495495
/// If a custom index has not been set, the default index for the repository
496-
/// will be returned (the one located in .git/index).
497-
///
498-
/// **Caution**: If the [`git2::Repository`] of this index is dropped, then this
499-
/// [`git2::Index`] will become detached, and most methods on it will fail. See
500-
/// [`git2::Index::open`]. Be sure the repository has a binding such as a local
501-
/// variable to keep it alive at least as long as the index.
496+
/// will be returned (the one located in `.git/index`).
502497
pub fn index(&self) -> crate::Result<Index> {
503498
Ok(Index {
504499
inner: self.inner.index()?,

0 commit comments

Comments
 (0)