提交 583c6a22 编写于 作者: J Junio C Hamano

Merge branch 'js/blame-lib'

The internal logic used in "git blame" has been libified to make it
easier to use by cgit.

* js/blame-lib: (29 commits)
  blame: move entry prepend to libgit
  blame: move scoreboard setup to libgit
  blame: move scoreboard-related methods to libgit
  blame: move fake-commit-related methods to libgit
  blame: move origin-related methods to libgit
  blame: move core structures to header
  blame: create entry prepend function
  blame: create scoreboard setup function
  blame: create scoreboard init function
  blame: rework methods that determine 'final' commit
  blame: wrap blame_sort and compare_blame_final
  blame: move progress updates to a scoreboard callback
  blame: make sanity_check use a callback in scoreboard
  blame: move no_whole_file_rename flag to scoreboard
  blame: move xdl_opts flags to scoreboard
  blame: move show_root flag to scoreboard
  blame: move reverse flag to scoreboard
  blame: move contents_from to scoreboard
  blame: move copy/move thresholds to scoreboard
  blame: move stat counters to scoreboard
  ...
...@@ -720,6 +720,7 @@ LIB_OBJS += argv-array.o ...@@ -720,6 +720,7 @@ LIB_OBJS += argv-array.o
LIB_OBJS += attr.o LIB_OBJS += attr.o
LIB_OBJS += base85.o LIB_OBJS += base85.o
LIB_OBJS += bisect.o LIB_OBJS += bisect.o
LIB_OBJS += blame.o
LIB_OBJS += blob.o LIB_OBJS += blob.o
LIB_OBJS += branch.o LIB_OBJS += branch.o
LIB_OBJS += bulk-checkin.o LIB_OBJS += bulk-checkin.o
......
此差异已折叠。
#ifndef BLAME_H
#define BLAME_H
#include "cache.h"
#include "commit.h"
#include "xdiff-interface.h"
#include "revision.h"
#include "prio-queue.h"
#include "diff.h"
#define PICKAXE_BLAME_MOVE 01
#define PICKAXE_BLAME_COPY 02
#define PICKAXE_BLAME_COPY_HARDER 04
#define PICKAXE_BLAME_COPY_HARDEST 010
#define BLAME_DEFAULT_MOVE_SCORE 20
#define BLAME_DEFAULT_COPY_SCORE 40
/*
* One blob in a commit that is being suspected
*/
struct blame_origin {
int refcnt;
/* Record preceding blame record for this blob */
struct blame_origin *previous;
/* origins are put in a list linked via `next' hanging off the
* corresponding commit's util field in order to make finding
* them fast. The presence in this chain does not count
* towards the origin's reference count. It is tempting to
* let it count as long as the commit is pending examination,
* but even under circumstances where the commit will be
* present multiple times in the priority queue of unexamined
* commits, processing the first instance will not leave any
* work requiring the origin data for the second instance. An
* interspersed commit changing that would have to be
* preexisting with a different ancestry and with the same
* commit date in order to wedge itself between two instances
* of the same commit in the priority queue _and_ produce
* blame entries relevant for it. While we don't want to let
* us get tripped up by this case, it certainly does not seem
* worth optimizing for.
*/
struct blame_origin *next;
struct commit *commit;
/* `suspects' contains blame entries that may be attributed to
* this origin's commit or to parent commits. When a commit
* is being processed, all suspects will be moved, either by
* assigning them to an origin in a different commit, or by
* shipping them to the scoreboard's ent list because they
* cannot be attributed to a different commit.
*/
struct blame_entry *suspects;
mmfile_t file;
struct object_id blob_oid;
unsigned mode;
/* guilty gets set when shipping any suspects to the final
* blame list instead of other commits
*/
char guilty;
char path[FLEX_ARRAY];
};
/*
* Each group of lines is described by a blame_entry; it can be split
* as we pass blame to the parents. They are arranged in linked lists
* kept as `suspects' of some unprocessed origin, or entered (when the
* blame origin has been finalized) into the scoreboard structure.
* While the scoreboard structure is only sorted at the end of
* processing (according to final image line number), the lists
* attached to an origin are sorted by the target line number.
*/
struct blame_entry {
struct blame_entry *next;
/* the first line of this group in the final image;
* internally all line numbers are 0 based.
*/
int lno;
/* how many lines this group has */
int num_lines;
/* the commit that introduced this group into the final image */
struct blame_origin *suspect;
/* the line number of the first line of this group in the
* suspect's file; internally all line numbers are 0 based.
*/
int s_lno;
/* how significant this entry is -- cached to avoid
* scanning the lines over and over.
*/
unsigned score;
};
/*
* The current state of the blame assignment.
*/
struct blame_scoreboard {
/* the final commit (i.e. where we started digging from) */
struct commit *final;
/* Priority queue for commits with unassigned blame records */
struct prio_queue commits;
struct rev_info *revs;
const char *path;
/*
* The contents in the final image.
* Used by many functions to obtain contents of the nth line,
* indexed with scoreboard.lineno[blame_entry.lno].
*/
const char *final_buf;
unsigned long final_buf_size;
/* linked list of blames */
struct blame_entry *ent;
/* look-up a line in the final buffer */
int num_lines;
int *lineno;
/* stats */
int num_read_blob;
int num_get_patch;
int num_commits;
/*
* blame for a blame_entry with score lower than these thresholds
* is not passed to the parent using move/copy logic.
*/
unsigned move_score;
unsigned copy_score;
/* use this file's contents as the final image */
const char *contents_from;
/* flags */
int reverse;
int show_root;
int xdl_opts;
int no_whole_file_rename;
int debug;
/* callbacks */
void(*on_sanity_fail)(struct blame_scoreboard *, int);
void(*found_guilty_entry)(struct blame_entry *, void *);
void *found_guilty_entry_data;
};
/*
* Origin is refcounted and usually we keep the blob contents to be
* reused.
*/
static inline struct blame_origin *blame_origin_incref(struct blame_origin *o)
{
if (o)
o->refcnt++;
return o;
}
extern void blame_origin_decref(struct blame_origin *o);
extern void blame_coalesce(struct blame_scoreboard *sb);
extern void blame_sort_final(struct blame_scoreboard *sb);
extern unsigned blame_entry_score(struct blame_scoreboard *sb, struct blame_entry *e);
extern void assign_blame(struct blame_scoreboard *sb, int opt);
extern const char *blame_nth_line(struct blame_scoreboard *sb, long lno);
extern void init_scoreboard(struct blame_scoreboard *sb);
extern void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blame_origin **orig);
extern struct blame_entry *blame_entry_prepend(struct blame_entry *head, long start, long end, struct blame_origin *o);
#endif /* BLAME_H */
...@@ -25,8 +25,6 @@ struct fmt_merge_msg_opts { ...@@ -25,8 +25,6 @@ struct fmt_merge_msg_opts {
extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out, extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
struct fmt_merge_msg_opts *); struct fmt_merge_msg_opts *);
extern int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);
extern int is_builtin(const char *s); extern int is_builtin(const char *s);
extern int cmd_add(int argc, const char **argv, const char *prefix); extern int cmd_add(int argc, const char **argv, const char *prefix);
......
此差异已折叠。
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
*/ */
#include "cache.h" #include "cache.h"
#include "builtin.h" #include "builtin.h"
#include "diff.h"
#include "parse-options.h" #include "parse-options.h"
#include "userdiff.h" #include "userdiff.h"
#include "streaming.h" #include "streaming.h"
......
...@@ -5270,6 +5270,29 @@ size_t fill_textconv(struct userdiff_driver *driver, ...@@ -5270,6 +5270,29 @@ size_t fill_textconv(struct userdiff_driver *driver,
return size; return size;
} }
int textconv_object(const char *path,
unsigned mode,
const struct object_id *oid,
int oid_valid,
char **buf,
unsigned long *buf_size)
{
struct diff_filespec *df;
struct userdiff_driver *textconv;
df = alloc_filespec(path);
fill_filespec(df, oid->hash, oid_valid, mode);
textconv = get_textconv(df);
if (!textconv) {
free_filespec(df);
return 0;
}
*buf_size = fill_textconv(textconv, df, buf);
free_filespec(df);
return 1;
}
void setup_diff_pager(struct diff_options *opt) void setup_diff_pager(struct diff_options *opt)
{ {
/* /*
......
...@@ -385,6 +385,13 @@ extern size_t fill_textconv(struct userdiff_driver *driver, ...@@ -385,6 +385,13 @@ extern size_t fill_textconv(struct userdiff_driver *driver,
*/ */
extern struct userdiff_driver *get_textconv(struct diff_filespec *one); extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
/*
* Prepare diff_filespec and convert it using diff textconv API
* if the textconv driver exists.
* Return 1 if the conversion succeeds, 0 otherwise.
*/
extern int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);
extern int parse_rename_score(const char **cp_p); extern int parse_rename_score(const char **cp_p);
extern long parse_algorithm_value(const char *value); extern long parse_algorithm_value(const char *value);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册