]>
git.proxmox.com Git - libgit2.git/blob - tests/refs/reflog/reflog_helpers.c
2ea41ee061e487570be17293e729a9e535bbaa2b
1 #include "clar_libgit2.h"
3 #include "repository.h"
5 #include "reflog_helpers.h"
7 int reflog_entry_tostr(git_str
*out
, const git_reflog_entry
*entry
)
9 char old_oid
[GIT_OID_HEXSZ
], new_oid
[GIT_OID_HEXSZ
];
13 git_oid_tostr((char *)&old_oid
, GIT_OID_HEXSZ
, git_reflog_entry_id_old(entry
));
14 git_oid_tostr((char *)&new_oid
, GIT_OID_HEXSZ
, git_reflog_entry_id_new(entry
));
16 return git_str_printf(out
, "%s %s %s %s", old_oid
, new_oid
, "somesig", git_reflog_entry_message(entry
));
19 size_t reflog_entrycount(git_repository
*repo
, const char *name
)
24 cl_git_pass(git_reflog_read(&log
, repo
, name
));
25 ret
= git_reflog_entrycount(log
);
31 void cl_reflog_check_entry_(git_repository
*repo
, const char *reflog
, size_t idx
,
32 const char *old_spec
, const char *new_spec
,
33 const char *email
, const char *message
,
34 const char *file
, const char *func
, int line
)
37 const git_reflog_entry
*entry
;
38 git_str result
= GIT_STR_INIT
;
40 cl_git_pass(git_reflog_read(&log
, repo
, reflog
));
41 entry
= git_reflog_entry_byindex(log
, idx
);
43 clar__fail(file
, func
, line
, "Reflog has no such entry", NULL
, 1);
46 git_object
*obj
= NULL
;
47 if (git_revparse_single(&obj
, repo
, old_spec
) == GIT_OK
) {
48 if (git_oid_cmp(git_object_id(obj
), git_reflog_entry_id_old(entry
)) != 0) {
49 git_oid__writebuf(&result
, "\tOld OID: \"", git_object_id(obj
));
50 git_oid__writebuf(&result
, "\" != \"", git_reflog_entry_id_old(entry
));
51 git_str_puts(&result
, "\"\n");
55 git_oid
*oid
= git__calloc(1, sizeof(*oid
));
56 git_oid_fromstr(oid
, old_spec
);
57 if (git_oid_cmp(oid
, git_reflog_entry_id_old(entry
)) != 0) {
58 git_oid__writebuf(&result
, "\tOld OID: \"", oid
);
59 git_oid__writebuf(&result
, "\" != \"", git_reflog_entry_id_old(entry
));
60 git_str_puts(&result
, "\"\n");
66 git_object
*obj
= NULL
;
67 if (git_revparse_single(&obj
, repo
, new_spec
) == GIT_OK
) {
68 if (git_oid_cmp(git_object_id(obj
), git_reflog_entry_id_new(entry
)) != 0) {
69 git_oid__writebuf(&result
, "\tNew OID: \"", git_object_id(obj
));
70 git_oid__writebuf(&result
, "\" != \"", git_reflog_entry_id_new(entry
));
71 git_str_puts(&result
, "\"\n");
75 git_oid
*oid
= git__calloc(1, sizeof(*oid
));
76 git_oid_fromstr(oid
, new_spec
);
77 if (git_oid_cmp(oid
, git_reflog_entry_id_new(entry
)) != 0) {
78 git_oid__writebuf(&result
, "\tNew OID: \"", oid
);
79 git_oid__writebuf(&result
, "\" != \"", git_reflog_entry_id_new(entry
));
80 git_str_puts(&result
, "\"\n");
86 if (email
&& strcmp(email
, git_reflog_entry_committer(entry
)->email
) != 0)
87 git_str_printf(&result
, "\tEmail: \"%s\" != \"%s\"\n", email
, git_reflog_entry_committer(entry
)->email
);
90 const char *entry_msg
= git_reflog_entry_message(entry
);
91 if (entry_msg
== NULL
) entry_msg
= "";
93 if (entry_msg
&& strcmp(message
, entry_msg
) != 0)
94 git_str_printf(&result
, "\tMessage: \"%s\" != \"%s\"\n", message
, entry_msg
);
96 if (git_str_len(&result
) != 0)
97 clar__fail(file
, func
, line
, "Reflog entry mismatch", git_str_cstr(&result
), 1);
99 git_str_dispose(&result
);
100 git_reflog_free(log
);
103 void reflog_print(git_repository
*repo
, const char *reflog_name
)
107 git_str out
= GIT_STR_INIT
;
109 git_reflog_read(&reflog
, repo
, reflog_name
);
111 for (idx
= 0; idx
< git_reflog_entrycount(reflog
); idx
++) {
112 const git_reflog_entry
*entry
= git_reflog_entry_byindex(reflog
, idx
);
113 reflog_entry_tostr(&out
, entry
);
114 git_str_putc(&out
, '\n');
117 fprintf(stderr
, "%s", git_str_cstr(&out
));
118 git_str_dispose(&out
);
119 git_reflog_free(reflog
);