10
10
#include "revision.h"
11
11
#include "log-tree.h"
12
12
#include "builtin.h"
13
+ #include "tag.h"
13
14
#include <time.h>
14
15
#include <sys/time.h>
15
16
@@ -71,9 +72,43 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
71
72
return cmd_log_walk (& rev );
72
73
}
73
74
75
+ static int show_object (const unsigned char * sha1 , int suppress_header )
76
+ {
77
+ unsigned long size ;
78
+ char type [20 ];
79
+ char * buf = read_sha1_file (sha1 , type , & size );
80
+ int offset = 0 ;
81
+
82
+ if (!buf )
83
+ return error ("Could not read object %s" , sha1_to_hex (sha1 ));
84
+
85
+ if (suppress_header )
86
+ while (offset < size && buf [offset ++ ] != '\n' ) {
87
+ int new_offset = offset ;
88
+ while (new_offset < size && buf [new_offset ++ ] != '\n' )
89
+ ; /* do nothing */
90
+ offset = new_offset ;
91
+ }
92
+
93
+ if (offset < size )
94
+ fwrite (buf + offset , size - offset , 1 , stdout );
95
+ free (buf );
96
+ return 0 ;
97
+ }
98
+
99
+ static int show_tree_object (const unsigned char * sha1 ,
100
+ const char * base , int baselen ,
101
+ const char * pathname , unsigned mode , int stage )
102
+ {
103
+ printf ("%s%s\n" , pathname , S_ISDIR (mode ) ? "/" : "" );
104
+ return 0 ;
105
+ }
106
+
74
107
int cmd_show (int argc , const char * * argv , const char * prefix )
75
108
{
76
109
struct rev_info rev ;
110
+ struct object_array_entry * objects ;
111
+ int i , count , ret = 0 ;
77
112
78
113
git_config (git_log_config );
79
114
init_revisions (& rev , prefix );
@@ -85,7 +120,52 @@ int cmd_show(int argc, const char **argv, const char *prefix)
85
120
rev .ignore_merges = 0 ;
86
121
rev .no_walk = 1 ;
87
122
cmd_log_init (argc , argv , prefix , & rev );
88
- return cmd_log_walk (& rev );
123
+
124
+ count = rev .pending .nr ;
125
+ objects = rev .pending .objects ;
126
+ for (i = 0 ; i < count && !ret ; i ++ ) {
127
+ struct object * o = objects [i ].item ;
128
+ const char * name = objects [i ].name ;
129
+ switch (o -> type ) {
130
+ case OBJ_BLOB :
131
+ ret = show_object (o -> sha1 , 0 );
132
+ break ;
133
+ case OBJ_TAG : {
134
+ struct tag * t = (struct tag * )o ;
135
+
136
+ printf ("%stag %s%s\n\n" ,
137
+ diff_get_color (rev .diffopt .color_diff ,
138
+ DIFF_COMMIT ),
139
+ t -> tag ,
140
+ diff_get_color (rev .diffopt .color_diff ,
141
+ DIFF_RESET ));
142
+ ret = show_object (o -> sha1 , 1 );
143
+ objects [i ].item = (struct object * )t -> tagged ;
144
+ i -- ;
145
+ break ;
146
+ }
147
+ case OBJ_TREE :
148
+ printf ("%stree %s%s\n\n" ,
149
+ diff_get_color (rev .diffopt .color_diff ,
150
+ DIFF_COMMIT ),
151
+ name ,
152
+ diff_get_color (rev .diffopt .color_diff ,
153
+ DIFF_RESET ));
154
+ read_tree_recursive ((struct tree * )o , "" , 0 , 0 , NULL ,
155
+ show_tree_object );
156
+ break ;
157
+ case OBJ_COMMIT :
158
+ rev .pending .nr = rev .pending .alloc = 0 ;
159
+ rev .pending .objects = NULL ;
160
+ add_object_array (o , name , & rev .pending );
161
+ ret = cmd_log_walk (& rev );
162
+ break ;
163
+ default :
164
+ ret = error ("Unknown type: %d" , o -> type );
165
+ }
166
+ }
167
+ free (objects );
168
+ return ret ;
89
169
}
90
170
91
171
int cmd_log (int argc , const char * * argv , const char * prefix )
0 commit comments