gitg/libgitg/gitg-commit.vala

180 lines
3.2 KiB
Vala
Raw Normal View History

/*
* This file is part of gitg
*
* Copyright (C) 2012 - Jesse van den Kieboom
*
* gitg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* gitg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gitg. If not, see <http://www.gnu.org/licenses/>.
*/
2012-04-14 11:46:39 +00:00
namespace Gitg
{
public class Commit : Ggit.Commit
{
2012-04-22 13:11:43 +00:00
public LaneTag tag { get; set; }
private uint d_mylane;
2012-04-24 22:01:27 +00:00
private SList<Lane> d_lanes;
2012-04-14 11:46:39 +00:00
2012-04-24 22:01:27 +00:00
public unowned SList<Lane> get_lanes()
{
return d_lanes;
}
2012-04-14 11:46:39 +00:00
2012-04-22 13:11:43 +00:00
public uint mylane
2012-04-14 11:46:39 +00:00
{
get { return d_mylane; }
set
{
d_mylane = value;
update_lane_tag();
}
}
2012-04-22 13:11:43 +00:00
public Lane lane
2012-04-14 11:46:39 +00:00
{
2012-04-24 22:01:27 +00:00
get { return d_lanes.nth_data(d_mylane); }
}
public unowned SList<Lane> insert_lane(Lane lane, int idx)
{
d_lanes.insert(lane, idx);
return d_lanes;
2012-04-14 11:46:39 +00:00
}
public unowned SList<Lane> remove_lane(Lane lane)
{
2012-04-24 22:01:27 +00:00
d_lanes.remove(lane);
return d_lanes;
2012-04-14 11:46:39 +00:00
}
private void update_lane_tag()
{
2012-04-24 22:01:27 +00:00
unowned Lane? lane = d_lanes.nth_data(d_mylane);
2012-04-14 11:46:39 +00:00
if (lane == null)
{
return;
}
2012-04-22 13:11:43 +00:00
lane.tag &= ~(LaneTag.SIGN_STASH |
LaneTag.SIGN_STAGED |
LaneTag.SIGN_UNSTAGED) | tag;
2012-04-14 11:46:39 +00:00
}
2012-04-22 13:11:43 +00:00
public void update_lanes(owned SList<Lane> lanes, int mylane)
2012-04-14 11:46:39 +00:00
{
2012-04-24 22:01:27 +00:00
d_lanes = (owned)lanes;
2012-04-14 11:46:39 +00:00
if (mylane >= 0)
{
d_mylane = (ushort)mylane;
}
update_lane_tag();
}
public string format_patch_name
{
owned get
{
2013-02-20 09:37:13 +00:00
return get_subject().replace(" ", "-").replace("/", "-");
2012-04-14 11:46:39 +00:00
}
}
public string committer_date_for_display
{
owned get
{
2013-07-06 13:53:54 +00:00
var dt = get_committer().get_time();
return (new Date.for_date_time(dt)).for_display();
2012-04-14 11:46:39 +00:00
}
}
public string author_date_for_display
{
owned get
{
2013-07-06 13:53:54 +00:00
var dt = get_author().get_time();
return (new Date.for_date_time(dt)).for_display();
2012-04-14 11:46:39 +00:00
}
}
2013-02-21 16:41:25 +00:00
2014-12-16 07:23:30 +00:00
public Ggit.Diff get_diff(Ggit.DiffOptions? options, int parent)
2013-02-21 16:41:25 +00:00
{
2013-11-23 13:54:29 +00:00
Ggit.Diff? diff = null;
2013-02-21 16:41:25 +00:00
var repo = get_owner();
try
{
var parents = get_parents();
2014-12-14 18:16:41 +00:00
if (parents.size == 0)
2013-02-21 16:41:25 +00:00
{
2014-12-16 07:23:30 +00:00
// No parents, initial commit?
2013-11-23 13:54:29 +00:00
diff = new Ggit.Diff.tree_to_tree(repo,
null,
get_tree(),
options);
}
else
{
2014-12-16 07:23:30 +00:00
if (parent >= parents.size)
2013-02-21 16:41:25 +00:00
{
2014-12-16 07:23:30 +00:00
parent = (int)parents.size - 1;
2013-02-21 16:41:25 +00:00
}
2014-12-16 07:23:30 +00:00
diff = new Ggit.Diff.tree_to_tree(repo,
parents[parent].get_tree(),
get_tree(),
options);
2013-02-21 16:41:25 +00:00
}
}
catch (Error e)
{
stderr.printf("Error when getting diff: %s\n", e.message);
}
2013-02-21 16:41:25 +00:00
if (diff != null)
{
try
{
diff.find_similar(null);
} catch {}
}
2013-02-21 16:41:25 +00:00
return diff;
}
public Ggit.Note get_note()
{
Ggit.Note note = null;
var repo = get_owner();
try
{
note = repo.read_note(null, get_id());
}
catch (Error e) {}
return note;
}
2012-04-14 11:46:39 +00:00
}
}
// ex:set ts=4 noet