@@ -21,36 +21,73 @@ static int contains(struct diff_filespec *one,
2121 return 0 ;
2222}
2323
24- void diffcore_pickaxe (const char * needle )
24+ void diffcore_pickaxe (const char * needle , int opts )
2525{
2626 struct diff_queue_struct * q = & diff_queued_diff ;
2727 unsigned long len = strlen (needle );
28- int i ;
28+ int i , has_changes ;
2929 struct diff_queue_struct outq ;
3030 outq .queue = NULL ;
3131 outq .nr = outq .alloc = 0 ;
3232
33- for (i = 0 ; i < q -> nr ; i ++ ) {
34- struct diff_filepair * p = q -> queue [i ];
35- int onum = outq .nr ;
36- if (!DIFF_FILE_VALID (p -> one )) {
37- if (!DIFF_FILE_VALID (p -> two ))
38- continue ; /* ignore nonsense */
39- /* created */
40- if (contains (p -> two , needle , len ))
41- diff_q (& outq , p );
33+ if (opts & DIFF_PICKAXE_ALL ) {
34+ /* Showing the whole changeset if needle exists */
35+ for (i = has_changes = 0 ; !has_changes && i < q -> nr ; i ++ ) {
36+ struct diff_filepair * p = q -> queue [i ];
37+ if (!DIFF_FILE_VALID (p -> one )) {
38+ if (!DIFF_FILE_VALID (p -> two ))
39+ continue ; /* ignore unmerged */
40+ /* created */
41+ if (contains (p -> two , needle , len ))
42+ has_changes ++ ;
43+ }
44+ else if (!DIFF_FILE_VALID (p -> two )) {
45+ if (contains (p -> one , needle , len ))
46+ has_changes ++ ;
47+ }
48+ else if (!diff_unmodified_pair (p ) &&
49+ contains (p -> one , needle , len ) !=
50+ contains (p -> two , needle , len ))
51+ has_changes ++ ;
4252 }
43- else if (!DIFF_FILE_VALID (p -> two )) {
44- if (contains (p -> one , needle , len ))
53+ if (has_changes )
54+ return ; /* not munge the queue */
55+
56+ /* otherwise we will clear the whole queue
57+ * by copying the empty outq at the end of this
58+ * function, but first clear the current entries
59+ * in the queue.
60+ */
61+ for (i = 0 ; i < q -> nr ; i ++ )
62+ diff_free_filepair (q -> queue [i ]);
63+ }
64+ else
65+ /* Showing only the filepairs that has the needle */
66+ for (i = 0 ; i < q -> nr ; i ++ ) {
67+ struct diff_filepair * p = q -> queue [i ];
68+ has_changes = 0 ;
69+ if (!DIFF_FILE_VALID (p -> one )) {
70+ if (!DIFF_FILE_VALID (p -> two ))
71+ ; /* ignore unmerged */
72+ /* created */
73+ else if (contains (p -> two , needle , len ))
74+ has_changes = 1 ;
75+ }
76+ else if (!DIFF_FILE_VALID (p -> two )) {
77+ if (contains (p -> one , needle , len ))
78+ has_changes = 1 ;
79+ }
80+ else if (!diff_unmodified_pair (p ) &&
81+ contains (p -> one , needle , len ) !=
82+ contains (p -> two , needle , len ))
83+ has_changes = 1 ;
84+
85+ if (has_changes )
4586 diff_q (& outq , p );
87+ else
88+ diff_free_filepair (p );
4689 }
47- else if (!diff_unmodified_pair (p ) &&
48- contains (p -> one , needle , len ) !=
49- contains (p -> two , needle , len ))
50- diff_q (& outq , p );
51- if (onum == outq .nr )
52- diff_free_filepair (p );
53- }
90+
5491 free (q -> queue );
5592 * q = outq ;
5693 return ;
0 commit comments