Skip to content

Commit a1b5ba6

Browse files
committed
Add a few Debug impls
1 parent e6f0834 commit a1b5ba6

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

helper/libgit.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use std::convert::TryInto;
66
use std::ffi::{c_void, CStr, CString, OsStr};
7+
use std::fmt;
78
use std::io::{self, Write};
89
use std::os::raw::{c_char, c_int, c_long, c_uint, c_ulong, c_ushort};
910
#[cfg(unix)]
@@ -492,36 +493,51 @@ extern "C" {
492493

493494
pub struct FileMode(u16);
494495

496+
impl fmt::Debug for FileMode {
497+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
498+
write!(f, "{:06o}", self.0)
499+
}
500+
}
501+
502+
#[derive(Derivative)]
503+
#[derivative(Debug)]
495504
pub enum DiffTreeItem {
496505
Added {
506+
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
497507
path: Box<[u8]>,
498508
mode: FileMode,
499509
oid: BlobId,
500510
},
501511
Deleted {
512+
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
502513
path: Box<[u8]>,
503514
mode: FileMode,
504515
oid: BlobId,
505516
},
506517
Modified {
518+
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
507519
path: Box<[u8]>,
508520
from_mode: FileMode,
509521
from_oid: BlobId,
510522
to_mode: FileMode,
511523
to_oid: BlobId,
512524
},
513525
Renamed {
526+
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
514527
to_path: Box<[u8]>,
515528
to_mode: FileMode,
516529
to_oid: BlobId,
530+
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
517531
from_path: Box<[u8]>,
518532
from_mode: FileMode,
519533
from_oid: BlobId,
520534
},
521535
Copied {
536+
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
522537
to_path: Box<[u8]>,
523538
to_mode: FileMode,
524539
to_oid: BlobId,
540+
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
525541
from_path: Box<[u8]>,
526542
from_mode: FileMode,
527543
from_oid: BlobId,

helper/util.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use std::borrow::ToOwned;
66
use std::cmp::Ordering;
77
use std::convert::TryInto;
8+
use std::fmt;
89
use std::io::{self, copy, Cursor, LineWriter, Read, Seek, SeekFrom, Write};
910
use std::mem;
1011
#[cfg(unix)]
@@ -516,3 +517,7 @@ fn test_ordered_zip() {
516517
Some(Err(UnorderedError(())))
517518
);
518519
}
520+
521+
pub fn bstr_fmt<S: AsRef<[u8]>>(s: &S, f: &mut fmt::Formatter) -> fmt::Result {
522+
fmt::Debug::fmt(s.as_ref().as_bstr(), f)
523+
}

helper/xdiff.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::ffi::c_void;
77
use std::marker::PhantomData;
88
use std::os::raw::{c_char, c_int, c_long, c_ulong};
99

10-
use bstr::{BStr, ByteSlice};
10+
use bstr::ByteSlice;
1111

1212
#[allow(non_camel_case_types)]
1313
#[repr(C)]
@@ -67,11 +67,13 @@ extern "C" {
6767
) -> c_int;
6868
}
6969

70-
#[derive(Debug, PartialEq)]
70+
#[derive(Derivative, PartialEq)]
71+
#[derivative(Debug)]
7172
pub struct PatchInfo<'a> {
7273
pub start: usize,
7374
pub end: usize,
74-
pub data: &'a BStr,
75+
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
76+
pub data: &'a [u8],
7577
}
7678

7779
struct HunkContext<'a> {

0 commit comments

Comments
 (0)